diff --git a/packages/engine/src/apiProxyUtils.ts b/packages/engine/src/apiProxyUtils.ts index c5310bea232..e4b0bf24618 100644 --- a/packages/engine/src/apiProxyUtils.ts +++ b/packages/engine/src/apiProxyUtils.ts @@ -9,6 +9,7 @@ export type TokenBalancesQuery = { // eslint-disable-next-line camelcase contract_addresses?: string[]; xpub?: string; + withBRC20Tokens?: boolean; }; export type TokenBalancesResponse = { @@ -38,6 +39,7 @@ export const getBalancesFromApi = async ({ const query: TokenBalancesQuery = { network: networkId, address, + withBRC20Tokens: true, }; if (xpub) { Object.assign(query, { xpub }); diff --git a/packages/engine/src/vaults/utils/btcForkChain/VaultBtcFork.ts b/packages/engine/src/vaults/utils/btcForkChain/VaultBtcFork.ts index 7d21ed34667..8e3515c57af 100644 --- a/packages/engine/src/vaults/utils/btcForkChain/VaultBtcFork.ts +++ b/packages/engine/src/vaults/utils/btcForkChain/VaultBtcFork.ts @@ -518,7 +518,10 @@ export default class VaultBtcFork extends VaultBase { from: 'unknown', to: dbAccount.address, amount: '0', - asset: output.inscriptions[0], + asset: { + ...output.inscriptions[0], + type: NFTAssetType.BTC, + }, }), ); } else { @@ -1161,6 +1164,10 @@ export default class VaultBtcFork extends VaultBase { tokenAddress: tokenIdOnNetwork, }); + // several history items with same txid + // merge them into one + const txIdSet = new Set(); + const promises = history.map(async (tx) => { try { const historyTxToMerge = localHistory.find( @@ -1171,62 +1178,77 @@ export default class VaultBtcFork extends VaultBase { return null; } - const { - fromAddress, - toAddress, - time, - token: tick, - actionType, - amount, - } = tx; + if (txIdSet.has(tx.txId)) { + return null; + } - const tokenId = `brc-20--${tick}`; + txIdSet.add(tx.txId); - const tokenInfo = await this.engine.findToken({ - networkId: this.networkId, - tokenIdOnNetwork: tokenId, - }); + const txsWithSameTxId = history.filter( + (item) => item.txId === tx.txId, + ); const actions: IDecodedTxAction[] = []; - const isInscribeTransfer = actionType === 'inscribeTransfer'; - - if (tokenInfo) { - const action = this.buildBRC20TokenAction({ - nftInfo: { - from: isInscribeTransfer ? toAddress : fromAddress, - to: toAddress, - amount, - asset: { - type: NFTAssetType.BTC, - inscription_id: tx.inscriptionId, - inscription_number: new BigNumber( - tx.inscriptionNumber, - ).toNumber(), - tx_hash: tx.txId, - content: '', - content_length: 0, - content_type: '', - timestamp: tx.time, - output: tx.index, - owner: '', - output_value_sat: 0, - genesis_transaction_hash: '', - location: tx.location, - contentUrl: '', - }, - }, - dbAccount, - token: tokenInfo, - brc20Content: { - p: 'brc20', - op: actionType, - tick, - amt: amount, - }, + + for (let i = 0, len = txsWithSameTxId.length; i < len; i += 1) { + const { + fromAddress, + toAddress, + time, + token: tick, + actionType, + amount, + } = txsWithSameTxId[i]; + + const tokenId = `brc-20--${tick}`; + + const tokenInfo = await this.engine.findToken({ + networkId: this.networkId, + tokenIdOnNetwork: tokenId, }); - actions.push(action); + + const isInscribeTransfer = actionType === 'inscribeTransfer'; + + if (tokenInfo) { + const action = this.buildBRC20TokenAction({ + nftInfo: { + from: isInscribeTransfer ? toAddress : fromAddress, + to: toAddress, + amount, + asset: { + type: NFTAssetType.BTC, + inscription_id: tx.inscriptionId, + inscription_number: new BigNumber( + tx.inscriptionNumber, + ).toNumber(), + tx_hash: tx.txId, + content: '', + content_length: 0, + content_type: '', + timestamp: tx.time, + output: tx.index, + owner: '', + output_value_sat: 0, + genesis_transaction_hash: '', + location: tx.location, + contentUrl: '', + }, + }, + dbAccount, + token: tokenInfo, + brc20Content: { + p: 'brc20', + op: actionType, + tick, + amt: amount, + }, + }); + actions.push(action); + } } + const { time } = txsWithSameTxId[0]; + const decodedTx: IDecodedTx = { txid: tx.txId, owner: dbAccount.address, diff --git a/packages/kit/src/views/Wallet/NFT/NFTDetail/Components/BTCAsset/BTCAssetDetailContent.tsx b/packages/kit/src/views/Wallet/NFT/NFTDetail/Components/BTCAsset/BTCAssetDetailContent.tsx index 2d6d65c1f71..67a48ab6da0 100644 --- a/packages/kit/src/views/Wallet/NFT/NFTDetail/Components/BTCAsset/BTCAssetDetailContent.tsx +++ b/packages/kit/src/views/Wallet/NFT/NFTDetail/Components/BTCAsset/BTCAssetDetailContent.tsx @@ -95,10 +95,7 @@ function BTCAssetDetailContent({ const [asset, updateAsset] = useState(outerAsset); const isDisabled = - wallet?.type === WALLET_TYPE_WATCHING || - asset.owner !== outerAsset.accountAddress || - !accountId || - !isOwner; + wallet?.type === WALLET_TYPE_WATCHING || !accountId || !isOwner; const sendAction = useCallback(() => { if (!networkId || !accountId) {