From 956252f6c070efc156fc5caabdbbce9a77518d76 Mon Sep 17 00:00:00 2001 From: alexandermendes Date: Sun, 10 Nov 2024 09:42:09 +0000 Subject: [PATCH] refactor: move from console logs to basic logger module --- src/logger.ts | 6 ++++++ src/provider.tsx | 5 +++-- src/utils.ts | 19 ++++++++++--------- 3 files changed, 19 insertions(+), 11 deletions(-) create mode 100644 src/logger.ts diff --git a/src/logger.ts b/src/logger.ts new file mode 100644 index 0000000..74e812e --- /dev/null +++ b/src/logger.ts @@ -0,0 +1,6 @@ +/* eslint-disable no-console */ +export const logger = { + debug: console.debug, + warn: console.warn, + error: console.error, +}; diff --git a/src/provider.tsx b/src/provider.tsx index 26a4df9..7ab7a7a 100644 --- a/src/provider.tsx +++ b/src/provider.tsx @@ -38,6 +38,7 @@ import { StakingContext } from './context'; import { erc20abi } from './abis/erc20'; import { AuroraNetwork } from './types/network'; import { config } from './config'; +import { logger } from './logger'; type StakingProviderProps = { isConnected: boolean; @@ -221,7 +222,7 @@ export const StakingProvider = ({ setAccountSynced(true); } catch (error) { - console.error(error, 'Failed to sync account'); + logger.error(error, 'Failed to sync account'); } }, [ account, @@ -323,7 +324,7 @@ export const StakingProvider = ({ useEffect(() => { init().catch((error) => { - console.error(`Failed to initialize Staking Provider: ${error}`); + logger.error(`Failed to initialize Staking Provider: ${error}`); }); }, [init]); diff --git a/src/utils.ts b/src/utils.ts index 682f663..2832c4f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -2,6 +2,7 @@ import { BigNumber, ethers, providers } from 'ethers'; import { stakingAbi } from './abis/staking'; import { erc20abi } from './abis/erc20'; import { AuroraNetworkConfig } from './types/network'; +import { logger } from './logger'; export const getDeposit = async ( account: string, @@ -151,7 +152,7 @@ export const getStreamedAmounts = async ( return latestStreamedAmounts; } catch (error) { - console.error('Zero staked shares?', error); + logger.error('Zero staked shares?', error); return streamIds.map(() => ethers.BigNumber.from(0)); } @@ -372,7 +373,7 @@ export const approveStaking = async ( { gasPrice: 0 }, ); - console.log(tx); + logger.debug(tx); await tx.wait(); }; @@ -389,7 +390,7 @@ export const stake = async ( const tx = await staking.stake(amount, { gasPrice: 0 }); - console.log(tx); + logger.debug(tx); await tx.wait(); }; @@ -406,7 +407,7 @@ export const unstake = async ( const tx = await staking.unstake(amount, { gasPrice: 0 }); - console.log(tx); + logger.debug(tx); await tx.wait(); }; @@ -422,7 +423,7 @@ export const unstakeAll = async ( const tx = await staking.unstakeAll({ gasPrice: 0 }); - console.log(tx); + logger.debug(tx); await tx.wait(); }; @@ -439,7 +440,7 @@ export const withdraw = async ( const tx = await staking.withdraw(streamId, { gasPrice: 0 }); - console.log(tx); + logger.debug(tx); await tx.wait(); }; @@ -455,7 +456,7 @@ export const withdrawAll = async ( const tx = await staking.withdrawAll({ gasPrice: 0 }); - console.log(tx); + logger.debug(tx); await tx.wait(); }; @@ -472,7 +473,7 @@ export const claim = async ( const tx = await staking.moveRewardsToPending(streamId, { gasPrice: 0 }); - console.log(tx); + logger.debug(tx); await tx.wait(); }; @@ -488,6 +489,6 @@ export const claimAll = async ( const tx = await staking.moveAllRewardsToPending({ gasPrice: 0 }); - console.log(tx); + logger.debug(tx); await tx.wait(); };