From 9d37833b9c5cbf8998978de83ebb471f155cdeb5 Mon Sep 17 00:00:00 2001 From: Javier Bueno Date: Tue, 3 Sep 2024 16:07:39 +0200 Subject: [PATCH] CR: update --- .../WalletDuplicatedModal.tsx | 12 ++++------- .../CreateWallet/WalletDetailsScreen.tsx | 14 +++++-------- .../RestoreHwWallet/ConnectNanoXScreen.tsx | 2 +- .../RestoreHwWallet/SaveNanoXScreen.tsx | 14 +++++-------- .../RestoreWallet/RestoreWalletScreen.tsx | 2 +- .../features/WalletManager/wallet-manager.ts | 20 ++++++++++--------- .../Staking/StakingCenter/StakingCenter.tsx | 4 ++-- .../Staking/StakingCenter/StakingCenter.json | 8 ++++---- 8 files changed, 33 insertions(+), 43 deletions(-) diff --git a/apps/wallet-mobile/src/features/SetupWallet/common/WalletDuplicatedModal/WalletDuplicatedModal.tsx b/apps/wallet-mobile/src/features/SetupWallet/common/WalletDuplicatedModal/WalletDuplicatedModal.tsx index 014b7fad79..e3023e255f 100644 --- a/apps/wallet-mobile/src/features/SetupWallet/common/WalletDuplicatedModal/WalletDuplicatedModal.tsx +++ b/apps/wallet-mobile/src/features/SetupWallet/common/WalletDuplicatedModal/WalletDuplicatedModal.tsx @@ -15,9 +15,9 @@ export const WalletDuplicatedModal = ({publicKeyHex}: {publicKeyHex: string}) => const {resetToTxHistory} = useWalletNavigation() const {walletManager} = useWalletManager() - const plate = walletManager.getWalletPlate(publicKeyHex) + const {plate, seed} = walletManager.checksum(publicKeyHex) const walletDuplicatedMeta = Array.from(walletManager.walletMetas.values()).find( - (walletMeta) => walletMeta.plate === plate.TextPart, + (walletMeta) => walletMeta.plate === plate, ) if (!walletDuplicatedMeta) throw new Error('Wallet Duplicated Modal: invalid state') @@ -34,18 +34,14 @@ export const WalletDuplicatedModal = ({publicKeyHex}: {publicKeyHex: string}) => - + {walletDuplicatedMeta.name} - {plate.TextPart} + {plate} diff --git a/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/WalletDetailsScreen.tsx b/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/WalletDetailsScreen.tsx index 9d0081521d..4aa510aefe 100644 --- a/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/WalletDetailsScreen.tsx +++ b/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/WalletDetailsScreen.tsx @@ -82,7 +82,7 @@ export const WalletDetailsScreen = () => { walletIdChanged, accountVisual, } = useSetupWallet() - const plate = walletManager.getWalletPlate(publicKeyHex) + const {plate, seed} = walletManager.checksum(publicKeyHex) const [name, setName] = React.useState(features.prefillWalletInfo ? debugWalletInfo.WALLET_NAME : '') const passwordRef = React.useRef(null) const [password, setPassword] = React.useState(features.prefillWalletInfo ? debugWalletInfo.PASSWORD : '') @@ -221,11 +221,11 @@ export const WalletDetailsScreen = () => { @@ -310,15 +310,11 @@ export const WalletDetailsScreen = () => { /> - + - {plate.TextPart} + {plate} diff --git a/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreHwWallet/ConnectNanoXScreen.tsx b/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreHwWallet/ConnectNanoXScreen.tsx index 0a9336e505..bb03ccc668 100644 --- a/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreHwWallet/ConnectNanoXScreen.tsx +++ b/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreHwWallet/ConnectNanoXScreen.tsx @@ -44,7 +44,7 @@ export const ConnectNanoXScreen = ({defaultDevices}: Props) => { const onSuccess = (hwDeviceInfo: HW.DeviceInfo) => { hwDeviceInfoChanged(hwDeviceInfo) - const isWalletDuplicated = walletManager.getIsWalletDuplicated(hwDeviceInfo.bip44AccountPublic) + const isWalletDuplicated = walletManager.isWalletAccountDuplicated(hwDeviceInfo.bip44AccountPublic) if (isWalletDuplicated) { openModal( diff --git a/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreHwWallet/SaveNanoXScreen.tsx b/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreHwWallet/SaveNanoXScreen.tsx index c44c9366cb..19b401f299 100644 --- a/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreHwWallet/SaveNanoXScreen.tsx +++ b/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreHwWallet/SaveNanoXScreen.tsx @@ -70,7 +70,7 @@ export const SaveNanoXScreen = () => { const {walletImplementation, hwDeviceInfo, accountVisual, walletIdChanged} = useSetupWallet() if (!hwDeviceInfo) throw new Error('no hwDeviceInfo') - const plate = walletManager.getWalletPlate(hwDeviceInfo.bip44AccountPublic) + const {plate, seed} = walletManager.checksum(hwDeviceInfo.bip44AccountPublic) const {createWallet, isLoading} = useCreateWalletXPub({ onSuccess: async (wallet) => { @@ -161,11 +161,11 @@ export const SaveNanoXScreen = () => { @@ -223,16 +223,12 @@ export const SaveNanoXScreen = () => { - + - {plate.TextPart} + {plate} diff --git a/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreWallet/RestoreWalletScreen.tsx b/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreWallet/RestoreWalletScreen.tsx index d4a0d8f428..279d8ad9d7 100644 --- a/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreWallet/RestoreWalletScreen.tsx +++ b/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreWallet/RestoreWalletScreen.tsx @@ -108,7 +108,7 @@ export const RestoreWalletScreen = () => { const handleOnNext = React.useCallback(async () => { const {accountPubKeyHex} = await walletManager.generateWalletKeys(walletImplementation, mnemonic, accountVisual) - const iswalletDuplicated = walletManager.getIsWalletDuplicated(accountPubKeyHex) + const iswalletDuplicated = walletManager.isWalletAccountDuplicated(accountPubKeyHex) if (iswalletDuplicated) { openModal(strings.restoreDuplicatedWalletModalTitle, ) diff --git a/apps/wallet-mobile/src/features/WalletManager/wallet-manager.ts b/apps/wallet-mobile/src/features/WalletManager/wallet-manager.ts index bbe4f09e3e..a4109da4b5 100644 --- a/apps/wallet-mobile/src/features/WalletManager/wallet-manager.ts +++ b/apps/wallet-mobile/src/features/WalletManager/wallet-manager.ts @@ -1,4 +1,4 @@ -import {WalletChecksum, walletChecksum} from '@emurgo/cip4-js' +import {walletChecksum} from '@emurgo/cip4-js' import {difference, parseSafe} from '@yoroi/common' import {Blockies} from '@yoroi/identicon' import {App, Chain, HW, Network, Wallet} from '@yoroi/types' @@ -385,17 +385,19 @@ export class WalletManager { await this.#rootStorage.setItem('deletedWalletIds', []) } - getWalletPlate(publicKeyHex: string): WalletChecksum { - const plate = walletChecksum(publicKeyHex) - return plate + checksum(publicKeyHex: string) { + const {TextPart, ImagePart} = walletChecksum(publicKeyHex) + + return { + plate: TextPart, + seed: ImagePart, + } } - getIsWalletDuplicated(publicKeyHex: string): boolean { - const plate = this.getWalletPlate(publicKeyHex) + isWalletAccountDuplicated(publicKeyHex: string) { + const {plate} = this.checksum(publicKeyHex) - const walletDuplicatedMeta = Array.from(this.walletMetas.values()).find( - (walletMeta) => walletMeta.plate === plate.TextPart, - ) + const walletDuplicatedMeta = Array.from(this.walletMetas.values()).find((walletMeta) => walletMeta.plate === plate) const isWalletDuplicated = walletDuplicatedMeta !== undefined diff --git a/apps/wallet-mobile/src/legacy/Staking/StakingCenter/StakingCenter.tsx b/apps/wallet-mobile/src/legacy/Staking/StakingCenter/StakingCenter.tsx index 9e6e44c2fa..49a0ded070 100644 --- a/apps/wallet-mobile/src/legacy/Staking/StakingCenter/StakingCenter.tsx +++ b/apps/wallet-mobile/src/legacy/Staking/StakingCenter/StakingCenter.tsx @@ -30,7 +30,7 @@ export const StakingCenter = () => { const {wallet, meta} = useSelectedWallet() const {walletManager} = useWalletManager() const {track} = useMetrics() - const plate = walletManager.getWalletPlate(wallet.publicKeyHex) + const {plate} = walletManager.checksum(wallet.publicKeyHex) useFocusEffect( React.useCallback(() => { @@ -87,7 +87,7 @@ export const StakingCenter = () => { handleOnMessage(event)} {...(isDark && { injectedJavaScript: ` diff --git a/apps/wallet-mobile/translations/messages/src/legacy/Staking/StakingCenter/StakingCenter.json b/apps/wallet-mobile/translations/messages/src/legacy/Staking/StakingCenter/StakingCenter.json index db289cda56..bfbee05540 100644 --- a/apps/wallet-mobile/translations/messages/src/legacy/Staking/StakingCenter/StakingCenter.json +++ b/apps/wallet-mobile/translations/messages/src/legacy/Staking/StakingCenter/StakingCenter.json @@ -6,12 +6,12 @@ "start": { "line": 127, "column": 9, - "index": 4467 + "index": 4454 }, "end": { "line": 130, "column": 3, - "index": 4575 + "index": 4562 } }, { @@ -21,12 +21,12 @@ "start": { "line": 131, "column": 11, - "index": 4588 + "index": 4575 }, "end": { "line": 134, "column": 3, - "index": 4754 + "index": 4741 } } ] \ No newline at end of file