Skip to content

Commit

Permalink
refactor: use app logger instead of console
Browse files Browse the repository at this point in the history
  • Loading branch information
greatertomi committed Feb 4, 2025
1 parent 9c7750d commit 525093a
Show file tree
Hide file tree
Showing 73 changed files with 214 additions and 181 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* eslint-disable no-console */
import React, { useEffect, useState, useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { Modal, Typography } from 'antd';
import { Button } from '@lace/common';
import { Button, logger } from '@lace/common';
import styles from './Announcement.module.scss';
import { ExtensionUpdateData } from '@lib/scripts/types';
import { fetchNotes } from './ReleaseNotes';
Expand All @@ -26,7 +25,7 @@ export const Announcement = ({ visible, onConfirm, version, reason }: Announceme
try {
notes = await fetchNotes(version);
} catch (error) {
console.log(error);
logger.info(error);
}
}
setReleaseNotes(notes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
ThemeSwitcher,
UserInfo
} from './components';
import { Switch } from '@lace/common';
import { logger, Switch } from '@lace/common';
import styles from './DropdownMenuOverlay.module.scss';
import { NetworkInfo } from './components/NetworkInfo';
import { Sections } from './types';
Expand Down Expand Up @@ -60,7 +60,7 @@ export const DropdownMenuOverlay: VFC<Props> = ({
useEffect(() => {
getBackgroundStorage()
.then((storage) => setNamiMigration(storage.namiMigration))
.catch(console.error);
.catch(logger.error);
}, []);

const openWalletAccounts = (wallet: AnyBip32Wallet<Wallet.WalletMetadata, Wallet.AccountMetadata>) => {
Expand Down Expand Up @@ -112,8 +112,7 @@ export const DropdownMenuOverlay: VFC<Props> = ({
try {
await backgroundServices.handleOpenPopup();
} catch (error) {
// improve logging
console.warn(error);
logger.warn(error);
}
} else {
window.location.reload();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { FailedMigration } from './FailedMigration';
import { MigrationInProgress } from './MigrationInProgress';
import { useSecrets } from '@lace/core';
import type { OnPasswordChange } from '@lace/core';
import { logger } from '@lace/common';

export interface MigrationContainerProps {
children: React.ReactNode;
Expand Down Expand Up @@ -85,7 +86,7 @@ export const MigrationContainer = ({ children, appMode }: MigrationContainerProp
setIsLoadingFirstTime(true);
setMigrationState(value.MIGRATION_STATE as MigrationState);
})
.catch((error) => console.error('Error fetching initial migration state:', error));
.catch((error) => logger.error('Error fetching initial migration state:', error));

// Observe changes to MIGRATION_STATE in storage
const observeMigrationState = async (changes: Record<string, Storage.StorageChange>) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState, useCallback } from 'react';
import { Wallet } from '@lace/cardano';
import { Button, PostHogAction } from '@lace/common';
import { Button, logger, PostHogAction } from '@lace/common';
import { useTranslation } from 'react-i18next';
import { Layout } from './Layout';
import { sectionTitle, DAPP_VIEWS } from '../config';
Expand Down Expand Up @@ -79,7 +79,7 @@ export const DappConfirmData = (): React.ReactElement => {
baseChannel: DAPP_CHANNELS.userPrompt,
properties: { readyToSignData: RemoteApiPropertyType.MethodReturningPromise }
},
{ logger: console, runtime }
{ logger, runtime }
);

return () => {
Expand Down Expand Up @@ -110,7 +110,7 @@ export const DappConfirmData = (): React.ReactElement => {
await req.sign();
redirectToSignSuccess();
} catch (error) {
console.error('error', error);
logger.error('error', error);
cancelTransaction();
redirectToSignFailure();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable react/no-multi-comp */
import React, { useEffect, useState } from 'react';
import { Banner, Button } from '@lace/common';
import { Banner, Button, logger } from '@lace/common';
import cn from 'classnames';
import { useTranslation } from 'react-i18next';
import { Layout } from './Layout';
Expand Down Expand Up @@ -80,7 +80,7 @@ const authorize = (authorization: 'deny' | 'just-once' | 'allow', url: string) =
baseChannel: DAPP_CHANNELS.userPrompt,
properties: { allowOrigin: RemoteApiPropertyType.MethodReturningPromise }
},
{ logger: console, runtime }
{ logger, runtime }
);

setTimeout(() => {
Expand All @@ -96,7 +96,7 @@ const dappDataApi = consumeRemoteApi<Pick<DappDataService, 'getDappInfo'>>(
getDappInfo: RemoteApiPropertyType.MethodReturningPromise
}
},
{ logger: console, runtime }
{ logger, runtime }
);

export const Connect = (): React.ReactElement => {
Expand All @@ -116,7 +116,7 @@ export const Connect = (): React.ReactElement => {
}
})
.catch((error) => {
console.error(error);
logger.error(error);
});
}, []);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { CreateCollateral } from './CreateCollateral';
import { APIErrorCode, ApiError } from '@cardano-sdk/dapp-connector';
import { useRedirection } from '@hooks';
import { dAppRoutePaths } from '@routes';
import { useObservable } from '@lace/common';
import { logger, useObservable } from '@lace/common';

enum ReturnResponse {
resolve = 'resolve',
Expand Down Expand Up @@ -51,12 +51,12 @@ const collateralRequestResponse = (action: RejectResponse | ResolveResponse) =>
properties: { getCollateralRequest: RemoteApiPropertyType.MethodReturningPromise }
},
{
logger: console,
logger,
runtime
}
);
} catch (error) {
console.error(error);
logger.error(error);
}
};

