Skip to content

Commit

Permalink
Implement Total Balance Across Connected Wallets
Browse files Browse the repository at this point in the history
  • Loading branch information
ccali11 committed Jul 6, 2023
1 parent 997b083 commit 9549b35
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
8 changes: 4 additions & 4 deletions apps/web/src/composables/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const totalWalletBalance = ref<BreakdownAmount>({

export default function useContracts() {
const { ethereumURL } = useEnvironment()
const { ethersProviderList, getEthersBrowserSigner } = useEthers()
const { ethersProviderList, getEthersBalance, getEthersBrowserSigner } = useEthers()
const { getEthersLedgerSigner } = useLedger()
const { getCurrentPrice } = usePrice()
const { getEthersTrezorSigner } = useTrezor()
Expand Down Expand Up @@ -189,8 +189,8 @@ export default function useContracts() {
async function getTotalWalletBalance() : Promise<BreakdownAmount> {
const promises = [] as Array<Promise<any>>
const addresses = (user.value as UserWithAccounts).accounts.map((account: Account) => account.address) as string[]
addresses.forEach((address) => { promises.push(getUserContractEventsTotals(address)) })
const totalWalletBalance = (await Promise.all(promises)).reduce((acc, curr) => acc + curr.StakeDeposited, 0)
addresses.forEach((address) => { promises.push(getEthersBalance(address)) })
const totalWalletBalance = (await Promise.all(promises)).reduce((acc, curr) => acc + curr, 0)
const totalWalletBalanceUSD = totalWalletBalance * (await getCurrentPrice({ coin: 'ETH', currency: 'USD' }))
return {
exchange: totalWalletBalance.toFixed(2) + ' ETH',
Expand Down Expand Up @@ -237,7 +237,7 @@ export default function useContracts() {

async function refreshBreakdown() {
setBreakdownValue({ name: 'currentStaked', ...await getCurrentStaked() })
// setBreakdownValue({ name: 'totalWalletBalance', ...await getTotalWalletBalance() })
setBreakdownValue({ name: 'totalWalletBalance', ...await getTotalWalletBalance() })
// setBreakdownValue({ name: 'stakingRewards', ...await getStakingRewards() })
}

Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/pages/overview/components/BreakdownChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ watch(selectedTimeframe, () => {
<div class="flex flex-wrap justify-between mb-[52px]">
<div>
<h6 class="blance_title mb-[15px]">
Connected Wallets Balance
Total Balance Across Connected Wallets
</h6>
<div class="flex items-center gap-[12px]">
<h5 class="blance_amount">
Expand Down
11 changes: 5 additions & 6 deletions apps/web/src/pages/overview/components/Staking.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,17 @@ watch(formattedAmountToStake, async () => {
let maxAmount
// minAmount is 0.0001 ETH
let minAmount = 0.0001
if(selectedWallet.value){
if (selectedWallet.value) {
maxAmount = await getEthersBalance(selectedWallet.value)
}else{
} else {
maxAmount = 0
}
if(floatAmount > maxAmount){
if (floatAmount > maxAmount) {
errorMessage.value = 'Insufficient Funds'
} else if(floatAmount < minAmount){
} else if (floatAmount < minAmount) {
errorMessage.value = 'Minimun Staking is 0.0001 ETH'
}else {
} else {
errorMessage.value = null
}
} else{
Expand All @@ -141,7 +141,6 @@ watch(formattedAmountToStake, async () => {
watch(user, () => {
aggregateAddressesByProvider()
termsOfServiceCheckbox.value = user.value?.agreedToTermsOfService as boolean
console.log('user.value.agreedToTermsOfService :>> ', user.value?.agreedToTermsOfService)
})
onMounted(async () => {
Expand Down

0 comments on commit 9549b35

Please sign in to comment.