Skip to content

Commit

Permalink
fix: only split inscriptions to change-address
Browse files Browse the repository at this point in the history
  • Loading branch information
slient-coder committed Jun 30, 2023
1 parent 68d021c commit 0a87974
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 38 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"@types/react-dom": "^18.0.4",
"@unisat/bitcoin-hd-keyring": "1.0.0",
"@unisat/bitcoinjs-wallet": "^0.1.0",
"@unisat/ord-utils": "0.3.0",
"@unisat/ord-utils": "0.3.1",
"antd": "^4.20.4",
"antd-dayjs-webpack-plugin": "1.0.6",
"assert": "^2.0.0",
Expand Down
3 changes: 1 addition & 2 deletions src/background/controller/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ export class WalletController extends BaseController {
return psbt.toHex();
};

splitInscription = async ({ to, inscriptionId, feeRate }: { to: string; inscriptionId: string; feeRate: number }) => {
splitInscription = async ({ inscriptionId, feeRate }: { to: string; inscriptionId: string; feeRate: number }) => {
const account = await preferenceService.getCurrentAccount();
if (!account) throw new Error('no current account');

Expand All @@ -764,7 +764,6 @@ export class WalletController extends BaseController {
ords: v.inscriptions
};
}),
toAddress: to,
wallet: this,
network: psbtNetwork,
changeAddress: account.address,
Expand Down
8 changes: 7 additions & 1 deletion src/ui/pages/Wallet/OrdinalsDetailScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ export default function OrdinalsDetailScreen() {
<InscriptionPreview data={inscription} preset="large" />
</Row>

{isMultiStuck && <Text color="danger" textCenter text={'This inscription is stuck by other inscriptions'} />}
{isMultiStuck && (
<Text
color="danger"
textCenter
text={'Multiple inscriptions are mixed together. Please split them first.'}
/>
)}
{withSend &&
(isMultiStuck ? (
<Button
Expand Down
29 changes: 4 additions & 25 deletions src/ui/pages/Wallet/SplitTxCreateScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { Inscription, RawTxInfo } from '@/shared/types';
import { Button, Column, Content, Header, Input, Layout, Row, Text } from '@/ui/components';
import { FeeRateBar } from '@/ui/components/FeeRateBar';
import InscriptionPreview from '@/ui/components/InscriptionPreview';
import { useCurrentAccount } from '@/ui/state/accounts/hooks';
import { useCreateOrdinalsTxCallback, useCreateSplitTxCallback, useOrdinalsTx } from '@/ui/state/transactions/hooks';
import { useCreateSplitTxCallback, useOrdinalsTx } from '@/ui/state/transactions/hooks';
import { isValidAddress, useWallet } from '@/ui/utils';

import { useNavigate } from '../MainRoute';
Expand All @@ -21,11 +20,6 @@ export default function SplitTxCreateScreen() {
};
const ordinalsTx = useOrdinalsTx();

const [toInfo, setToInfo] = useState({
address: '',
domain: ''
});

const [error, setError] = useState('');
const createSplitTx = useCreateSplitTxCallback();

Expand All @@ -51,17 +45,13 @@ export default function SplitTxCreateScreen() {
return;
}

if (!isValidAddress(toInfo.address)) {
return;
}

if (toInfo.address == ordinalsTx.toAddress && feeRate == ordinalsTx.feeRate) {
if (feeRate == ordinalsTx.feeRate) {
//Prevent repeated triggering caused by setAmount
setDisabled(false);
return;
}

createSplitTx(toInfo, inscription.inscriptionId, feeRate)
createSplitTx(inscription.inscriptionId, feeRate)
.then((data) => {
setRawTxInfo(data);
setDisabled(false);
Expand All @@ -70,7 +60,7 @@ export default function SplitTxCreateScreen() {
console.log(e);
setError(e.message);
});
}, [toInfo, feeRate]);
}, [feeRate]);

return (
<Layout>
Expand All @@ -97,17 +87,6 @@ export default function SplitTxCreateScreen() {
</Row>
</Row>

<Text text="Recipient" color="textDim" />

<Input
preset="address"
addressInputData={toInfo}
autoFocus={true}
onAddressInputChange={(val) => {
setToInfo(val);
}}
/>

<Text text="Fee" color="textDim" />

<FeeRateBar
Expand Down
6 changes: 2 additions & 4 deletions src/ui/state/transactions/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,8 @@ export function useCreateSplitTxCallback() {
const fromAddress = useAccountAddress();
const utxos = useUtxos();
return useCallback(
async (toAddressInfo: ToAddressInfo, inscriptionId: string, feeRate: number) => {
async (inscriptionId: string, feeRate: number) => {
const psbtHex = await wallet.splitInscription({
to: toAddressInfo.address,
inscriptionId,
feeRate
});
Expand All @@ -216,8 +215,7 @@ export function useCreateSplitTxCallback() {
);
const rawTxInfo: RawTxInfo = {
psbtHex,
rawtx,
toAddressInfo
rawtx
};
return rawTxInfo;
},
Expand Down
2 changes: 1 addition & 1 deletion src/ui/utils/WalletContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export interface WalletController {

sendInscriptions(data: { to: string; inscriptionIds: string[]; feeRate: number }): Promise<string>;

splitInscription(data: { to: string; inscriptionId: string; feeRate: number }): Promise<string>;
splitInscription(data: { inscriptionId: string; feeRate: number }): Promise<string>;

pushTx(rawtx: string): Promise<string>;

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2734,10 +2734,10 @@
tiny-secp256k1 "^2.2.1"
uuid "^9.0.0"

"@unisat/[email protected].0":
version "0.3.0"
resolved "https://registry.yarnpkg.com/@unisat/ord-utils/-/ord-utils-0.3.0.tgz#94222a870acd98232b19e5383469db98289942e4"
integrity sha512-QQQqqeP/pB6AdaibT9KX+gl4BTAXQEz0zIbWPnTa6cGij2GYfrDpuP6y3Pyj9Y797Et4dDOsAnHfQeUq51KOJA==
"@unisat/[email protected].1":
version "0.3.1"
resolved "https://registry.yarnpkg.com/@unisat/ord-utils/-/ord-utils-0.3.1.tgz#55bce4cd4c7ac95871391f481bd266a8edb7d36b"
integrity sha512-65Z8gURDZDfiUVMjMQ0Efi/GaiojgQ3Voyjwb0CXLZxM2+jZFSyTvhUiHzfIUmDGkpQlnlBe8ul1r2UzbM8/xw==
dependencies:
bignumber.js "^9.1.1"
bitcoinjs-lib "^6.1.0"
Expand Down

0 comments on commit 0a87974

Please sign in to comment.