From a2b3df1ee541401a00759626cc2779162086bd71 Mon Sep 17 00:00:00 2001 From: Juliano Lazzarotto <30806844+stackchain@users.noreply.github.com> Date: Tue, 26 Mar 2024 17:10:55 +0000 Subject: [PATCH] chore(wallet-mobile): clean ups (#3171) --- .../src/components/Modal/ModalContext.tsx | 2 ++ .../Links/common/useLinksRequestAction.tsx | 3 +-- .../Links/common/useLinksRequestRedirect.tsx | 3 +-- .../Links/common/useLinksRequestWallet.tsx | 3 +-- .../useCases/RequestSpecificAmountScreen.tsx | 2 -- .../src/metrics/metricsManager.tsx | 1 - .../src/wallet-manager/walletManager.ts | 3 --- .../src/yoroi-wallets/cardano/api/fetch.ts | 11 ++--------- .../yoroi-wallets/cardano/byron/ByronWallet.ts | 17 ----------------- .../src/yoroi-wallets/cardano/hw/hw.ts | 14 -------------- .../yoroi-wallets/cardano/promise/promise.ts | 9 --------- .../cardano/shelley/ShelleyWallet.ts | 16 ---------------- 12 files changed, 7 insertions(+), 77 deletions(-) diff --git a/apps/wallet-mobile/src/components/Modal/ModalContext.tsx b/apps/wallet-mobile/src/components/Modal/ModalContext.tsx index cae595ee30..7dd04387ab 100644 --- a/apps/wallet-mobile/src/components/Modal/ModalContext.tsx +++ b/apps/wallet-mobile/src/components/Modal/ModalContext.tsx @@ -1,5 +1,6 @@ import {useNavigation} from '@react-navigation/native' import React from 'react' +import {Keyboard} from 'react-native' type ModalState = { height: number @@ -43,6 +44,7 @@ export const ModalProvider = ({ } }, openModal: (title: ModalState['title'], content: ModalState['content'], height?: ModalState['height']) => { + Keyboard.dismiss() dispatch({type: 'open', title, content, height}) navigation.navigate('modal') }, diff --git a/apps/wallet-mobile/src/features/Links/common/useLinksRequestAction.tsx b/apps/wallet-mobile/src/features/Links/common/useLinksRequestAction.tsx index d6340edb16..3147498ccd 100644 --- a/apps/wallet-mobile/src/features/Links/common/useLinksRequestAction.tsx +++ b/apps/wallet-mobile/src/features/Links/common/useLinksRequestAction.tsx @@ -1,7 +1,7 @@ import {linksCardanoModuleMaker, LinksTransferRequestAdaWithLinkParams, LinksYoroiAction, useLinks} from '@yoroi/links' import {useTransfer} from '@yoroi/transfer' import * as React from 'react' -import {InteractionManager, Keyboard} from 'react-native' +import {InteractionManager} from 'react-native' import {useModal} from '../../../components/Modal/ModalContext' import {useSelectedWalletContext} from '../../../SelectedWallet' @@ -63,7 +63,6 @@ export const useLinksRequestAction = () => { const openRequestedPaymentAdaWithLink = React.useCallback( ({params, isTrusted}: {params: LinksTransferRequestAdaWithLinkParams; isTrusted: boolean}, decimals: number) => { - Keyboard.dismiss() const title = isTrusted ? strings.trustedPaymentRequestedTitle : strings.untrustedPaymentRequestedTitle const handleOnContinue = () => startTransferWithLink( diff --git a/apps/wallet-mobile/src/features/Links/common/useLinksRequestRedirect.tsx b/apps/wallet-mobile/src/features/Links/common/useLinksRequestRedirect.tsx index 1188df6470..f8795816e3 100644 --- a/apps/wallet-mobile/src/features/Links/common/useLinksRequestRedirect.tsx +++ b/apps/wallet-mobile/src/features/Links/common/useLinksRequestRedirect.tsx @@ -1,5 +1,5 @@ import * as React from 'react' -import {InteractionManager, Keyboard} from 'react-native' +import {InteractionManager} from 'react-native' import {useModal} from '../../../components/Modal/ModalContext' import {isEmptyString} from '../../../utils/utils' @@ -13,7 +13,6 @@ export const useLinksRequestRedirect = (redirectTo?: string) => { const askToRedirect = React.useCallback( (link: string) => { - Keyboard.dismiss() const content = openModal(strings.askToRedirectTitle, content, heightBreakpoint) }, diff --git a/apps/wallet-mobile/src/features/Links/common/useLinksRequestWallet.tsx b/apps/wallet-mobile/src/features/Links/common/useLinksRequestWallet.tsx index 5b095a2ffd..0fa04972d8 100644 --- a/apps/wallet-mobile/src/features/Links/common/useLinksRequestWallet.tsx +++ b/apps/wallet-mobile/src/features/Links/common/useLinksRequestWallet.tsx @@ -1,6 +1,6 @@ import {useLinks} from '@yoroi/links' import * as React from 'react' -import {InteractionManager, Keyboard} from 'react-native' +import {InteractionManager} from 'react-native' import {useModal} from '../../../components/Modal/ModalContext' import {useSelectedWalletContext} from '../../../SelectedWallet' @@ -15,7 +15,6 @@ export const useLinksRequestWallet = () => { const {action} = useLinks() const askToOpenAWallet = React.useCallback(() => { - Keyboard.dismiss() const content = openModal(strings.askToOpenAWalletTitle, content, heightBreakpoint) }, [openModal, strings.askToOpenAWalletTitle]) diff --git a/apps/wallet-mobile/src/features/Receive/useCases/RequestSpecificAmountScreen.tsx b/apps/wallet-mobile/src/features/Receive/useCases/RequestSpecificAmountScreen.tsx index eefb1a0799..1bf0ef2ef1 100644 --- a/apps/wallet-mobile/src/features/Receive/useCases/RequestSpecificAmountScreen.tsx +++ b/apps/wallet-mobile/src/features/Receive/useCases/RequestSpecificAmountScreen.tsx @@ -42,8 +42,6 @@ export const RequestSpecificAmountScreen = () => { const {openModal} = useModal() const handleOnGenerateLink = React.useCallback(() => { - Keyboard.dismiss() - track.receiveAmountGeneratedPageViewed({ada_amount: Number(amount)}) openModal(strings.amountToReceive, , modalHeight) }, [track, amount, openModal, strings.amountToReceive, selectedAddress, modalHeight]) diff --git a/apps/wallet-mobile/src/metrics/metricsManager.tsx b/apps/wallet-mobile/src/metrics/metricsManager.tsx index 773706bc6d..fffade2d69 100644 --- a/apps/wallet-mobile/src/metrics/metricsManager.tsx +++ b/apps/wallet-mobile/src/metrics/metricsManager.tsx @@ -31,7 +31,6 @@ const infoPlugin: EnrichmentPlugin = { type: PluginType.ENRICHMENT, setup: async () => Promise.resolve(), execute: async (event: Event) => { - Logger.info('[metrics-react-native]', event.event_type, event.event_properties ?? '- No properties') return Promise.resolve(event) }, } diff --git a/apps/wallet-mobile/src/wallet-manager/walletManager.ts b/apps/wallet-mobile/src/wallet-manager/walletManager.ts index 74c706a715..c595c681fa 100644 --- a/apps/wallet-mobile/src/wallet-manager/walletManager.ts +++ b/apps/wallet-mobile/src/wallet-manager/walletManager.ts @@ -5,7 +5,6 @@ import uuid from 'uuid' import {getCardanoWalletFactory} from '../yoroi-wallets/cardano/getWallet' import {isYoroiWallet, YoroiWallet} from '../yoroi-wallets/cardano/types' import {HWDeviceInfo} from '../yoroi-wallets/hw' -import {Logger} from '../yoroi-wallets/logging' import {makeWalletEncryptedStorage} from '../yoroi-wallets/storage' import {Keychain} from '../yoroi-wallets/storage/Keychain' import {rootStorage} from '../yoroi-wallets/storage/rootStorage' @@ -123,8 +122,6 @@ export class WalletManager { await this.walletsRootStorage.setItem(id, walletMeta) - Logger.debug('WalletManager::saveWallet::wallet', wallet) - if (isYoroiWallet(wallet)) { return wallet } diff --git a/apps/wallet-mobile/src/yoroi-wallets/cardano/api/fetch.ts b/apps/wallet-mobile/src/yoroi-wallets/cardano/api/fetch.ts index 54d4326a25..c9ae5c4566 100644 --- a/apps/wallet-mobile/src/yoroi-wallets/cardano/api/fetch.ts +++ b/apps/wallet-mobile/src/yoroi-wallets/cardano/api/fetch.ts @@ -10,7 +10,7 @@ type RequestMethod = 'POST' | 'GET' type ResponseChecker = (rawResponse: Record, requestPayload: Record) => Promise -const _checkResponse: ResponseChecker> = async (rawResponse, requestPayload) => { +const _checkResponse: ResponseChecker> = async (rawResponse) => { let responseBody = {} try { @@ -28,9 +28,6 @@ const _checkResponse: ResponseChecker> = async (rawResponse, throw new ApiHistoryError((responseBody as any).error.response) } - Logger.debug('Bad status code from server', status) - Logger.debug('Request payload:', requestPayload) - Logger.info('response', responseBody) throw new ApiError((responseBody as any).error?.response) } @@ -47,8 +44,6 @@ type FetchRequest = { export const checkedFetch = (request: FetchRequest) => { const {endpoint, payload, method, headers} = request const checkResponse = request.checkResponse || _checkResponse - Logger.info(`API call: ${endpoint}`) - const args = [ endpoint, { @@ -60,7 +55,7 @@ export const checkedFetch = (request: FetchRequest) => { return fetch(...args) // Fetch throws only for network/dns/related errors, not http statuses .catch((e) => { - Logger.info(`API call ${endpoint} failed`, e) + Logger.error(`API call ${endpoint} failed`, e) /* It really is TypeError according to https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch @@ -72,9 +67,7 @@ export const checkedFetch = (request: FetchRequest) => { throw e }) .then(async (r) => { - Logger.info(`API call ${endpoint} finished`) const response = await checkResponse(r, payload) - // Logger.debug('Response:', response) return response }) } diff --git a/apps/wallet-mobile/src/yoroi-wallets/cardano/byron/ByronWallet.ts b/apps/wallet-mobile/src/yoroi-wallets/cardano/byron/ByronWallet.ts index c09b0f67ca..f644991c3d 100644 --- a/apps/wallet-mobile/src/yoroi-wallets/cardano/byron/ByronWallet.ts +++ b/apps/wallet-mobile/src/yoroi-wallets/cardano/byron/ByronWallet.ts @@ -222,8 +222,6 @@ export class ByronWallet implements YoroiWallet { static async restore({walletMeta, storage}: {storage: App.Storage; walletMeta: WalletMeta}) { const data = await storage.getItem('data', parseWalletJSON) if (!data) throw new Error('Cannot read saved data') - Logger.debug('openWallet::data', data) - Logger.info('restore wallet', walletMeta.name) const networkId = data.networkId ?? walletMeta.networkId // can be null for versions < 3.0.0 const {internalChain, externalChain} = addressChains.restore({data, networkId}) @@ -395,8 +393,6 @@ export class ByronWallet implements YoroiWallet { timeout: NodeJS.Timeout | null = null startSync() { - Logger.info(`starting wallet: ${this.id}`) - const backgroundSync = async () => { try { await this.tryDoFullSync() @@ -415,7 +411,6 @@ export class ByronWallet implements YoroiWallet { stopSync() { if (!this.timeout) return - Logger.info(`stopping wallet: ${this.id}`) clearTimeout(this.timeout) } @@ -453,7 +448,6 @@ export class ByronWallet implements YoroiWallet { assert(this.hwDeviceInfo != null, 'no device info for hardware wallet') } } catch (e) { - Logger.error('wallet::_integrityCheck', e) throw new InvalidState((e as Error).message) } } @@ -541,7 +535,6 @@ export class ByronWallet implements YoroiWallet { .then((key) => key.derive(NUMBERS.STAKING_KEY_INDEX)) .then((key) => key.toRawKey()) - Logger.info(`getStakingKey: ${Buffer.from(await stakingKey.asBytes()).toString('hex')}`) return stakingKey } @@ -792,7 +785,6 @@ export class ByronWallet implements YoroiWallet { }) } catch (e) { if (e instanceof NotEnoughMoneyToSendError || e instanceof NoOutputsError) throw e - Logger.error(`shelley::createUnsignedGovernanceTx:: ${(e as Error).message}`, e) throw new CardanoError((e as Error).message) } } @@ -907,8 +899,6 @@ export class ByronWallet implements YoroiWallet { } async createVotingRegTx(pin: string, supportsCIP36: boolean) { - Logger.debug('CardanoWallet::createVotingRegTx called') - const bytes = await generatePrivateKeyForCatalyst() .then((key) => key.toRawKey()) .then((key) => key.asBytes()) @@ -999,7 +989,6 @@ export class ByronWallet implements YoroiWallet { } } catch (e) { if (e instanceof LocalizableError || e instanceof ExtendableError) throw e - Logger.error(`shelley::createVotingRegTx:: ${(e as Error).message}`, e) throw new CardanoError((e as Error).message) } } @@ -1058,7 +1047,6 @@ export class ByronWallet implements YoroiWallet { const appAdaVersion = await getCardanoAppMajorVersion(this.hwDeviceInfo, useUSB) if (!doesCardanoAppVersionSupportCIP36(appAdaVersion) && unsignedTx.voting.registration) { - Logger.info('CardanoWallet::signTxWithLedger: Ledger app version <= 5') const ledgerPayload = await Cardano.buildVotingLedgerPayloadV5( unsignedTx.unsignedTx, Number.parseInt(this.getChainNetworkId(), 10), @@ -1118,7 +1106,6 @@ export class ByronWallet implements YoroiWallet { async submitTransaction(signedTx: string) { const response: any = await legacyApi.submitTransaction(signedTx, this.getBackendConfig()) - Logger.info(response) return response as any } @@ -1383,8 +1370,6 @@ export class ByronWallet implements YoroiWallet { assert(this.isInitialized, 'doFullSync: isInitialized') if (isJormungandr(this.networkId)) return - Logger.info('Discovery done, now syncing transactions') - await this.discoverAddresses() await Promise.all([ @@ -1434,8 +1419,6 @@ export class ByronWallet implements YoroiWallet { // ========== UI state ============= // private updateState(update: Partial) { - Logger.debug('Wallet::updateState', update) - this.state = { ...this.state, ...update, diff --git a/apps/wallet-mobile/src/yoroi-wallets/cardano/hw/hw.ts b/apps/wallet-mobile/src/yoroi-wallets/cardano/hw/hw.ts index 489b6bdf68..ce9d92428f 100644 --- a/apps/wallet-mobile/src/yoroi-wallets/cardano/hw/hw.ts +++ b/apps/wallet-mobile/src/yoroi-wallets/cardano/hw/hw.ts @@ -94,19 +94,14 @@ const isAdaAppClosedError = (e: Error | unknown): boolean => { const mapLedgerError = (e: Error | any): Error | LocalizableError => { if (isAdaAppClosedError(e)) { - Logger.info('ledgerUtils::mapLedgerError: Ada app closed', e) return new AdaAppClosedError() } else if (isUserError(e)) { - Logger.info('ledgerUtils::mapLedgerError: User-side error', e) return new LedgerUserError() } else if (isRejectedError(e)) { - Logger.info('ledgerUtils::mapLedgerError: Rejected by user error', e) return new RejectedByUserError() } else if (isConnectionError(e)) { - Logger.info('ledgerUtils::mapLedgerError: General/BleError', e) return new GeneralConnectionError() } else if (e instanceof DeprecatedAdaAppError) { - Logger.info('ledgerUtils::mapLedgerError: Deprecated Ada app', e) return e } else { Logger.error('ledgerUtils::mapLedgerError: Unexpected error', e) @@ -216,15 +211,12 @@ export const getHWDeviceInfo = async ( useUSB = false, ): Promise => { try { - Logger.debug('ledgerUtils::getHWDeviceInfo called') const appAda = await connectionHandler(deviceId, deviceObj, useUSB) // assume single account in Yoroi const accountPath = makeCardanoAccountBIP44Path(getWalletType(walletImplementationId), NUMBERS.ACCOUNT_INDEX) - Logger.debug('bip44 account path', accountPath) // get Cardano's first account // i.e hdPath = [2147483692, 2147485463, 2147483648] const extendedPublicKeyResp: GetExtendedPublicKeyResponse = await appAda.getExtendedPublicKey(accountPath) - Logger.debug('extended public key', extendedPublicKeyResp) const serial: GetSerialResponse = await appAda.getSerial() const hwDeviceInfo = normalizeHWResponse({ extendedPublicKeyResp, @@ -232,8 +224,6 @@ export const getHWDeviceInfo = async ( deviceObj, ...serial, }) - Logger.info('ledgerUtils::getHWDeviceInfo: Ledger device OK') - Logger.info('hwDeviceInfo', hwDeviceInfo) await appAda.transport.close() return hwDeviceInfo } catch (e) { @@ -295,13 +285,9 @@ export const signTxWithLedger = async ( useUSB: boolean, ) => { try { - Logger.debug('ledgerUtils::signTxWithLedger called') const appAda = await connectionHandler(hwDeviceInfo.hwFeatures.deviceId, hwDeviceInfo.hwFeatures.deviceObj, useUSB) - Logger.debug('ledgerUtils::signTxWithLedger inputs', signRequest.tx.inputs) - Logger.debug('ledgerUtils::signTxWithLedger outputs', signRequest.tx.outputs) const ledgerSignature: SignTransactionResponse = await appAda.signTransaction(signRequest) await appAda.transport.close() - Logger.debug('ledgerUtils::ledgerSignature', JSON.stringify(ledgerSignature)) return ledgerSignature } catch (e) { throw mapLedgerError(e) diff --git a/apps/wallet-mobile/src/yoroi-wallets/cardano/promise/promise.ts b/apps/wallet-mobile/src/yoroi-wallets/cardano/promise/promise.ts index 39b34e633b..03bf3191bc 100644 --- a/apps/wallet-mobile/src/yoroi-wallets/cardano/promise/promise.ts +++ b/apps/wallet-mobile/src/yoroi-wallets/cardano/promise/promise.ts @@ -1,8 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import ExtendableError from 'es6-error' -import {Logger} from '../../logging' - export class IsLockedError extends ExtendableError {} export type Mutex = { lock: Promise | null | undefined @@ -14,20 +12,15 @@ export const delay = (duration: number): Promise => { } // Try locking mutex, waits if cannot be locked export const synchronize = (mutex: Mutex, factory: () => Promise): Promise => { - Logger.debug('Synchronize on', mutex) - if (!mutex.lock) { - Logger.debug('Synchronize lock fastpath') // We are first and can grab lock const myPromise = factory() mutex.lock = myPromise return myPromise.finally(() => { - Logger.debug('Synchronize unlock fastpath') // clean up if we do not have anything waiting on lock if (mutex.lock === myPromise) mutex.lock = null }) } else { - Logger.debug('Synchronize lock wait') // We need to update lock and at the same time wait for the original // function const orig: Promise = mutex.lock as any @@ -43,13 +36,11 @@ export const synchronize = (mutex: Mutex, factory: () => Promise): Promise mutex.lock = newLock // note: don't await on purpose orig.finally(() => { - Logger.debug('Synchronize lock resume') // Ok, waiting for the original is done, now let's do our work const myPromise = factory() myPromise .finally(() => { // clean up if we do not have anything waiting on lock - Logger.debug('Synchronize unlock') if (mutex.lock === newLock) mutex.lock = null }) .then(_resolve) diff --git a/apps/wallet-mobile/src/yoroi-wallets/cardano/shelley/ShelleyWallet.ts b/apps/wallet-mobile/src/yoroi-wallets/cardano/shelley/ShelleyWallet.ts index 6ec98911da..eb321c27b7 100644 --- a/apps/wallet-mobile/src/yoroi-wallets/cardano/shelley/ShelleyWallet.ts +++ b/apps/wallet-mobile/src/yoroi-wallets/cardano/shelley/ShelleyWallet.ts @@ -241,8 +241,6 @@ export const makeShelleyWallet = (constants: typeof MAINNET | typeof TESTNET | t static async restore({walletMeta, storage}: {storage: App.Storage; walletMeta: WalletMeta}) { const data = await storage.getItem('data', parseWalletJSON) if (!data) throw new Error('Cannot read saved data') - Logger.debug('openWallet::data', data) - Logger.info('restore wallet', walletMeta.name) const {internalChain, externalChain} = addressChains.restore({data}) @@ -381,8 +379,6 @@ export const makeShelleyWallet = (constants: typeof MAINNET | typeof TESTNET | t timeout: NodeJS.Timeout | null = null startSync() { - Logger.info(`starting wallet: ${this.id}`) - const backgroundSync = async () => { try { await this.tryDoFullSync() @@ -400,7 +396,6 @@ export const makeShelleyWallet = (constants: typeof MAINNET | typeof TESTNET | t stopSync() { if (!this.timeout) return - Logger.info(`stopping wallet: ${this.id}`) clearTimeout(this.timeout) } @@ -464,7 +459,6 @@ export const makeShelleyWallet = (constants: typeof MAINNET | typeof TESTNET | t .then((key) => key.derive(STAKING_KEY_INDEX)) .then((key) => key.toRawKey()) - Logger.info(`getStakingKey: ${Buffer.from(await stakingKey.asBytes()).toString('hex')}`) return stakingKey } @@ -644,7 +638,6 @@ export const makeShelleyWallet = (constants: typeof MAINNET | typeof TESTNET | t return yoroiUnsignedTx({unsignedTx, networkConfig: NETWORK_CONFIG, addressedUtxos, entries, primaryTokenId}) } catch (e) { if (e instanceof NotEnoughMoneyToSendError || e instanceof NoOutputsError) throw e - Logger.error(`shelley::createUnsignedTx:: ${(e as Error).message}`, e) throw new CardanoError((e as Error).message) } } @@ -689,7 +682,6 @@ export const makeShelleyWallet = (constants: typeof MAINNET | typeof TESTNET | t }) } catch (e) { if (e instanceof NotEnoughMoneyToSendError || e instanceof NoOutputsError) throw e - Logger.error(`shelley::createUnsignedGovernanceTx:: ${(e as Error).message}`, e) throw new CardanoError((e as Error).message) } } @@ -795,8 +787,6 @@ export const makeShelleyWallet = (constants: typeof MAINNET | typeof TESTNET | t } async createVotingRegTx(pin: string, supportsCIP36: boolean) { - Logger.debug('CardanoWallet::createVotingRegTx called') - const bytes = await generatePrivateKeyForCatalyst() .then((key) => key.toRawKey()) .then((key) => key.asBytes()) @@ -886,7 +876,6 @@ export const makeShelleyWallet = (constants: typeof MAINNET | typeof TESTNET | t } } catch (e) { if (e instanceof LocalizableError || e instanceof ExtendableError) throw e - Logger.error(`shelley::createVotingRegTx:: ${(e as Error).message}`, e) throw new CardanoError((e as Error).message) } } @@ -1030,7 +1019,6 @@ export const makeShelleyWallet = (constants: typeof MAINNET | typeof TESTNET | t async submitTransaction(signedTx: string) { const response: any = await legacyApi.submitTransaction(signedTx, BACKEND) - Logger.info(response) return response as any } @@ -1277,8 +1265,6 @@ export const makeShelleyWallet = (constants: typeof MAINNET | typeof TESTNET | t private async _doFullSync() { assert(this.isInitialized, 'doFullSync: isInitialized') - Logger.info('Discovery done, now syncing transactions') - await this.discoverAddresses() await Promise.all([this.syncUtxos(), this.transactionManager.doSync(this.getAddressesInBlocks(), BACKEND)]) @@ -1325,8 +1311,6 @@ export const makeShelleyWallet = (constants: typeof MAINNET | typeof TESTNET | t // ========== UI state ============= // private updateState(update: Partial) { - Logger.debug('Wallet::updateState', update) - this.state = { ...this.state, ...update,