Skip to content

Commit

Permalink
refactor: move from console logs to basic logger module
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandermendes committed Nov 10, 2024
1 parent f16f20d commit 956252f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
6 changes: 6 additions & 0 deletions src/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-disable no-console */
export const logger = {
debug: console.debug,
warn: console.warn,
error: console.error,
};
5 changes: 3 additions & 2 deletions src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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]);

Expand Down
19 changes: 10 additions & 9 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -372,7 +373,7 @@ export const approveStaking = async (
{ gasPrice: 0 },
);

console.log(tx);
logger.debug(tx);
await tx.wait();
};

Expand All @@ -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();
};

Expand All @@ -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();
};

Expand All @@ -422,7 +423,7 @@ export const unstakeAll = async (

const tx = await staking.unstakeAll({ gasPrice: 0 });

console.log(tx);
logger.debug(tx);
await tx.wait();
};

Expand All @@ -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();
};

Expand All @@ -455,7 +456,7 @@ export const withdrawAll = async (

const tx = await staking.withdrawAll({ gasPrice: 0 });

console.log(tx);
logger.debug(tx);
await tx.wait();
};

Expand All @@ -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();
};

Expand All @@ -488,6 +489,6 @@ export const claimAll = async (

const tx = await staking.moveAllRewardsToPending({ gasPrice: 0 });

console.log(tx);
logger.debug(tx);
await tx.wait();
};

0 comments on commit 956252f

Please sign in to comment.