From dab63c0b085143fd506dc96158930b22e7e81a56 Mon Sep 17 00:00:00 2001 From: Christopher Cali Date: Wed, 28 Jun 2023 12:17:57 -0700 Subject: [PATCH] Clean up unused methods and such --- apps/web/src/composables/contracts.ts | 88 ++------------------------- apps/web/src/composables/ethers.ts | 37 +---------- apps/web/src/composables/wallet.ts | 4 +- 3 files changed, 7 insertions(+), 122 deletions(-) diff --git a/apps/web/src/composables/contracts.ts b/apps/web/src/composables/contracts.ts index bfb216ccd..971fe3d00 100644 --- a/apps/web/src/composables/contracts.ts +++ b/apps/web/src/composables/contracts.ts @@ -47,23 +47,6 @@ export default function useContracts() { const { getEthersTrezorSigner } = useTrezor() const { isWalletConnectSigner, getEthersWalletConnectSigner } = useWalletConnect() - // watch(user, async () => { - // const promises = [] as any[] - // const accounts = user.value?.accounts - // accounts?.forEach(account => { - // promises.push(getCurrentStaked(account.address)) - // }) - // const promisesResults = await Promise.all(promises) - // const totalUSD = Math.round(promisesResults.reduce((a, b) => a + b, 0) * 100) / 100 - // const currentEthPrice = await getCurrentPrice({coin: 'ETH', currency: 'USD'}) - // const totalETH = (Math.round((totalUSD / currentEthPrice)*100) / 100).toString() - // currentStaked.value = { - // usd: '$' + totalUSD, - // exchange: totalETH + ' ETH' - // } - // await getUserContractEventsTotals(user.value?.accounts[0].address as string) - // }) - async function deposit({ amount, walletProvider }: { amount: string, walletProvider: ProviderString }) { // const ethAmount = (parseInt(amount) / (await getCurrentPrice({ coin: 'ETH', currency: 'USD' }))).toString() const signerCreators = { @@ -160,12 +143,6 @@ export default function useContracts() { })) } - // async function initializeBreakdown() { - // setBreakdownValue({ name: 'currentStaked', ...await getCurrentStaked() }) - // setBreakdownValue({ name: 'totalDeposited', ...await getTotalDeposited() }) - // setBreakdownValue({ name: 'stakingRewards', ...await getStakingRewards() }) - // } - async function refreshBreakdown() { setBreakdownValue({ name: 'currentStaked', ...await getCurrentStaked() }) // setBreakdownValue({ name: 'totalDeposited', ...await getTotalDeposited() }) @@ -234,25 +211,10 @@ export default function useContracts() { } async function listenForContractEvents() { - manager.on('StakeDeposited', async (event: any) => { - console.log('got to StakeDeposited!') - }) - - manager.on('StakeRebalanced', async (event: any) => { - console.log('got to StakeRebalanced!') - await refreshBreakdown() - }) - - manager.on('WithdrawalInitiated', async (event: any) => { - console.log('got to WithdrawalInitiated!') - }) - - manager.on('WithdrawalFulfilled', async (event: any) => { - console.log('got to WithdrawalFulfilled!') - // const promises = [] as Array> - // promises.push(...getUserEventPromises()) - // await refreshUserEventsTotals(promises) - }) + manager.on('StakeDeposited', async (event: any) => await refreshBreakdown()) + manager.on('StakeRebalanced', async (event: any) => await refreshBreakdown()) + manager.on('WithdrawalInitiated', async (event: any) => await refreshBreakdown()) + manager.on('WithdrawalFulfilled', async (event: any) => await refreshBreakdown()) } async function withdraw({ amount, walletProvider }: { amount: string, walletProvider: ProviderString }) { @@ -312,45 +274,6 @@ export default function useContracts() { return userEventTotals } - async function setUserContractTotals(eventTotals: any) { - // console.log('eventTotals.WithdrawalInitiated :>> ', eventTotals.WithdrawalInitiated) - // console.log('eventTotals.WithdrawalFulfilled :>> ', eventTotals.WithdrawalFulfilled) - - /* CurrentStaked (eventTotals.StakeDeposited) */ - if (eventTotals.StakeDeposited > 0) { - const exchangeCurrentStaked = eventTotals.StakeDeposited - eventTotals.WithdrawalInitiated - const usdCurrentStaked = exchangeCurrentStaked * (await getCurrentPrice({ coin: 'ETH', currency: 'USD' })) - const exchangeCurrentStakedRounded = Math.round(exchangeCurrentStaked * 100) / 100 - const usdCurrentStakedRounded = Math.round(usdCurrentStaked * 100) / 100 - currentStaked.value = { - exchange: exchangeCurrentStakedRounded + ' ETH', - usd: '$ ' + usdCurrentStakedRounded - } - } - - /* Staking Rewards (eventTotals.StakeRebalanced) */ - if (eventTotals.StakeRebalanced > 0) { - const exchangeStakingRewards = eventTotals.StakeRebalanced - const usdStakingRewards = exchangeStakingRewards * (await getCurrentPrice({ coin: 'ETH', currency: 'USD' })) - const exchangeStakingRewardsRounded = Math.round(exchangeStakingRewards * 100) / 100 - const usdStakingRewardsRounded = Math.round(usdStakingRewards * 100) / 100 - stakingRewards.value = { - exchange: exchangeStakingRewardsRounded + ' ETH', - usd: '$ ' + usdStakingRewardsRounded - } - } - - /* TotalDeposited */ - const exchangeTotalDeposited = parseFloat(currentStaked.value.exchange.replace(' ETH', '')) + parseFloat(stakingRewards.value.exchange.replace(' ETH', '')) - const usdTotalDeposited = parseFloat(currentStaked.value.usd.replace('$ ', '')) + parseFloat(stakingRewards.value.usd.replace('$ ', '')) - const exchangeTotalDepositedRounded = Math.round(exchangeTotalDeposited * 100) / 100 - const usdTotalDepositedRounded = Math.round(usdTotalDeposited * 100) / 100 - totalDeposited.value = { - usd: '$ ' + usdTotalDepositedRounded, - exchange: exchangeTotalDepositedRounded + ' ETH' - } - } - return { currentStaked, manager, @@ -359,12 +282,9 @@ export default function useContracts() { deposit, getDepositFees, getPools, - getUserContractEventsTotals, getCurrentStaked, listenForContractEvents, - // initializeBreakdown, refreshBreakdown, - setUserContractTotals, withdraw } } \ No newline at end of file diff --git a/apps/web/src/composables/ethers.ts b/apps/web/src/composables/ethers.ts index f7196aa55..35e3c073f 100644 --- a/apps/web/src/composables/ethers.ts +++ b/apps/web/src/composables/ethers.ts @@ -5,13 +5,11 @@ import { GasEstimate, LoginCredentials, MessageRequest, ProviderString } from '@ import useAuth from '@/composables/auth' import useContracts from '@/composables/contracts' import useEnvironment from '@/composables/environment' -import usePrice from '@/composables/price' import useUsers from '@/composables/users' const { createSiweMessage, signInWithEthereum } = useAuth() +const { manager, getCurrentStaked, refreshBreakdown } = useContracts() const { ethereumURL } = useEnvironment() -const { manager, getCurrentStaked, getUserContractEventsTotals, refreshBreakdown, setUserContractTotals } = useContracts() -const { getCurrentPrice } = usePrice() const { user } = useUsers() export default function useEthers() { @@ -150,36 +148,6 @@ export default function useEthers() { return maxAfterFees } - function getUserEventPromises() { - const promises = [] as Array> - user.value?.accounts?.forEach((account: Account) => { - const { address } = account - promises.push(getUserContractEventsTotals(address)) - }) - return promises - } - - async function refreshUserEventsTotals(promises: Array>) { - try { - const userEventTotals = (await Promise.all(promises)).reduce((acc, curr) => { - return { - StakeDeposited: acc.StakeDeposited + curr.StakeDeposited, - StakeRebalanced: acc.StakeRebalanced + curr.StakeRebalanced, - WithdrawalInitiated: acc.WithdrawalInitiated + curr.WithdrawalInitiated, - WithdrawalFulfilled: acc.WithdrawalFulfilled += curr.WithdrawalFulfilled - } - }, { - StakeDeposited: 0, - StakeRebalanced: 0, - WithdrawalInitiated: 0, - WithdrawalFulfilled: 0 - }) - await setUserContractTotals(userEventTotals) - } catch (err) { - console.error('There was an error in refreshUserEventsTotals :>> ', err) - } - } - async function listenForTransactions() { const provider = new ethers.providers.JsonRpcProvider(ethereumURL) provider.on('block', async (blockNumber: number) => { @@ -187,7 +155,6 @@ export default function useEthers() { const addresses = user.value?.accounts.map((account: Account) => account.address) as Array const block = await provider.getBlockWithTransactions(blockNumber) const transactions = block.transactions - const promises = [] as Array> transactions.map(async (tx) => { if (addresses.includes(tx.from.toLowerCase())) { console.log('tx :>> ', tx) @@ -195,10 +162,8 @@ export default function useEthers() { console.log('response :>> ', response) await refreshBreakdown() await getCurrentStaked() - // promises.push(...getUserEventPromises()) } }) - // await refreshUserEventsTotals(promises) }) await new Promise(() => { // Wait indefinitely using a Promise that never resolves diff --git a/apps/web/src/composables/wallet.ts b/apps/web/src/composables/wallet.ts index 6f1883e8e..b64647c35 100644 --- a/apps/web/src/composables/wallet.ts +++ b/apps/web/src/composables/wallet.ts @@ -35,12 +35,12 @@ const selectedCurrency = ref('') const toAddress = ref('0x728474D29c2F81eb17a669a7582A2C17f1042b57') export default function useWallet() { - const { getUserContractEventsTotals, listenForContractEvents, refreshBreakdown, setUserContractTotals } = useContracts() + const { listenForContractEvents, refreshBreakdown } = useContracts() const { estimateEIP1559GasFee, ethersProviderList, getEthersAddressWithBalance, getEthersBalance, sendEthersTransaction, signEthersMessage, listenForTransactions, loginWithEthers, getEthersBrowserProviderSelectedCurrency, switchEthersNetwork } = useEthers() const { getLedgerAddress, loginWithLedger, sendLedgerTransaction, signLedgerMessage } = useLedger() const { solanaProviderList, sendSolanaTransaction, signSolanaMessage } = useSolana() const { getTrezorAddress, loginWithTrezor, sendTrezorTransaction, signTrezorMessage } = useTrezor() - const { user, getUser, setUser, addAccount, checkIfSecondaryAddress, checkIfPrimaryUserExists, removeAccount, updatePrimaryAddress, userAddresses } = useUsers() + const { user, getUser, setUser, addAccount, checkIfSecondaryAddress, checkIfPrimaryUserExists, removeAccount, updatePrimaryAddress } = useUsers() const { getWalletConnectAddress, loginWithWalletConnect, sendWalletConnectTransaction, signWalletConnectMessage } = useWalletConnect() function getColdStorageAddress(provider: ProviderString, currency: Currency = 'ETH') {