Skip to content

Commit

Permalink
CR: update
Browse files Browse the repository at this point in the history
  • Loading branch information
banklesss committed Sep 3, 2024
1 parent 1b8ebd8 commit 9d37833
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -34,18 +34,14 @@ export const WalletDuplicatedModal = ({publicKeyHex}: {publicKeyHex: string}) =>
<Space height="lg" />

<View style={styles.checksum}>
<Icon.WalletAvatar
image={new Blockies({seed: plate.ImagePart}).asBase64()}
style={styles.walletChecksum}
size={38}
/>
<Icon.WalletAvatar image={new Blockies({seed}).asBase64()} style={styles.walletChecksum} size={38} />

<Space width="sm" />

<View>
<Text style={styles.plateName}>{walletDuplicatedMeta.name}</Text>

<Text style={styles.plateText}>{plate.TextPart}</Text>
<Text style={styles.plateText}>{plate}</Text>
</View>
</View>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<RNTextInput>(null)
const [password, setPassword] = React.useState(features.prefillWalletInfo ? debugWalletInfo.PASSWORD : '')
Expand Down Expand Up @@ -221,11 +221,11 @@ export const WalletDetailsScreen = () => {
<ScrollView bounces={false}>
<CardAboutPhrase
title={strings.walletChecksumModalCardTitle}
checksumImage={plate.ImagePart}
checksumImage={seed}
checksumLine={1}
linesOfText={[
strings.walletChecksumModalCardFirstItem,
strings.walletChecksumModalCardSecondItem(plate.TextPart),
strings.walletChecksumModalCardSecondItem(plate),
strings.walletChecksumModalCardThirdItem,
]}
/>
Expand Down Expand Up @@ -310,15 +310,11 @@ export const WalletDetailsScreen = () => {
/>

<View style={styles.checksum}>
<Icon.WalletAvatar
image={new Blockies({seed: plate.ImagePart}).asBase64()}
style={styles.walletChecksum}
size={24}
/>
<Icon.WalletAvatar image={new Blockies({seed}).asBase64()} style={styles.walletChecksum} size={24} />

<Space width="sm" />

<Text style={styles.plateNumber}>{plate.TextPart}</Text>
<Text style={styles.plateNumber}>{plate}</Text>

<Space width="sm" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -161,11 +161,11 @@ export const SaveNanoXScreen = () => {
<View>
<CardAboutPhrase
title={strings.walletChecksumModalCardTitle}
checksumImage={plate.ImagePart}
checksumImage={seed}
checksumLine={1}
linesOfText={[
strings.walletChecksumModalCardFirstItem,
strings.walletChecksumModalCardSecondItem(plate.TextPart),
strings.walletChecksumModalCardSecondItem(plate),
strings.walletChecksumModalCardThirdItem,
]}
/>
Expand Down Expand Up @@ -223,16 +223,12 @@ export const SaveNanoXScreen = () => {
<Space height="lg" />

<View style={styles.checksum}>
<Icon.WalletAvatar
image={new Blockies({seed: plate.ImagePart}).asBase64()}
style={styles.walletChecksum}
size={24}
/>
<Icon.WalletAvatar image={new Blockies({seed}).asBase64()} style={styles.walletChecksum} size={24} />

<Space width="sm" />

<Text style={styles.plateNumber} testID="wallet-plate-number">
{plate.TextPart}
{plate}
</Text>

<Space width="sm" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, <WalletDuplicatedModal publicKeyHex={accountPubKeyHex} />)
Expand Down
20 changes: 11 additions & 9 deletions apps/wallet-mobile/src/features/WalletManager/wallet-manager.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -87,7 +87,7 @@ export const StakingCenter = () => {
<WebView
originWhitelist={['*']}
androidLayerType="software"
source={{uri: prepareStakingURL(languageCode, plate.TextPart)}}
source={{uri: prepareStakingURL(languageCode, plate)}}
onMessage={(event) => handleOnMessage(event)}
{...(isDark && {
injectedJavaScript: `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"start": {
"line": 127,
"column": 9,
"index": 4467
"index": 4454
},
"end": {
"line": 130,
"column": 3,
"index": 4575
"index": 4562
}
},
{
Expand All @@ -21,12 +21,12 @@
"start": {
"line": 131,
"column": 11,
"index": 4588
"index": 4575
},
"end": {
"line": 134,
"column": 3,
"index": 4754
"index": 4741
}
}
]

0 comments on commit 9d37833

Please sign in to comment.