Skip to content

Commit

Permalink
refactor: moving balances to balances store
Browse files Browse the repository at this point in the history
  • Loading branch information
dafuga committed Oct 24, 2023
1 parent 6f921fa commit f76b2cd
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 21 deletions.
1 change: 0 additions & 1 deletion src/components/elements/input/token/selector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
$: {
if (tokenOptions) {
filteredTokens = tokenOptions.map(tokenOption => {
const usdt = $tokens?.find(token => token.contract === 'tethertether')
const token = $tokens?.find(token => tokenOption.tokenName === token.name)
if (!token) {
Expand Down
7 changes: 1 addition & 6 deletions src/components/elements/input/token/selector/row.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@
let balance
$: {
if (token.balance) {
balance = token.balance
} else {
balance =
$balances && $balances.find((balance) => balance.tokenKey === token.key)?.quantity
}
balance = $balances && $balances.find((balance) => balance.tokenKey === token.key)?.quantity
if (typeof balance === 'string') {
formattedTokenBalance = balance
Expand Down
8 changes: 4 additions & 4 deletions src/pages/transfer/form.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import {Asset as CoreAsset} from '@greymass/eosio'
import {activeEvmSession, activeSession, activeBlockchain, currentAccountBalance} from '~/store'
import {Token, TokenOption, systemToken} from '~/stores/tokens'
import type {Token, TokenOption} from '~/stores/tokens'
import Label from '~/components/elements/input/label.svelte'
import Form from '~/components/elements/form.svelte'
Expand Down Expand Up @@ -73,8 +73,6 @@
Object.values(transferManagers).map(async (transferManagerData) => {
const TransferManagerClass = transferManagerData.transferClass
if (!$systemToken) return
// Only displaying accounts that support the current chain
if (!TransferManagerClass.supportedChains.includes($activeBlockchain?.id)) return
Expand All @@ -90,7 +88,7 @@
fromOptions.push({
tokenName: String(transferManagerData.token),
label: TransferManagerClass.fromDisplayString,
label: transferManagerData.fromLabel,
})
})
)
Expand Down Expand Up @@ -125,6 +123,8 @@
}
}
$: console.log({ fromOptions })
$: {
transferManager?.balance().then((balance) => {
availableToReceive = CoreAsset.from(
Expand Down
4 changes: 0 additions & 4 deletions src/pages/transfer/managers/eosEvmBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import {updateActiveAccount} from '~/stores/account-provider'
import {updateEvmBalance} from '~/stores/balances-provider'

export class EosEvmBridge extends TransferManager {
static from = 'eos'
static fromDisplayString = 'EOS'
static to = 'evm'
static toDisplayString = 'EOS (EVM)'
static supportedChains = ['eos']
static evmRequired = true

Expand Down
40 changes: 34 additions & 6 deletions src/pages/transfer/managers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,59 @@ import type {TransferManager} from './transferManager'
interface TransferType {
transferClass: typeof TransferManager
token: AssetType
from: string
fromLabel: string
to: string
toLabel: string
}

export const transferManagers: {[key: string]: TransferType} = {
'EOS - EOS (EVM)': {
transferClass: EosEvmBridge,
token: 'EOS'
token: 'EOS',
from: 'eos',
fromLabel: 'EOS',
to: 'evm',
toLabel: 'EOS (EVM)',
},
'EOS (EVM) - EOS': {
transferClass: EvmEosBridge,
token: 'EOS'
token: 'EOS',
from: 'evm',
fromLabel: 'EOS (EVM)',
to: 'eos',
toLabel: 'EOS',
},
'USDT - USDT (EVM)': {
transferClass: EosEvmBridge,
token: 'USDT'
token: 'USDT',
from: 'usdt',
fromLabel: 'USDT',
to: 'evm',
toLabel: 'USDT (EVM)',
},
'USDT (EVM) - USDT': {
transferClass: EvmEosBridge,
token: 'USDT'
token: 'USDT',
from: 'evm',
fromLabel: 'USDT (EVM)',
to: 'usdt',
toLabel: 'USDT',
},
'TLOS - TLOS (EVM)': {
transferClass: TelosEvmBridge,
token: 'TLOS'
token: 'TLOS',
from: 'tlos',
fromLabel: 'TLOS',
to: 'evm',
toLabel: 'TLOS (EVM)',
},
'TLOS (EVM) - TLOS': {
transferClass: EvmTelosBridge,
token: 'TLOS'
token: 'TLOS',
from: 'evm',
fromLabel: 'TLOS (EVM)',
to: 'tlos',
toLabel: 'TLOS',
},
}

0 comments on commit f76b2cd

Please sign in to comment.