Expand Down Expand Up @@ -98,7 +98,7 @@ export const DappCollateralContainer = (): React.ReactElement => {
collateralRequestResponse({ response: ReturnResponse.resolve, utxos });
redirectToCreateSuccess();
} catch (error) {
console.error(error);
logger.error(error);
redirectToCreateFailure();
}
},
Expand All @@ -115,7 +115,7 @@ export const DappCollateralContainer = (): React.ReactElement => {
getCollateralRequest: RemoteApiPropertyType.MethodReturningPromise
}
},
{ logger: console, runtime }
{ logger, runtime }
)
.getCollateralRequest()
.then(({ dappInfo: requestDappInfo, collateralRequest }) => {
Expand Down Expand Up @@ -157,7 +157,7 @@ export const DappCollateralContainer = (): React.ReactElement => {
setIsCalculatingCollateral(false);
});
} catch (error) {
console.error(error);
logger.error(error);
redirectToCreateFailure();
}
}, [redirectToCreateFailure, balance, availableRewards]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from 'react';
import cn from 'classnames';
import { Button, PostHogAction } from '@lace/common';
import { Button, logger, PostHogAction } from '@lace/common';
import { useTranslation } from 'react-i18next';
import { Layout } from '../Layout';
import { useViewsFlowContext } from '@providers/ViewFlowProvider';
Expand Down Expand Up @@ -66,7 +66,7 @@ export const ConfirmTransaction = (): React.ReactElement => {
baseChannel: DAPP_CHANNELS.userPrompt,
properties: { readyToSignTx: RemoteApiPropertyType.MethodReturningPromise }
},
{ logger: console, runtime }
{ logger, runtime }
);

return () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useEffect, useMemo } from 'react';
import { useObservable } from '@lace/common';
import { logger, useObservable } from '@lace/common';
import {
DappTransaction,
TxDetailsCertificates,
Expand All @@ -26,7 +26,7 @@ import { createWalletAssetProvider } from '@cardano-sdk/wallet';
import { Skeleton } from 'antd';

import { useCurrencyStore } from '@providers';
import { logger, walletRepository } from '@lib/wallet-api-ui';
import { walletRepository } from '@lib/wallet-api-ui';
import { useComputeTxCollateral } from '@hooks/useComputeTxCollateral';
import { eraSlotDateTime } from '@src/utils/era-slot-datetime';
import { AddressBookSchema, useDbStateValue } from '@lib/storage';
Expand Down Expand Up @@ -124,7 +124,7 @@ export const DappTransactionContainer = withAddressBookContext(
logger
}),
timeout: TIMEOUT,
logger: console
logger
}),
summary: transactionSummaryInspector({
addresses: userAddresses,
Expand All @@ -138,7 +138,7 @@ export const DappTransactionContainer = withAddressBookContext(
logger
}),
timeout: TIMEOUT,
logger: console
logger
})
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-console */
import isPlainObject from 'lodash/isPlainObject';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { AssetProvider, AssetsMintedInspection, MintedAsset } from '@cardano-sdk/core';
Expand All @@ -12,6 +11,7 @@ import { getTransactionAssetsId } from '@src/stores/slices';
import { allowSignTx, pubDRepKeyToHash, disallowSignTx } from './utils';
import { useWalletStore } from '@stores';
import { TransactionWitnessRequest, WalletType } from '@cardano-sdk/web-extension';
import { logger } from '@lace/common';

export const useCreateAssetList = ({
assets,
Expand All @@ -33,7 +33,7 @@ export const useCreateAssetList = ({
})
.then((result) => setAssetsInfo(result))
.catch((error) => {
console.error(error);
logger.error(error);
});
}
}, [assetIds, assetProvider, assets]);
Expand Down Expand Up @@ -120,7 +120,7 @@ export const useCreateMintedAssetList = ({
})
.then((result) => setAssetsInfo(result))
.catch((error) => {
console.error(error);
logger.error(error);
});
}
}, [assetIds, assetProvider, assets]);
Expand Down Expand Up @@ -176,7 +176,7 @@ export const useSignWithHardwareWallet = (
await req.sign();
redirectToSignSuccess();
} catch (error) {
console.error('signWithHardwareWallet error', error);
logger.error('signWithHardwareWallet error', error);
disallow(false);
redirectToSignFailure();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { UserPromptService } from '@lib/scripts/background/services';
import { DAPP_CHANNELS, cardanoCoin } from '@src/utils/constants';
import { runtime } from 'webextension-polyfill';
import { of } from 'rxjs';
import { logger } from '@lace/common';

const { CertificateType } = Wallet.Cardano;

Expand All @@ -22,7 +23,7 @@ export const readyToSign = (): void => {
baseChannel: DAPP_CHANNELS.userPrompt,
properties: { readyToSignTx: RemoteApiPropertyType.MethodReturningPromise }
},
{ logger: console, runtime }
{ logger, runtime }
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { consumeRemoteApi, RemoteApiPropertyType } from '@cardano-sdk/web-extens
import { runtime } from 'webextension-polyfill';
import { Wallet } from '@lace/cardano';
import isEqual from 'lodash/isEqual';
import { logger } from '@lace/common';

interface DappProviderProps {
children: React.ReactNode;
Expand All @@ -23,7 +24,7 @@ export const DappProvider = ({ children, initialState }: DappProviderProps): Rea
authorizedDappsList: RemoteApiPropertyType.HotObservable
}
},
{ logger: console, runtime }
{ logger, runtime }
);

authorizedDappService?.authorizedDappsList.subscribe((dapps) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useEffect } from 'react';

import { NamiMigrationUpdatingYourWallet } from '@lace/core';
import { consumeRemoteApi, RemoteApiPropertyType } from '@cardano-sdk/web-extension';
import type { NamiMigrationAPI } from '@lib/scripts/background/nami-migration';
Expand All @@ -10,6 +9,7 @@ import { useCurrencyStore } from '@providers/currency';
import { MigrationState } from './migration-tool/migrator/migration-state.data';
import { useTheme } from '@providers/ThemeProvider/context';
import { NamiMigrationChannels } from '@lib/scripts/types';
import { logger } from '@lace/common';

