Skip to content

Commit

Permalink
fix(suite-native): import and show Taproot descriptors correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
yanascz committed Feb 3, 2025
1 parent 37ace75 commit 27dfa4a
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions suite-native/module-accounts-import/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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({
Expand All @@ -99,7 +106,7 @@ export const getAccountInfoThunk = createThunk<
deviceState: PORTFOLIO_TRACKER_DEVICE_STATE,
})
: undefined,
descriptor: xpubAddress,
descriptor: taprootXpubWithApostrophes ?? xpubAddress,
details: 'txs',
suppressBackupWarning: true,
}),
Expand Down
1 change: 1 addition & 0 deletions suite-native/module-accounts-import/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
{ "path": "../video-assets" },
{ "path": "../../packages/connect" },
{ "path": "../../packages/styles" },
{ "path": "../../packages/utils" },
{ "path": "../../packages/utxo-lib" }
],
"include": [".", "**/*.json"]
Expand Down
1 change: 1 addition & 0 deletions suite-native/module-accounts-management/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand All @@ -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);
};
Expand All @@ -40,12 +46,11 @@ export const AccountSettingsShowXpubButton = ({ accountKey }: { accountKey: stri
>
{buttonTitle}
</Button>

<XpubQRCodeBottomSheet
isVisible={isXpubVisible}
onClose={handleClose}
symbol={account.symbol}
qrCodeData={account.descriptor}
qrCodeData={accountXpub}
/>
</>
);
Expand Down
3 changes: 2 additions & 1 deletion suite-native/module-accounts-management/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
{ "path": "../settings" },
{ "path": "../tokens" },
{ "path": "../transactions" },
{ "path": "../../packages/styles" }
{ "path": "../../packages/styles" },
{ "path": "../../packages/utils" }
]
}
2 changes: 2 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 27dfa4a

Please sign in to comment.