From 1ad11b3926dd7d3cb7a22edce86fecc7e03a08ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Hus=C3=A1k?= Date: Fri, 13 Feb 2026 01:33:46 +0100 Subject: [PATCH] fix(native): show xpub at correct moment --- .../AccountSettingsShowXpubButton.tsx | 3 +- suite-native/qr-code/package.json | 4 +- .../src/components/XpubQRCodeBottomSheet.tsx | 47 +++++++++++++++++-- suite-native/qr-code/tsconfig.json | 3 ++ yarn.lock | 3 +- 5 files changed, 53 insertions(+), 7 deletions(-) diff --git a/suite-native/module-accounts-management/src/components/AccountSettingsShowXpubButton.tsx b/suite-native/module-accounts-management/src/components/AccountSettingsShowXpubButton.tsx index 909f04ebf8..56600ad2c5 100644 --- a/suite-native/module-accounts-management/src/components/AccountSettingsShowXpubButton.tsx +++ b/suite-native/module-accounts-management/src/components/AccountSettingsShowXpubButton.tsx @@ -6,7 +6,6 @@ import { selectAccountByKey, selectIsDeviceBackupRequired, selectSelectedDevice, - showXpubOnDevice, } from '@suite-common/wallet-core'; import { AccountKey } from '@suite-common/wallet-types'; import { isAddressBasedNetwork } from '@suite-common/wallet-utils'; @@ -48,7 +47,6 @@ export const AccountSettingsShowXpubButton = ({ accountKey }: { accountKey: Acco const showXpub = useCallback(() => { if (!device || !account) return; - showXpubOnDevice(device, account); if (isDeviceBackupRequired) { openWalletBackupWarningSheet(); } else { @@ -118,6 +116,7 @@ export const AccountSettingsShowXpubButton = ({ accountKey }: { accountKey: Acco onClose={closeXpubQRSheet} symbol={account.symbol} qrCodeData={accountXpub} + accountKey={accountKey} /> ); diff --git a/suite-native/qr-code/package.json b/suite-native/qr-code/package.json index 5af1ae0a6b..1e0bdd9db0 100644 --- a/suite-native/qr-code/package.json +++ b/suite-native/qr-code/package.json @@ -11,6 +11,7 @@ }, "dependencies": { "@suite-common/wallet-config": "workspace:*", + "@suite-common/wallet-core": "workspace:*", "@suite-common/wallet-types": "workspace:*", "@suite-common/wallet-utils": "workspace:*", "@suite-native/atoms": "workspace:*", @@ -26,6 +27,7 @@ "expo-image-picker": "~17.0.10", "react": "19.1.0", "react-native": "0.81.5", - "react-qr-code": "2.0.18" + "react-qr-code": "2.0.18", + "react-redux": "9.2.0" } } diff --git a/suite-native/qr-code/src/components/XpubQRCodeBottomSheet.tsx b/suite-native/qr-code/src/components/XpubQRCodeBottomSheet.tsx index 28ecbee9d0..864b447cfe 100644 --- a/suite-native/qr-code/src/components/XpubQRCodeBottomSheet.tsx +++ b/suite-native/qr-code/src/components/XpubQRCodeBottomSheet.tsx @@ -1,10 +1,19 @@ import { useState } from 'react'; +import { useSelector } from 'react-redux'; import { type NetworkSymbol, getNetworkType } from '@suite-common/wallet-config'; +import { + AccountsRootState, + selectAccountByKey, + selectSelectedDevice, + showXpubOnDevice, +} from '@suite-common/wallet-core'; +import { AccountKey } from '@suite-common/wallet-types'; import { isAddressBasedNetwork } from '@suite-common/wallet-utils'; import { BottomSheetModal, BottomSheetModalRef, Box, Button, VStack } from '@suite-native/atoms'; import { useCopyToClipboard } from '@suite-native/clipboard'; import { Translation, useTranslate } from '@suite-native/intl'; +import TrezorConnect from '@trezor/connect'; import { prepareNativeStyle, useNativeStyles } from '@trezor/styles'; import { XpubQRCodeCard } from './XpubQRCodeCard'; @@ -14,6 +23,7 @@ type XpubQRCodeBottomSheetProps = { qrCodeData?: string; symbol: NetworkSymbol; ref: BottomSheetModalRef; + accountKey: AccountKey; }; const buttonStyle = prepareNativeStyle(utils => ({ @@ -25,7 +35,9 @@ export const XpubQRCodeBottomSheet = ({ qrCodeData, symbol, ref, + accountKey, }: XpubQRCodeBottomSheetProps) => { + const [confirmationInProgress, setConfirmationInProgress] = useState(false); const { translate } = useTranslate(); const networkType = getNetworkType(symbol); const isAddressBased = isAddressBasedNetwork(networkType); @@ -33,6 +45,12 @@ export const XpubQRCodeBottomSheet = ({ const copyToClipboard = useCopyToClipboard(); const [isXpubShown, setIsXpubShown] = useState(isAddressBased); + const account = useSelector((state: AccountsRootState) => + selectAccountByKey(state, accountKey), + ); + + const device = useSelector(selectSelectedDevice); + if (!qrCodeData) return null; const copyMessage = translate( @@ -60,8 +78,26 @@ export const XpubQRCodeBottomSheet = ({ /> ); - const handleShowXpub = () => { - setIsXpubShown(true); + const handleCancelConfirmation = () => { + if (!confirmationInProgress) return; + + setConfirmationInProgress(false); + TrezorConnect.cancel(); + }; + + const handleShowXpub = async () => { + if (!device || !account) return; + + setConfirmationInProgress(true); + const xpubResponse = await showXpubOnDevice(device, account); + + if (xpubResponse.success) { + setIsXpubShown(true); + } else { + onClose(); + } + + setConfirmationInProgress(false); }; const handleCopyXpub = async () => { @@ -70,7 +106,12 @@ export const XpubQRCodeBottomSheet = ({ }; return ( - + diff --git a/suite-native/qr-code/tsconfig.json b/suite-native/qr-code/tsconfig.json index 8bfa1ddc0a..1bb4eaada3 100644 --- a/suite-native/qr-code/tsconfig.json +++ b/suite-native/qr-code/tsconfig.json @@ -5,6 +5,9 @@ { "path": "../../suite-common/wallet-config" }, + { + "path": "../../suite-common/wallet-core" + }, { "path": "../../suite-common/wallet-types" }, diff --git a/yarn.lock b/yarn.lock index 1675c8dc5c..4cfccd1ee8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13370,7 +13370,6 @@ __metadata: "@suite-common/validators": "workspace:*" "@suite-common/wallet-config": "workspace:*" "@suite-common/wallet-constants": "workspace:*" - "@suite-common/wallet-core": "workspace:*" "@suite-common/wallet-types": "workspace:*" "@suite-common/wallet-utils": "workspace:*" "@suite-native/accounts": "workspace:*" @@ -13699,6 +13698,7 @@ __metadata: resolution: "@suite-native/qr-code@workspace:suite-native/qr-code" dependencies: "@suite-common/wallet-config": "workspace:*" + "@suite-common/wallet-core": "workspace:*" "@suite-common/wallet-types": "workspace:*" "@suite-common/wallet-utils": "workspace:*" "@suite-native/atoms": "workspace:*" @@ -13715,6 +13715,7 @@ __metadata: react: "npm:19.1.0" react-native: "npm:0.81.5" react-qr-code: "npm:2.0.18" + react-redux: "npm:9.2.0" languageName: unknown linkType: soft