const namiMigrationRemoteApi = consumeRemoteApi<Pick<NamiMigrationAPI, 'startMigration' | 'checkMigrationStatus'>>(
{
Expand All @@ -20,7 +20,7 @@ const namiMigrationRemoteApi = consumeRemoteApi<Pick<NamiMigrationAPI, 'startMig
}
},
{
logger: console,
logger,
runtime
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { APP_MODE_POPUP } from '@src/utils/constants';
import { useBackgroundServiceAPIContext } from '@providers';
import { BrowserViewSections, NamiMigrationChannels } from '@lib/scripts/types';
import { NamiMigration } from './NamiMigration';
import { logger } from '@lace/common';

const namiMigrationRemoteApi = consumeRemoteApi<Pick<NamiMigrationAPI, 'checkMigrationStatus' | 'abortMigration'>>(
{
Expand All @@ -21,7 +22,7 @@ const namiMigrationRemoteApi = consumeRemoteApi<Pick<NamiMigrationAPI, 'checkMig
}
},
{
logger: console,
logger,
runtime
}
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-console */
import { runtime, tabs } from 'webextension-polyfill';
import { State as MigrationData } from '../migrator/migration-data.data';
import { MigrationState } from '../migrator/migration-state.data';
Expand All @@ -7,6 +6,7 @@ import { createLaceMigrationPingListener } from './lace/create-lace-migration-pi
import { NAMI_EXTENSION_ID } from './lace/environment';
import { createLaceMigrationOpenListener } from './lace/create-lace-migration-open-listener';
import { LACE_EXTENSION_ID } from './nami/environment';
import { logger } from '@lace/common';

type CheckMigrationStatus = () => Promise<MigrationState>;

Expand Down Expand Up @@ -38,9 +38,9 @@ export const completeMigration: CompleteMigration = () => {
};

export const handleNamiRequests = (): void => {
console.log('[NAMI MIGRATION] createLaceMigrationPingListener');
logger.info('[NAMI MIGRATION] createLaceMigrationPingListener');
runtime.onMessageExternal.addListener(createLaceMigrationPingListener(NAMI_EXTENSION_ID));
console.log('[NAMI MIGRATION] createLaceMigrationOpenListener');
logger.info('[NAMI MIGRATION] createLaceMigrationOpenListener');
runtime.onMessageExternal.addListener(
createLaceMigrationOpenListener(NAMI_EXTENSION_ID, LACE_EXTENSION_ID, tabs.create)
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* eslint-disable no-console */
import { closeAllLaceWindows } from '@lib/scripts/background/util';
import { MessageSender, NamiMessages } from '../shared/types';
import { logger } from '@lace/common';

export const createLaceMigrationOpenListener =
(namiExtensionId: string, laceExtensionId: string, createTab: ({ url }: { url: string }) => void) =>
async (message: NamiMessages, sender: MessageSender): Promise<void> => {
console.log('[NAMI MIGRATION] createLaceMigrationOpenListener', message, sender);
logger.info('[NAMI MIGRATION] createLaceMigrationOpenListener', message, sender);
if (message === NamiMessages.open && sender.id === namiExtensionId) {
// First close all open lace tabs
await closeAllLaceWindows();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* eslint-disable consistent-return */
/* eslint-disable no-console */
import { MessageSender, NamiLacePingProtocol } from '../shared/types';
import { logger } from '@lace/common';

export const createLaceMigrationPingListener =
(namiExtensionId: string) =>
async (message: NamiLacePingProtocol, sender: MessageSender): Promise<void | NamiLacePingProtocol.pong> => {
console.log('[NAMI MIGRATION] createLaceMigrationPingListener', message, sender);
logger.info('[NAMI MIGRATION] createLaceMigrationPingListener', message, sender);
if (message === NamiLacePingProtocol.ping && sender.id === namiExtensionId) {
console.log('[NAMI MIGRATION] Sending pong message to Nami');
logger.info('[NAMI MIGRATION] Sending pong message to Nami');
return NamiLacePingProtocol.pong;
}
};
Loading

0 comments on commit 525093a

Please sign in to comment.