From 92de6abbe21dd4b081ea029a5f98597c36de943d Mon Sep 17 00:00:00 2001 From: fede erbes Date: Mon, 4 Dec 2023 17:33:52 +0000 Subject: [PATCH 1/3] fix: show sat bundle for each input with an exotic or inscription --- src/app/hooks/useDetectOrdinalInSignPsbt.ts | 34 +++++++------ .../screens/signBatchPsbtRequest/index.tsx | 51 ++++++++++++++----- src/app/screens/signPsbtRequest/index.tsx | 33 ++++++------ src/locales/en.json | 3 +- 4 files changed, 74 insertions(+), 47 deletions(-) diff --git a/src/app/hooks/useDetectOrdinalInSignPsbt.ts b/src/app/hooks/useDetectOrdinalInSignPsbt.ts index b570729cf..f4d177820 100644 --- a/src/app/hooks/useDetectOrdinalInSignPsbt.ts +++ b/src/app/hooks/useDetectOrdinalInSignPsbt.ts @@ -1,21 +1,22 @@ import { Bundle, - BundleSatRange, getUtxoOrdinalBundle, mapRareSatsAPIResponseToBundle, ParsedPSBT, } from '@secretkeylabs/xverse-core'; import useWalletSelector from './useWalletSelector'; -export type InputsBundle = Pick; +export type InputsBundle = (Pick & { + inputIndex: number; +})[]; const useDetectOrdinalInSignPsbt = () => { const { ordinalsAddress, network } = useWalletSelector(); - const handleOrdinalAndOrdinalInfo = async (parsedPsbt?: ParsedPSBT) => { - const satRanges: BundleSatRange[] = []; - let value = 0; - let totalExoticSats = 0; + const handleOrdinalAndOrdinalInfo = async ( + parsedPsbt?: ParsedPSBT, + ): Promise<{ bundleItemsData: InputsBundle; userReceivesOrdinal: boolean }> => { + const bundleItemsData: InputsBundle = []; let userReceivesOrdinal = false; if (parsedPsbt) { @@ -23,11 +24,18 @@ const useDetectOrdinalInSignPsbt = () => { getUtxoOrdinalBundle(network.type, input.txid, input.index), ); const inputsResponse = await Promise.all(inputsRequest); - inputsResponse.forEach((inputResponse) => { + inputsResponse.forEach((inputResponse, index) => { const bundle = mapRareSatsAPIResponseToBundle(inputResponse); - value += bundle.value; - totalExoticSats += bundle.totalExoticSats; - satRanges.push(...bundle.satRanges); + if ( + bundle.inscriptions.length > 0 || + bundle.satributes.some((satributes) => !satributes.includes('COMMON')) + ) { + bundleItemsData.push({ + satRanges: bundle.satRanges, + totalExoticSats: bundle.totalExoticSats, + inputIndex: index, + }); + } }); parsedPsbt.outputs.forEach((output) => { @@ -37,12 +45,6 @@ const useDetectOrdinalInSignPsbt = () => { }); } - const bundleItemsData = { - value, - satRanges, - totalExoticSats, - }; - return { bundleItemsData, userReceivesOrdinal, diff --git a/src/app/screens/signBatchPsbtRequest/index.tsx b/src/app/screens/signBatchPsbtRequest/index.tsx index e546b7fe6..5917c02b9 100644 --- a/src/app/screens/signBatchPsbtRequest/index.tsx +++ b/src/app/screens/signBatchPsbtRequest/index.tsx @@ -117,6 +117,7 @@ function SignBatchPsbtRequest() { const { btcAddress, ordinalsAddress, selectedAccount, network } = useWalletSelector(); const navigate = useNavigate(); const { t } = useTranslation('translation', { keyPrefix: 'CONFIRM_TRANSACTION' }); + const { t: tCommon } = useTranslation('translation', { keyPrefix: 'COMMON' }); const [expandInputOutputView, setExpandInputOutputView] = useState(false); const { payload, confirmSignPsbt, cancelSignPsbt, getSigningAddresses, requestToken } = useSignBatchPsbtTx(); @@ -366,14 +367,32 @@ function SignBatchPsbtRequest() { {userTransfersOrdinals.length > 0 && userTransfersOrdinals.map((item, index) => ( - // eslint-disable-next-line react/no-array-index-key - + ))} {userReceivesOrdinals.length > 0 && userTransfersOrdinals.map((item, index) => ( - // eslint-disable-next-line react/no-array-index-key - + ))} - {userReceivesOrdinalArr[currentPsbtIndex]?.bundleItemsData && ( - - )} + {Array.isArray(userReceivesOrdinalArr[currentPsbtIndex]?.bundleItemsData) && + userReceivesOrdinalArr[currentPsbtIndex].bundleItemsData.map((bundle, index) => ( + + ))} {t('REVIEW_TRANSACTION')} {!payload.broadcast && } - {bundleItemsData && ( - - )} + {Array.isArray(bundleItemsData) && + bundleItemsData.map((bundle, index) => ( + + ))} + - {payload.broadcast ? ( Date: Mon, 4 Dec 2023 17:43:54 +0000 Subject: [PATCH 2/3] chore: remove unused string --- src/locales/en.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/locales/en.json b/src/locales/en.json index 432baa518..c58d97ca4 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -1178,8 +1178,7 @@ "RARE_SATS_BUNDLE": "Rare Sats Bundle", "BUNDLE_PENDING_SEND_DESCRIPTION": "This bundle is already in a pending transfer.", "RARE_SAT": "Rare Sat", - "INSCRIBED_SAT": "Inscribed Sat", - "BUNDLE_SIZE": "Bundle size" + "INSCRIBED_SAT": "Inscribed Sat" }, "COLLECTIBLE_COLLECTION_SCREEN": { "BACK_TO_GALLERY": "Back to gallery", From 47c4c9b1b2830ca7f091adbce1cdc3fe488fc0e8 Mon Sep 17 00:00:00 2001 From: Tim Man Date: Tue, 5 Dec 2023 16:40:37 +0800 Subject: [PATCH 3/3] fix: use base-1 for psbt index shown in UI --- src/app/screens/signBatchPsbtRequest/index.tsx | 6 +++--- src/app/screens/signPsbtRequest/index.tsx | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/screens/signBatchPsbtRequest/index.tsx b/src/app/screens/signBatchPsbtRequest/index.tsx index 5917c02b9..a7ee9f476 100644 --- a/src/app/screens/signBatchPsbtRequest/index.tsx +++ b/src/app/screens/signBatchPsbtRequest/index.tsx @@ -370,7 +370,7 @@ function SignBatchPsbtRequest() { (