From 3edbb19b28f37a600c8f6afb0ec2d415fdb23f83 Mon Sep 17 00:00:00 2001 From: ArturHoncharuk <73081258+ArturHoncharuk@users.noreply.github.com> Date: Thu, 19 Dec 2024 17:23:44 +0200 Subject: [PATCH 1/2] fix: solve app imports issue --- .../base/preview-modules/form-template/index.tsx | 1 - src/features/swap/utils/multi-route.ts | 9 ++------- src/features/swap/utils/wrap-native-address.ts | 5 ++++- .../lib/hooks/use-new-notifications-count.ts | 2 +- src/screens/Settings/Settings.constants.tsx | 9 ++++++--- src/utils/keys.ts | 3 ++- src/utils/mnemonics.ts | 3 ++- 7 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/features/harbor/components/base/preview-modules/form-template/index.tsx b/src/features/harbor/components/base/preview-modules/form-template/index.tsx index 30c9c8f9..6e961a7f 100644 --- a/src/features/harbor/components/base/preview-modules/form-template/index.tsx +++ b/src/features/harbor/components/base/preview-modules/form-template/index.tsx @@ -10,7 +10,6 @@ import { HarborPreViewData } from '@features/harbor/components/harbor-preview/model'; import { scale } from '@utils'; -import { scale } from '@utils/scaling'; import { styles } from './styles'; export const FormTemplate = ({ diff --git a/src/features/swap/utils/multi-route.ts b/src/features/swap/utils/multi-route.ts index 9774502a..5cc5d98c 100644 --- a/src/features/swap/utils/multi-route.ts +++ b/src/features/swap/utils/multi-route.ts @@ -1,11 +1,6 @@ -import { - SWAP_SUPPORTED_TOKENS, - TOKEN_ADDRESSES -} from '@features/swap/entities'; +import { SWAP_SUPPORTED_TOKENS } from '@features/swap/entities'; import { environment } from '@utils/environment'; -import { wrapNativeAddress } from './wrap-native-address'; - -export const addresses = TOKEN_ADDRESSES[environment]; +import { addresses, wrapNativeAddress } from './wrap-native-address'; export const isMultiHopSwapAvailable = (path: string[]): boolean => { return !!extractArrayOfMiddleMultiHopAddresses(path).address; diff --git a/src/features/swap/utils/wrap-native-address.ts b/src/features/swap/utils/wrap-native-address.ts index ceb01bdf..e0afd56d 100644 --- a/src/features/swap/utils/wrap-native-address.ts +++ b/src/features/swap/utils/wrap-native-address.ts @@ -1,7 +1,10 @@ import { ethers } from 'ethers'; import Config from '@constants/config'; +import { TOKEN_ADDRESSES } from '@features/swap/entities'; import { SwapToken } from '@features/swap/types'; -import { addresses } from './multi-route'; +import { environment } from '@utils/environment'; + +export const addresses = TOKEN_ADDRESSES[environment]; export function isNativeWrapped(path: string[]) { const wrappedPath = Config.SWAP_TOKENS.find( diff --git a/src/features/wallet-assets/lib/hooks/use-new-notifications-count.ts b/src/features/wallet-assets/lib/hooks/use-new-notifications-count.ts index 86a6e3c0..476afd31 100644 --- a/src/features/wallet-assets/lib/hooks/use-new-notifications-count.ts +++ b/src/features/wallet-assets/lib/hooks/use-new-notifications-count.ts @@ -1,7 +1,7 @@ import { useEffect, useState } from 'react'; import { AirDAOEventType } from '@appTypes'; import { useNotificationsQuery } from '@hooks'; -import useAppFocus from '@hooks/useAppFocused'; +import { useAppFocus } from '@hooks/useAppFocused'; import { AirDAOEventDispatcher } from '@lib'; import { Cache, CacheKey } from '@lib/cache'; diff --git a/src/screens/Settings/Settings.constants.tsx b/src/screens/Settings/Settings.constants.tsx index 48d3a04d..eae39741 100644 --- a/src/screens/Settings/Settings.constants.tsx +++ b/src/screens/Settings/Settings.constants.tsx @@ -1,6 +1,10 @@ import React from 'react'; -import { TelegramSettingsIcon } from '@components/svg/icons'; -import MediumIcon from '@components/svg/icons/MediumIcon'; + +import { + MediumIcon, + XTwitterIcon, + TelegramSettingsIcon +} from '@components/svg/icons'; import { AboutIcon, CompassIcon, @@ -10,7 +14,6 @@ import { WalletIcon, WatchListIcon } from '@components/svg/icons/v2/settings'; -import XTwitterIcon from '@components/svg/icons/XTwitterIcon'; import { COLORS } from '@constants/colors'; import { SettingsMenuItem } from '@screens/Settings/Settings.types'; diff --git a/src/utils/keys.ts b/src/utils/keys.ts index 22220bcf..df3c7796 100644 --- a/src/utils/keys.ts +++ b/src/utils/keys.ts @@ -1,8 +1,9 @@ -import bip39 from 'bip39'; // @ts-ignore import createHmac from 'create-hmac'; import * as Crypto from 'expo-crypto'; import { DEFAULT_WORDS } from '@constants/words'; +// eslint-disable-next-line @typescript-eslint/no-var-requires +const bip39 = require('bip39'); interface CreateHmacPDFK2Sizes { [key: string]: number; diff --git a/src/utils/mnemonics.ts b/src/utils/mnemonics.ts index 322aa9d9..45d52e64 100644 --- a/src/utils/mnemonics.ts +++ b/src/utils/mnemonics.ts @@ -1,6 +1,7 @@ -import bip39 from 'bip39'; import { DEFAULT_WORDS } from '@constants/words'; import { CryptoUtils } from './crypto'; +// eslint-disable-next-line @typescript-eslint/no-var-requires +const bip39 = require('bip39'); const generateNewMnemonic = async (size = 256) => { const random = await CryptoUtils.getRandomBytes(size / 8); From be1d5c5af055f060525f858d9ce66f17c0bae16a Mon Sep 17 00:00:00 2001 From: ArturHoncharuk <73081258+ArturHoncharuk@users.noreply.github.com> Date: Thu, 19 Dec 2024 17:35:15 +0200 Subject: [PATCH 2/2] fix: create wallet accounts argument & solve issue with imports --- src/lib/crypto/AirDAOKeys.ts | 1 - src/lib/crypto/AirDAOKeysStorage.ts | 3 ++- src/lib/index.ts | 2 +- .../CreateWallet/screens/CreateWalletStep2/index.tsx | 11 +++++++---- src/screens/Settings/screens/AccessKeys/index.tsx | 4 ++-- .../AccessKeys/tabs/Mnemonic/AccessKeys.Mnemonic.tsx | 4 ++-- src/utils/cashback.ts | 2 +- src/utils/wallet.ts | 2 +- 8 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/lib/crypto/AirDAOKeys.ts b/src/lib/crypto/AirDAOKeys.ts index 85248649..85f4c4bb 100644 --- a/src/lib/crypto/AirDAOKeys.ts +++ b/src/lib/crypto/AirDAOKeys.ts @@ -1,5 +1,4 @@ /* eslint-disable @typescript-eslint/no-var-requires */ - import { KeysUtils } from '@utils/keys'; const bip32 = require('bip32'); diff --git a/src/lib/crypto/AirDAOKeysStorage.ts b/src/lib/crypto/AirDAOKeysStorage.ts index 154e69eb..f9ad0694 100644 --- a/src/lib/crypto/AirDAOKeysStorage.ts +++ b/src/lib/crypto/AirDAOKeysStorage.ts @@ -266,4 +266,5 @@ class AirDAOKeysStorage { } } -export const singleAirDAOStorage = new AirDAOKeysStorage(); +const singleAirDAOStorage = new AirDAOKeysStorage(); +export default singleAirDAOStorage; diff --git a/src/lib/index.ts b/src/lib/index.ts index f4e302ea..4114b6d6 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -1,6 +1,6 @@ export * from './notification'; export * from './event-dispatcher'; -export { singleAirDAOStorage } from './crypto/AirDAOKeysStorage'; +export { default as AirDAOKeysStorage } from './crypto/AirDAOKeysStorage'; export * from './bridgeSDK'; export { default as PermissionService } from './permission'; export { default as UID } from './UID'; diff --git a/src/screens/CreateWallet/screens/CreateWalletStep2/index.tsx b/src/screens/CreateWallet/screens/CreateWalletStep2/index.tsx index 60f66622..f62873fe 100644 --- a/src/screens/CreateWallet/screens/CreateWalletStep2/index.tsx +++ b/src/screens/CreateWallet/screens/CreateWalletStep2/index.tsx @@ -10,6 +10,7 @@ import { Toast, ToastPosition, ToastType } from '@components/modular'; import { COLORS } from '@constants/colors'; import { useAddWalletStore } from '@features/add-wallet'; import { usePasscodeStore } from '@features/passcode'; +import { useAllAccounts } from '@hooks/database'; import { scale, verticalScale, WalletUtils } from '@utils'; import { MnemonicRandom } from './MnemonicRandom'; import { MnemonicSelected } from './MnemonicSelected'; @@ -20,6 +21,7 @@ export const CreateWalletStep2 = () => { const { mnemonic } = useAddWalletStore(); const { t } = useTranslation(); const { isPasscodeEnabled } = usePasscodeStore(); + const { data: accounts } = useAllAccounts(); const [walletMnemonicSelected, setWalletMnemonicSelected] = useState< { word: string; index: number }[] @@ -78,17 +80,18 @@ export const CreateWalletStep2 = () => { try { setLoading(true); - await WalletUtils.processWallet(mnemonic); + await WalletUtils.processWallet(mnemonic, accounts); navigateToSetUpSecurity(); } finally { setLoading(false); } }, [ + walletMnemonicSelected.length, + walletMnemonicArrayDefault.length, isMnemonicCorrect, - navigateToSetUpSecurity, mnemonic, - walletMnemonicArrayDefault.length, - walletMnemonicSelected.length + accounts, + navigateToSetUpSecurity ]); const onPositionIncorrect = () => { diff --git a/src/screens/Settings/screens/AccessKeys/index.tsx b/src/screens/Settings/screens/AccessKeys/index.tsx index a9f7aebb..781925a7 100644 --- a/src/screens/Settings/screens/AccessKeys/index.tsx +++ b/src/screens/Settings/screens/AccessKeys/index.tsx @@ -5,7 +5,7 @@ import { SafeAreaView } from 'react-native-safe-area-context'; import { SettingsTabParamsList } from '@appTypes'; import { Header } from '@components/composite'; import { AnimatedTabs } from '@components/modular'; -import { singleAirDAOStorage } from '@lib'; +import { AirDAOKeysStorage } from '@lib'; import { AccessKeysMnemonicTab } from '@screens/Settings/screens/AccessKeys/tabs/Mnemonic/AccessKeys.Mnemonic'; import { AccessKeysPrivateTab } from '@screens/Settings/screens/AccessKeys/tabs/Private/AccessKeys.Private'; import { styles } from './styles'; @@ -20,7 +20,7 @@ export const AccessKeysScreen = ({ route }: Props) => { (async () => { setIsMnemonicAvailable( ( - await singleAirDAOStorage.getWalletMnemonic(route.params.walletHash) + await AirDAOKeysStorage.getWalletMnemonic(route.params.walletHash) ).split(' ').length > 1 ); })(); diff --git a/src/screens/Settings/screens/AccessKeys/tabs/Mnemonic/AccessKeys.Mnemonic.tsx b/src/screens/Settings/screens/AccessKeys/tabs/Mnemonic/AccessKeys.Mnemonic.tsx index ed539597..6d54d145 100644 --- a/src/screens/Settings/screens/AccessKeys/tabs/Mnemonic/AccessKeys.Mnemonic.tsx +++ b/src/screens/Settings/screens/AccessKeys/tabs/Mnemonic/AccessKeys.Mnemonic.tsx @@ -9,7 +9,7 @@ import { import { useTranslation } from 'react-i18next'; import { Spacer, Text } from '@components/base'; import { COLORS } from '@constants/colors'; -import { singleAirDAOStorage } from '@lib'; +import { AirDAOKeysStorage } from '@lib'; import { scale } from '@utils'; import { styles } from './styles'; @@ -27,7 +27,7 @@ export const AccessKeysMnemonicTab = ({ if (walletHash) { (async () => { const mnemonic = ( - await singleAirDAOStorage.getWalletMnemonic(walletHash) + await AirDAOKeysStorage.getWalletMnemonic(walletHash) ).split(' '); setMnemonicPhrase(mnemonic); })(); diff --git a/src/utils/cashback.ts b/src/utils/cashback.ts index cd3062e9..bcddf74a 100644 --- a/src/utils/cashback.ts +++ b/src/utils/cashback.ts @@ -1,6 +1,6 @@ import AirDAOKeysForRef from '@lib/crypto/AirDAOKeysForRef'; import AirDAOKeysForRefStorage from '@lib/crypto/AirDAOKeysForRefStorage'; -import { singleAirDAOStorage } from '@lib/crypto/AirDAOKeysStorage'; +import singleAirDAOStorage from '@lib/crypto/AirDAOKeysStorage'; const getByHash = async (tmpHash: string) => { let tmpPublicAndPrivateResult = diff --git a/src/utils/wallet.ts b/src/utils/wallet.ts index 6e959860..4a6212c9 100644 --- a/src/utils/wallet.ts +++ b/src/utils/wallet.ts @@ -8,7 +8,7 @@ import { WalletDBModel } from '@database'; import AirDAOKeysForRef from '@lib/crypto/AirDAOKeysForRef'; -import { singleAirDAOStorage } from '@lib/crypto/AirDAOKeysStorage'; +import singleAirDAOStorage from '@lib/crypto/AirDAOKeysStorage'; import { CustomAppEvents, sendFirebaseEvent