mirror of
https://github.com/trezor/trezor-suite.git
synced 2026-02-20 00:33:07 +01:00
fix(native): show xpub at correct moment
This commit is contained in:
@@ -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}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 (
|
||||
<BottomSheetModal ref={ref} isCloseDisplayed title={sheetTitle}>
|
||||
<BottomSheetModal
|
||||
ref={ref}
|
||||
isCloseDisplayed
|
||||
title={sheetTitle}
|
||||
onClose={handleCancelConfirmation}
|
||||
>
|
||||
<VStack spacing="sp24">
|
||||
<XpubQRCodeCard isXpubShown={isXpubShown} qrCodeData={qrCodeData} />
|
||||
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
{
|
||||
"path": "../../suite-common/wallet-config"
|
||||
},
|
||||
{
|
||||
"path": "../../suite-common/wallet-core"
|
||||
},
|
||||
{
|
||||
"path": "../../suite-common/wallet-types"
|
||||
},
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user