From 27dfa4a952c15f7c2cc47f89f08b683742c52a57 Mon Sep 17 00:00:00 2001 From: yanas Date: Mon, 3 Feb 2025 15:31:48 +0100 Subject: [PATCH] fix(suite-native): import and show Taproot descriptors correctly --- suite-native/module-accounts-import/package.json | 1 + .../module-accounts-import/src/accountsImportThunks.ts | 9 ++++++++- suite-native/module-accounts-import/tsconfig.json | 1 + suite-native/module-accounts-management/package.json | 1 + .../src/components/AccountSettingsShowXpubButton.tsx | 9 +++++++-- suite-native/module-accounts-management/tsconfig.json | 3 ++- yarn.lock | 2 ++ 7 files changed, 22 insertions(+), 4 deletions(-) diff --git a/suite-native/module-accounts-import/package.json b/suite-native/module-accounts-import/package.json index 6fb9123358a..59246595b09 100644 --- a/suite-native/module-accounts-import/package.json +++ b/suite-native/module-accounts-import/package.json @@ -43,6 +43,7 @@ "@suite-native/video-assets": "workspace:*", "@trezor/connect": "workspace:*", "@trezor/styles": "workspace:*", + "@trezor/utils": "workspace:*", "@trezor/utxo-lib": "workspace:*", "react": "18.2.0", "react-hook-form": "^7.54.2", diff --git a/suite-native/module-accounts-import/src/accountsImportThunks.ts b/suite-native/module-accounts-import/src/accountsImportThunks.ts index ea235fbdf47..b603cebf0c2 100644 --- a/suite-native/module-accounts-import/src/accountsImportThunks.ts +++ b/suite-native/module-accounts-import/src/accountsImportThunks.ts @@ -23,6 +23,7 @@ import { Timestamp, TokenAddress } from '@suite-common/wallet-types'; import { getAccountIdentity, shouldUseIdentities } from '@suite-common/wallet-utils'; import { isCoinWithTokens } from '@suite-native/tokens'; import TrezorConnect, { AccountInfo } from '@trezor/connect'; +import { convertTaprootXpub } from '@trezor/utils'; import { getXpubOrDescriptorInfo } from '@trezor/utxo-lib'; import { paymentTypeToAccountType } from './constants'; @@ -90,6 +91,12 @@ export const getAccountInfoThunk = createThunk< >( `${ACCOUNTS_IMPORT_MODULE_PREFIX}/getAccountInfo`, async ({ symbol, fiatCurrency, xpubAddress }, { dispatch, rejectWithValue, getState }) => { + // Connect requires apostrophe in Taproot descriptors thus a conversion is necessary. + const taprootXpubWithApostrophes = convertTaprootXpub({ + xpub: xpubAddress, + direction: 'h-to-apostrophe', + }); + try { const [fetchedAccountInfo] = await Promise.all([ TrezorConnect.getAccountInfo({ @@ -99,7 +106,7 @@ export const getAccountInfoThunk = createThunk< deviceState: PORTFOLIO_TRACKER_DEVICE_STATE, }) : undefined, - descriptor: xpubAddress, + descriptor: taprootXpubWithApostrophes ?? xpubAddress, details: 'txs', suppressBackupWarning: true, }), diff --git a/suite-native/module-accounts-import/tsconfig.json b/suite-native/module-accounts-import/tsconfig.json index 21678864710..e7eaee71292 100644 --- a/suite-native/module-accounts-import/tsconfig.json +++ b/suite-native/module-accounts-import/tsconfig.json @@ -43,6 +43,7 @@ { "path": "../video-assets" }, { "path": "../../packages/connect" }, { "path": "../../packages/styles" }, + { "path": "../../packages/utils" }, { "path": "../../packages/utxo-lib" } ], "include": [".", "**/*.json"] diff --git a/suite-native/module-accounts-management/package.json b/suite-native/module-accounts-management/package.json index 159ffcee404..e6115a07cc3 100644 --- a/suite-native/module-accounts-management/package.json +++ b/suite-native/module-accounts-management/package.json @@ -37,6 +37,7 @@ "@suite-native/tokens": "workspace:*", "@suite-native/transactions": "workspace:*", "@trezor/styles": "workspace:*", + "@trezor/utils": "workspace:*", "date-fns": "^2.30.0", "jotai": "1.9.1", "react": "18.2.0", diff --git a/suite-native/module-accounts-management/src/components/AccountSettingsShowXpubButton.tsx b/suite-native/module-accounts-management/src/components/AccountSettingsShowXpubButton.tsx index e75a5b09616..67770372de7 100644 --- a/suite-native/module-accounts-management/src/components/AccountSettingsShowXpubButton.tsx +++ b/suite-native/module-accounts-management/src/components/AccountSettingsShowXpubButton.tsx @@ -6,6 +6,7 @@ import { isAddressBasedNetwork } from '@suite-common/wallet-utils'; import { Button } from '@suite-native/atoms'; import { Translation } from '@suite-native/intl'; import { XpubQRCodeBottomSheet } from '@suite-native/qr-code'; +import { convertTaprootXpub } from '@trezor/utils'; export const AccountSettingsShowXpubButton = ({ accountKey }: { accountKey: string }) => { const account = useSelector((state: AccountsRootState) => @@ -16,6 +17,11 @@ export const AccountSettingsShowXpubButton = ({ accountKey }: { accountKey: stri if (!account) return null; + // Suite uses apostrophe in Taproot descriptors but FW uses 'h' – make sure they match. + const accountXpub = + convertTaprootXpub({ xpub: account.descriptor, direction: 'apostrophe-to-h' }) ?? + account.descriptor; + const handleClose = () => { setIsXpubVisible(false); }; @@ -40,12 +46,11 @@ export const AccountSettingsShowXpubButton = ({ accountKey }: { accountKey: stri > {buttonTitle} - ); diff --git a/suite-native/module-accounts-management/tsconfig.json b/suite-native/module-accounts-management/tsconfig.json index 9f840ca7399..9eb3238c63a 100644 --- a/suite-native/module-accounts-management/tsconfig.json +++ b/suite-native/module-accounts-management/tsconfig.json @@ -34,6 +34,7 @@ { "path": "../settings" }, { "path": "../tokens" }, { "path": "../transactions" }, - { "path": "../../packages/styles" } + { "path": "../../packages/styles" }, + { "path": "../../packages/utils" } ] } diff --git a/yarn.lock b/yarn.lock index 88be7ffaf7e..024bf895e6d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10570,6 +10570,7 @@ __metadata: "@suite-native/video-assets": "workspace:*" "@trezor/connect": "workspace:*" "@trezor/styles": "workspace:*" + "@trezor/utils": "workspace:*" "@trezor/utxo-lib": "workspace:*" react: "npm:18.2.0" react-hook-form: "npm:^7.54.2" @@ -10610,6 +10611,7 @@ __metadata: "@suite-native/tokens": "workspace:*" "@suite-native/transactions": "workspace:*" "@trezor/styles": "workspace:*" + "@trezor/utils": "workspace:*" date-fns: "npm:^2.30.0" jotai: "npm:1.9.1" react: "npm:18.2.0"