Skip to content

Commit

Permalink
refactor: added evm tokens to tokens.json
Browse files Browse the repository at this point in the history
  • Loading branch information
dafuga committed Oct 27, 2023
1 parent dd3fcda commit 4048879
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 35 deletions.
20 changes: 3 additions & 17 deletions src/components/elements/input/token/selector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {writable} from 'svelte/store'
import {activeBlockchain} from '~/store'
import type {Token, TokenOption} from '~/stores/tokens'
import type {Token} from '~/stores/tokens'
import {tokens} from '~/stores/tokens'
import {balances} from '~/stores/balances'
Expand All @@ -15,7 +15,7 @@
export let defaultToken: Token | undefined = undefined
export let selectedToken: Token | undefined = undefined
export let tokenOptions: TokenOption[] | undefined = undefined
export let tokenOptions: Token[] | undefined = undefined
export let onTokenSelect: (token: Token) => void
export let showTokensWithoutBalance: boolean = false
Expand Down Expand Up @@ -44,21 +44,7 @@
$: {
if (tokenOptions) {
filteredTokens = tokenOptions.map(tokenOption => {
const token = $tokens?.find(token =>
String(tokenOption.tokenKey) === String(token.key) &&
String(tokenOption.tokenContract) === String(token.contract)
)
if (!token) {
throw new Error(`Token ${tokenOption.tokenName} not found.`)
}
return {
...token,
name: tokenOption.label || token.name,
}
})
filteredTokens = tokenOptions
} else {
filteredTokens =
$tokens?.filter((token) => {
Expand Down
25 changes: 14 additions & 11 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 type {Token, TokenOption} from '~/stores/tokens'
import {tokens, type Token} from '~/stores/tokens'
import Label from '~/components/elements/input/label.svelte'
import Form from '~/components/elements/form.svelte'
Expand All @@ -24,12 +24,12 @@
let validAmount = false
function handleFromChange(token: TokenOption) {
function handleFromChange(token: Token) {
resetForm() // reset form when changing from token
from = token
}
function handleToChange(token: TokenOption) {
function handleToChange(token: Token) {
to = token
}
Expand All @@ -56,8 +56,8 @@
}
}
let fromOptions: TokenOption[] = []
let toOptions: TokenOption[] = []
let fromOptions: Token[] = []
let toOptions: Token[] = []
let availableToReceive: CoreAsset | undefined
let generatingOptions = false
Expand Down Expand Up @@ -86,11 +86,14 @@
accountBalance = await transferManager.balance()
}
fromOptions.push({
tokenKey: transferManagerData.tokenKey,
tokenContract: String(transferManagerData.tokenContract),
label: transferManagerData.fromLabel,
})
const token = $tokens.find(token => token.key === transferManagerData.tokenKey)
if (!token) {
console.error(`Token ${transferManagerData.tokenKey} not found`)
return
}
fromOptions.push(token)
})
)
Expand All @@ -99,7 +102,7 @@
$: {
if (from) {
toOptions = fromOptions.filter((token) => token.tokenKey !== from?.name)
toOptions = fromOptions.filter((token) => token.name !== from?.name)
} else {
toOptions = fromOptions
}
Expand Down
2 changes: 1 addition & 1 deletion src/stores/balances-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export async function updateBalances(session: LinkSession) {
const evmBalances = await evmSession.getBalances()

evmBalances.forEach((balance) => {
const tokenKey = `evm-${balance.symbol.code}`
const tokenKey = `EVM-${balance.symbol.code}`
balances.push({
key: tokenKey,
chainId: session.chainId,
Expand Down
6 changes: 0 additions & 6 deletions src/stores/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ export interface Token {
balance?: Asset | string
}

export interface TokenOption {
tokenContract: NameType
tokenKey: string
label?: string
}

export interface TokenKeyParams {
chainId: ChainId
contract: NameType
Expand Down

0 comments on commit 4048879

Please sign in to comment.