From 3c6864edce4406f9c328264031b8393f57deed4d Mon Sep 17 00:00:00 2001 From: stackchain <30806844+stackchain@users.noreply.github.com> Date: Thu, 12 May 2022 09:41:44 -0400 Subject: [PATCH] [chore] Fix empty checksum --- android/app/build.gradle | 4 +- ios/emurgo.xcodeproj/project.pbxproj | 48 +++++++++---------- legacy/components/Common/WalletAccountIcon.js | 2 +- src/appStorage.test.ts | 10 +++- src/appStorage.ts | 37 +++++++------- src/components/Icon/Icon.stories.tsx | 2 +- src/components/Icon/WalletAccount.tsx | 2 +- 7 files changed, 58 insertions(+), 47 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index b9a7ed5f57..a81331f06b 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -150,8 +150,8 @@ android { applicationId "com.emurgo" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 342 - versionName "4.7.13" + versionCode 344 + versionName "4.7.14" ndk { abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64" } diff --git a/ios/emurgo.xcodeproj/project.pbxproj b/ios/emurgo.xcodeproj/project.pbxproj index 95ac3a935c..112ca115a2 100644 --- a/ios/emurgo.xcodeproj/project.pbxproj +++ b/ios/emurgo.xcodeproj/project.pbxproj @@ -1345,7 +1345,7 @@ BUNDLE_ID_SUFFIX = ""; CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = "iPhone Distribution"; - CURRENT_PROJECT_VERSION = 389; + CURRENT_PROJECT_VERSION = 394; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_TEAM = F8NVT2G2L4; ENABLE_BITCODE = NO; @@ -1369,7 +1369,7 @@ INFOPLIST_PREPROCESS = NO; IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - MARKETING_VERSION = 4.7.13; + MARKETING_VERSION = 4.7.14; OTHER_LDFLAGS = ( "$(inherited)", "-ObjC", @@ -1395,7 +1395,7 @@ CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = "iPhone Distribution"; CODE_SIGN_STYLE = Manual; - CURRENT_PROJECT_VERSION = 389; + CURRENT_PROJECT_VERSION = 394; DEVELOPMENT_TEAM = F8NVT2G2L4; ENABLE_BITCODE = NO; HEADER_SEARCH_PATHS = ( @@ -1418,7 +1418,7 @@ INFOPLIST_PREPROCESS = NO; IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - MARKETING_VERSION = 4.7.13; + MARKETING_VERSION = 4.7.14; OTHER_LDFLAGS = ( "$(inherited)", "-ObjC", @@ -1441,7 +1441,7 @@ BUNDLE_DISPLAY_NAME = Yoroi; BUNDLE_ID_SUFFIX = ""; CLANG_ENABLE_MODULES = YES; - CURRENT_PROJECT_VERSION = 389; + CURRENT_PROJECT_VERSION = 394; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_TEAM = F8NVT2G2L4; ENABLE_BITCODE = NO; @@ -1469,7 +1469,7 @@ "$(inherited)", "\"$(SRCROOT)/$(TARGET_NAME)\"", ); - MARKETING_VERSION = 4.7.13; + MARKETING_VERSION = 4.7.14; OTHER_LDFLAGS = ( "$(inherited)", "-ObjC", @@ -1492,7 +1492,7 @@ BUNDLE_DISPLAY_NAME = "Yoroi Staging"; BUNDLE_ID_SUFFIX = .staging; CLANG_ENABLE_MODULES = YES; - CURRENT_PROJECT_VERSION = 389; + CURRENT_PROJECT_VERSION = 394; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_TEAM = F8NVT2G2L4; ENABLE_BITCODE = NO; @@ -1520,7 +1520,7 @@ "$(inherited)", "\"$(SRCROOT)/$(TARGET_NAME)\"", ); - MARKETING_VERSION = 4.7.13; + MARKETING_VERSION = 4.7.14; OTHER_LDFLAGS = ( "$(inherited)", "-ObjC", @@ -1545,7 +1545,7 @@ CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Manual; - CURRENT_PROJECT_VERSION = 389; + CURRENT_PROJECT_VERSION = 394; DEVELOPMENT_TEAM = ""; ENABLE_BITCODE = NO; HEADER_SEARCH_PATHS = ( @@ -1572,7 +1572,7 @@ "$(inherited)", "\"$(SRCROOT)/$(TARGET_NAME)\"", ); - MARKETING_VERSION = 4.7.13; + MARKETING_VERSION = 4.7.14; OTHER_LDFLAGS = ( "$(inherited)", "-ObjC", @@ -1595,7 +1595,7 @@ BUNDLE_DISPLAY_NAME = "Yoroi Staging"; BUNDLE_ID_SUFFIX = .staging; CLANG_ENABLE_MODULES = YES; - CURRENT_PROJECT_VERSION = 389; + CURRENT_PROJECT_VERSION = 394; DEVELOPMENT_TEAM = F8NVT2G2L4; ENABLE_BITCODE = NO; HEADER_SEARCH_PATHS = ( @@ -1622,7 +1622,7 @@ "$(inherited)", "\"$(SRCROOT)/$(TARGET_NAME)\"", ); - MARKETING_VERSION = 4.7.13; + MARKETING_VERSION = 4.7.14; OTHER_LDFLAGS = ( "$(inherited)", "-ObjC", @@ -1831,7 +1831,7 @@ BUNDLE_ID_SUFFIX = .staging; CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = "iPhone Distribution"; - CURRENT_PROJECT_VERSION = 389; + CURRENT_PROJECT_VERSION = 394; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_TEAM = F8NVT2G2L4; ENABLE_BITCODE = NO; @@ -1855,7 +1855,7 @@ INFOPLIST_PREPROCESS = NO; IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - MARKETING_VERSION = 4.7.13; + MARKETING_VERSION = 4.7.14; OTHER_LDFLAGS = ( "$(inherited)", "-ObjC", @@ -1979,7 +1979,7 @@ BUNDLE_ID_SUFFIX = .staging; CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = "iPhone Distribution"; - CURRENT_PROJECT_VERSION = 389; + CURRENT_PROJECT_VERSION = 394; DEVELOPMENT_TEAM = F8NVT2G2L4; ENABLE_BITCODE = NO; HEADER_SEARCH_PATHS = ( @@ -2002,7 +2002,7 @@ INFOPLIST_PREPROCESS = NO; IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - MARKETING_VERSION = 4.7.13; + MARKETING_VERSION = 4.7.14; OTHER_LDFLAGS = ( "$(inherited)", "-ObjC", @@ -2064,7 +2064,7 @@ BUNDLE_ID_SUFFIX = ""; CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = "iPhone Distribution"; - CURRENT_PROJECT_VERSION = 389; + CURRENT_PROJECT_VERSION = 394; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_TEAM = F8NVT2G2L4; ENABLE_BITCODE = NO; @@ -2088,7 +2088,7 @@ INFOPLIST_PREPROCESS = NO; IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - MARKETING_VERSION = 4.7.13; + MARKETING_VERSION = 4.7.14; OTHER_LDFLAGS = ( "$(inherited)", "-ObjC", @@ -2113,7 +2113,7 @@ BUNDLE_ID_SUFFIX = .staging; CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = "iPhone Distribution"; - CURRENT_PROJECT_VERSION = 389; + CURRENT_PROJECT_VERSION = 394; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_TEAM = F8NVT2G2L4; ENABLE_BITCODE = NO; @@ -2137,7 +2137,7 @@ INFOPLIST_PREPROCESS = NO; IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - MARKETING_VERSION = 4.7.13; + MARKETING_VERSION = 4.7.14; OTHER_LDFLAGS = ( "$(inherited)", "-ObjC", @@ -2163,7 +2163,7 @@ CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = "iPhone Distribution"; CODE_SIGN_STYLE = Manual; - CURRENT_PROJECT_VERSION = 389; + CURRENT_PROJECT_VERSION = 394; DEVELOPMENT_TEAM = F8NVT2G2L4; ENABLE_BITCODE = NO; HEADER_SEARCH_PATHS = ( @@ -2186,7 +2186,7 @@ INFOPLIST_PREPROCESS = NO; IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - MARKETING_VERSION = 4.7.13; + MARKETING_VERSION = 4.7.14; OTHER_LDFLAGS = ( "$(inherited)", "-ObjC", @@ -2210,7 +2210,7 @@ BUNDLE_ID_SUFFIX = .staging; CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = "iPhone Distribution"; - CURRENT_PROJECT_VERSION = 389; + CURRENT_PROJECT_VERSION = 394; DEVELOPMENT_TEAM = F8NVT2G2L4; ENABLE_BITCODE = NO; HEADER_SEARCH_PATHS = ( @@ -2233,7 +2233,7 @@ INFOPLIST_PREPROCESS = NO; IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - MARKETING_VERSION = 4.7.13; + MARKETING_VERSION = 4.7.14; OTHER_LDFLAGS = ( "$(inherited)", "-ObjC", diff --git a/legacy/components/Common/WalletAccountIcon.js b/legacy/components/Common/WalletAccountIcon.js index c768b82769..6577e0e882 100644 --- a/legacy/components/Common/WalletAccountIcon.js +++ b/legacy/components/Common/WalletAccountIcon.js @@ -48,7 +48,7 @@ type Props = {| |} const WalletAccountIcon = ({iconSeed, scalePx = 5, saturationFactor = 0, style}: Props) => { - const colorIdx = Buffer.from(iconSeed, 'hex')[0] % COLORS.length + const colorIdx = !iconSeed || iconSeed.length < 2 ? 0 : Buffer.from(iconSeed, 'hex')[0] % COLORS.length const color = COLORS[colorIdx] return ( diff --git a/src/appStorage.test.ts b/src/appStorage.test.ts index 5088432acd..5aa861104b 100644 --- a/src/appStorage.test.ts +++ b/src/appStorage.test.ts @@ -33,6 +33,12 @@ const mockedWalletData = Object.freeze({ id: 'wallet-id', externalChain: { addressGenerator: { + account: { + derivation_scheme: 'V2', + root_cached_key: + '7f53efa3c08093db3824235769079e96ef96b6680fc254f6c021ec420e4d1555' + + 'b5bafb0b1fc6c8040cc8f69f7c1948dfb4dcadec4acd09730c0efb39c6159362', + }, accountPubKeyHex: '8e4e2f11b6ac2a269913286e26339779ab8767579d18d173cdd324929d94e2c43e3ec212cc8a36ed9860579dfe1e3ef4d6de778c5dbdd981623b48727cd96247', }, @@ -197,9 +203,9 @@ describe('migrateWalletMetas()', () => { ...mockedWalletMeta, walletImplementationId: WALLETS.JORMUNGANDR_ITN.WALLET_IMPLEMENTATION_ID, checksum: { - TextPart: 'ATPE-6458', + TextPart: 'SKBE-5478', ImagePart: - '1dda96f3e8a39341da9549bef4be416c173eeb940f092cfc98d5c63a06c6007d326c77a599b1fd36ddf57507b8ea52537f129dac7bceb18c674bc3baab90411f', + '61942e0a01bd7eccff636a468e4d04bd05fe2169c2d26f83236ade661860d93e22c07ff007117555c6a15a92ac43f88e453d31c3b7a240dcd11ca3a7eba29321', }, } diff --git a/src/appStorage.ts b/src/appStorage.ts index b25626eb20..0b8d82ed46 100644 --- a/src/appStorage.ts +++ b/src/appStorage.ts @@ -9,8 +9,7 @@ import {Logger} from '../legacy/utils/logging' import storage from '../legacy/utils/storage' async function toShelleyWalletMeta(currentWalletMeta: Partial): Promise { - if (!currentWalletMeta?.id) throw new Error(`Wallet meta stored is corrupted. ${JSON.stringify(currentWalletMeta)}`) - + if (!currentWalletMeta.id) throw new Error(`Wallet meta stored is corrupted. ${JSON.stringify(currentWalletMeta)}`) const walletData = await storage.read(`/wallet/${currentWalletMeta.id}/data`) const walletMetaUpdate: Partial = {...currentWalletMeta} @@ -40,16 +39,22 @@ async function toShelleyWalletMeta(currentWalletMeta: Partial): Prom } // migrate checksum - if (!currentWalletMeta?.checksum) { + if (!currentWalletMeta.checksum || !currentWalletMeta.checksum?.ImagePart) { if (walletData != null && walletData?.externalChain?.addressGenerator != null) { - const {accountPubKeyHex} = walletData.externalChain.addressGenerator + const {accountPubKeyHex, account} = walletData.externalChain.addressGenerator switch (walletImplementationId) { case WALLETS.HASKELL_BYRON.WALLET_IMPLEMENTATION_ID: + checksum = legacyWalletChecksum(accountPubKeyHex || account.root_cached_key) + break + case WALLETS.HASKELL_SHELLEY_24.WALLET_IMPLEMENTATION_ID: + case WALLETS.HASKELL_SHELLEY.WALLET_IMPLEMENTATION_ID: + checksum = walletChecksum(accountPubKeyHex) + break case WALLETS.JORMUNGANDR_ITN.WALLET_IMPLEMENTATION_ID: - checksum = legacyWalletChecksum(accountPubKeyHex) + checksum = legacyWalletChecksum(account?.root_cached_key || '') break default: - checksum = walletChecksum(accountPubKeyHex) + checksum = {ImagePart: '', TextPart: ''} } } else { checksum = {ImagePart: '', TextPart: ''} @@ -104,25 +109,25 @@ function isWalletMeta(walletMeta: WalletMeta | object | undefined): walletMeta i return ( // prettier-ignore !!walletMeta && - 'id' in walletMeta + 'id' in walletMeta && typeof walletMeta.id === 'string' && - 'name' in walletMeta + 'name' in walletMeta && typeof walletMeta.name === 'string' && - 'networkId' in walletMeta + 'networkId' in walletMeta && typeof walletMeta.networkId === 'number' && - 'isHW' in walletMeta + 'isHW' in walletMeta && typeof walletMeta.isHW === 'boolean' && - 'isEasyConfirmationEnabled' in walletMeta + 'isEasyConfirmationEnabled' in walletMeta && typeof walletMeta.isEasyConfirmationEnabled === 'boolean' && - 'checksum' in walletMeta + 'checksum' in walletMeta && typeof walletMeta.checksum === 'object' && - ('provider' in walletMeta + ('provider' in walletMeta && typeof walletMeta.provider === 'string' || !('provider' in walletMeta)) && - 'walletImplementationId' in walletMeta - && typeof walletMeta.walletImplementationId === 'string' + 'walletImplementationId' in walletMeta + && typeof walletMeta.walletImplementationId === 'string' && Object.values(WALLET_IMPLEMENTATION_REGISTRY).includes(walletMeta?.walletImplementationId) && - ('isShelley' in walletMeta + ('isShelley' in walletMeta && typeof walletMeta.isShelley === 'boolean' || !('isShelley' in walletMeta)) ) diff --git a/src/components/Icon/Icon.stories.tsx b/src/components/Icon/Icon.stories.tsx index 4406edf35f..5a2a617a97 100644 --- a/src/components/Icon/Icon.stories.tsx +++ b/src/components/Icon/Icon.stories.tsx @@ -13,7 +13,7 @@ storiesOf('Icon', module).add('Gallery', () => { } title="Magnify" /> } title="Received" /> } title="Sent" /> - } title="WalletAccount" /> + } title="WalletAccount" /> } title="Emurgo" /> } title="Check" /> } title="YoroiWallet" /> diff --git a/src/components/Icon/WalletAccount.tsx b/src/components/Icon/WalletAccount.tsx index 032904c58c..9e23742445 100644 --- a/src/components/Icon/WalletAccount.tsx +++ b/src/components/Icon/WalletAccount.tsx @@ -46,7 +46,7 @@ type Props = { } export const WalletAccount = ({iconSeed, scalePx = 5, saturationFactor = 0, style}: Props) => { - const colorIdx = Buffer.from(iconSeed, 'hex')[0] % COLORS.length + const colorIdx = !iconSeed || iconSeed.length < 2 ? 0 : Buffer.from(iconSeed, 'hex')[0] % COLORS.length const color = COLORS[colorIdx] return (