Skip to content

Commit

Permalink
Integrate formattedWalletOptions in staking component
Browse files Browse the repository at this point in the history
  • Loading branch information
ccali11 committed Jun 22, 2023
1 parent 441e3a6 commit cf040ce
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
42 changes: 28 additions & 14 deletions apps/web/src/pages/overview/components/Staking.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<script lang="ts" setup>
import { ref, onMounted, onUnmounted, watch } from 'vue'
import { FormattedWalletOption } from '@casimir/types'
import VueFeather from 'vue-feather'
import useUsers from '@/composables/users'
const { user } = useUsers()
const selectedWallet = ref(null as null | string)
const formattedAmountToStake = ref(null as null | string )
Expand Down Expand Up @@ -28,18 +32,7 @@ const handleInputOnAmountToStake = (event: any) => {
formattedAmountToStake.value = parts.join('.')
}
const formattedWalletOptions = ref(
[
{
provider: 'MetaMask',
connectedAccounts: [
'0xd557a5745d4560B24D36A68b52351ffF9c86A212',
'0xd557a5745d4560B24D36A68b52351ffF9c86A212',
'0xd557a5745d4560B24D36A68b52351ffF9c86A212',
]
}
]
)
const formattedWalletOptions = ref<Array<FormattedWalletOption>>([])
const convertString = (inputString: string) => {
if (inputString.length <= 4) {
Expand Down Expand Up @@ -83,6 +76,23 @@ const handleOutsideClick = (event: any) => {
}
}
const aggregateAddressesByProvider = () => {
formattedWalletOptions.value = []
// Iterate over user.value.accounts and aggregate addresses by provider
if(user.value){
const accounts = user.value.accounts
const providers = accounts.map((account) => account.walletProvider)
const uniqueProviders = [...new Set(providers)]
uniqueProviders.forEach((provider) => {
const addresses = accounts.filter((account) => account.walletProvider === provider).map((account) => account.address)
formattedWalletOptions.value.push({
provider,
addresses
})
})
}
}
watch(selectedWallet, () => {
selectedWallet.value? account_balance.value = '$1,234.56' : account_balance.value = '- - -'
})
Expand All @@ -99,11 +109,15 @@ watch(formattedAmountToStake, () => {
errorMessage.value = null
}
}
})
watch(user, () => {
aggregateAddressesByProvider()
})
onMounted(() => {
window.addEventListener('click', handleOutsideClick)
aggregateAddressesByProvider()
})
onUnmounted(() =>{
Expand Down Expand Up @@ -162,7 +176,7 @@ onUnmounted(() =>{


<button
v-for="wallet in item.connectedAccounts"
v-for="wallet in item.addresses"
:key="wallet"
class="w-full text-left rounded-[8px] py-[10px] px-[14px]
hover:bg-grey_1 flex justify-between items-center text-grey_4 hover:text-grey_6"
Expand Down
6 changes: 4 additions & 2 deletions common/types/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Account } from './interfaces/Account'
import { AccountWithStakingInfo } from './interfaces/AccountWithStakingInfo'
import { AddAccountOptions } from './interfaces/AddAccountOptions'
import { ApiResponse } from './interfaces/ApiResponse'
import { BalanceSnapshot } from './interfaces/BalanceSnapshot'
import { BrowserProviders } from './interfaces/BrowserProviders'
import { Cluster } from './interfaces/Cluster'
Expand All @@ -10,9 +11,9 @@ import { CryptoAddress } from './interfaces/CryptoAddress'
import { Currency } from './interfaces/Currency'
import { DeploymentConfig } from './interfaces/DeploymentConfig'
import { EthersProvider } from './interfaces/EthersProvider'
import { ApiResponse } from './interfaces/ApiResponse'
import { Event } from './interfaces/Event'
import { ExistingUserCheck } from './interfaces/ExistingUserCheck'
import { FormattedWalletOption } from './interfaces/FormattedWalletOption'
import { GasEstimate } from './interfaces/GasEstimate'
import { LoginCredentials } from './interfaces/LoginCredentials'
import { MessageRequest } from './interfaces/MessageRequest'
Expand All @@ -29,6 +30,7 @@ import { Validator } from './interfaces/Validator'
export type {
Account,
AccountWithStakingInfo,
ApiResponse,
AddAccountOptions,
BalanceSnapshot,
BrowserProviders,
Expand All @@ -39,9 +41,9 @@ export type {
Currency,
DeploymentConfig,
EthersProvider,
ApiResponse,
Event,
ExistingUserCheck,
FormattedWalletOption,
GasEstimate,
LoginCredentials,
MessageRequest,
Expand Down
6 changes: 6 additions & 0 deletions common/types/src/interfaces/FormattedWalletOption.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ProviderString } from './ProviderString'

export interface FormattedWalletOption {
provider: ProviderString,
addresses: string[],
}

0 comments on commit cf040ce

Please sign in to comment.