Skip to content

Commit

Permalink
fix: fixing token selector on send/receive page
Browse files Browse the repository at this point in the history
  • Loading branch information
dafuga committed Nov 10, 2023
1 parent 280ef85 commit 05f10ab
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 45 deletions.
4 changes: 4 additions & 0 deletions src/components/elements/input/token/selector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
export let tokenOptions: Token[] | undefined = undefined
export let onTokenSelect: (token: Token) => void
export let showTokensWithoutBalance: boolean = false
export let includeEvmTokens: boolean = false
$: {
if (defaultToken) {
Expand Down Expand Up @@ -48,6 +49,8 @@
} else {
filteredTokens =
$tokens?.filter((token) => {
if (token.evm && !includeEvmTokens) return false
const blockchainMatches = token.chainId.equals($activeBlockchain.chainId)
let balanceExists
if (!showTokensWithoutBalance) {
Expand All @@ -60,6 +63,7 @@
const queryMatches = String(token.name)
.toLowerCase()
.includes(query.toLowerCase())
return (
blockchainMatches &&
(queryExists || queryMatches) &&
Expand Down
9 changes: 6 additions & 3 deletions src/lib/evm/data/tokens.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"zh": "EOS (Enterprise Operation System) \u662f\u4e00\u4e2a\u533a\u5757\u94fe\u667a\u80fd\u5408\u7ea6\u5e73\u53f0\uff0c\u7531Block.one \u5f00\u53d1\u3002\u5b83\u81f4\u529b\u4e8e\u4e3a\u9ad8\u6027\u80fd\u5206\u5e03\u5f0f\u5e94\u7528\u63d0\u4f9b\u533a\u5757\u94fe\u5e95\u5c42\u670d\u52a1\u3002"
}
},
"chain_rank": ""
"chain_rank": "",
"evm": true
},
{
"key": "evm-usdt",
Expand All @@ -33,7 +34,8 @@
"logo": "https://raw.githubusercontent.com/eoscafe/eos-airdrops/master/logos/USDT.png",
"created_at": "2022-08-15T13:34:32.002Z"
},
"chain_rank": ""
"chain_rank": "",
"evm": true
},
{
"key": "evm-tlos",
Expand All @@ -49,6 +51,7 @@
"logo": "",
"created_at": "2022-08-15T13:34:32.004Z"
},
"chain_rank": ""
"chain_rank": "",
"evm": true
}
]
13 changes: 7 additions & 6 deletions src/pages/transfer/confirm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,27 @@
export let handleConfirm: () => void
export let handleBack: () => void
let depositAmountInUsd: string
let receivedAmountInUsd: string
let feeAmountInUsd: string
let depositAmountInUsd: string | undefined
let receivedAmountInUsd: string | undefined
let feeAmountInUsd: string | undefined
function getUsdValues() {
transferManager.convertToUsd(depositAmount?.value).then((usdValue) => {
transferManager.convertToUsd(depositAmount?.value, transferManagerData?.tokenName).then((usdValue) => {
depositAmountInUsd = usdValue
})
transferManager.convertToUsd(receivedAmount?.value).then((usdValue) => {
transferManager.convertToUsd(receivedAmount?.value, transferManagerData?.tokenName).then((usdValue) => {
receivedAmountInUsd = usdValue
})
if (feeAmount) {
transferManager.convertToUsd(feeAmount?.value).then((usdValue) => {
transferManager.convertToUsd(feeAmount?.value, transferManagerData?.tokenName).then((usdValue) => {
feeAmountInUsd = usdValue
})
}
}
getUsdValues()
</script>

Expand Down
6 changes: 0 additions & 6 deletions src/pages/transfer/form.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,8 @@
let generatingOptions = false
$: console.log({ balances: $balances })
$: balance = $balances.find((balance) => balance.tokenKey === from?.key)
$: console.log({ balance, from })
console.log({ tokens: $tokens })
async function generateOptions(evmSession?: EvmSession) {
if (!!generatingOptions) return
Expand Down
3 changes: 1 addition & 2 deletions src/pages/transfer/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
async function transfer() {
try {
transactResult = await transferManager?.transfer(deposit, received)
transactResult = await transferManager?.transfer(deposit, from!.symbol)
} catch (error) {
return (errorMessage = `Could not transfer. Error: ${
error.underlyingError?.message || JSON.stringify(error) === '{}'
Expand Down Expand Up @@ -99,7 +99,6 @@
try {
transferFee = await transferManager?.transferFee(transferAmount || received, from?.symbol)
} catch (error) {
console.log({ error })
if (
!error?.data?.message?.includes('insufficient funds for transfer') &&
!error?.data?.message?.includes('gas required exceeds allowance')
Expand Down
2 changes: 0 additions & 2 deletions src/pages/transfer/managers/eosEvmBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ export class EosEvmBridge extends TransferManager {
throw new Error('Failed to get config table from eosio.evm. Full error: ' + err)
}

console.log({rows: apiResponse.rows})

const config = apiResponse.rows[0]

const ingressBridgeFee = Asset.from(config.ingress_bridge_fee || '0.0000 EOS')
Expand Down
34 changes: 11 additions & 23 deletions src/pages/transfer/managers/transferManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import type {ethers} from 'ethers'
import type {EvmSession} from '~/lib/evm'
import {valueInFiat} from '~/lib/fiat'
import {activePriceTicker, waitForStoreValue} from '~/store'
import { systemToken } from '~/stores/tokens'

export abstract class TransferManager {
self: typeof TransferManager
static from: string
static to: string
static fromDisplayString: string
static toDisplayString: string
static supportedChains: string[]
static evmRequired: boolean = false

Expand All @@ -27,17 +24,24 @@ export abstract class TransferManager {
/* eslint-disable @typescript-eslint/no-unused-vars */
transfer(
_amount: string,
_tokenSymibol: Asset.SymbolType
_tokenSymbol: Asset.SymbolType,
_amountReceived?: string
): Promise<TransactResult | ethers.providers.TransactionResponse> {
throw new Error('transfer() not implemented')
}

transferFee(_amount?: string, tokenSymbol?: Asset.SymbolType): Promise<Asset> {
return Promise.resolve(Asset.from(0, tokenSymbol|| '4,EOS'))
return Promise.resolve(Asset.from(0, tokenSymbol || '4,EOS'))
}
/* eslint-enable @typescript-eslint/no-unused-vars */

async convertToUsd(amount: number): Promise<string> {
async convertToUsd(amount: number, token?: Asset.SymbolCodeType): Promise<string | undefined> {
const activeSystemToken = await waitForStoreValue(systemToken)

if (token && token !== activeSystemToken.symbol.code) {
return
}

const systemTokenPrice = await waitForStoreValue(activePriceTicker)

return valueInFiat(amount, systemTokenPrice)
Expand All @@ -56,22 +60,6 @@ export abstract class TransferManager {
throw new Error('toAddress() not implemented')
}

get from() {
return this.self.from
}

get to() {
return this.self.to
}

get fromDisplayString() {
return this.self.fromDisplayString
}

get toDisplayString() {
return this.self.toDisplayString
}

get supportedChains() {
return this.self.supportedChains
}
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 @@ -49,7 +49,7 @@ export async function updateBalances(session: LinkSession) {
if (provider) {
const balances = await provider.fetchBalances(session.auth.actor)
// Fetch evm balances when applicable
const evmSession = await waitForStoreValue(activeEvmSession)
const evmSession = get(activeEvmSession)
if (evmSession) {
const evmBalances = await evmSession.getBalances()

Expand Down
5 changes: 3 additions & 2 deletions src/stores/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {activeBlockchain, activePriceTicker, activeSession} from '~/store'
import {priceTicker} from '~/price-ticker'
import {Balance, balances} from '~/stores/balances'

import evmTokens from '../lib/evm/data/tokens.json'
import EvmTokens from '../lib/evm/data/tokens.json'

export interface Token {
key: string
Expand All @@ -20,6 +20,7 @@ export interface Token {
price?: number
logo?: string
balance?: Asset | string
evm?: boolean
}

export interface TokenKeyParams {
Expand Down Expand Up @@ -117,7 +118,7 @@ export function loadTokenMetadata(session: LinkSession) {

const allTokens = [
...AntelopeTokens,
...evmTokens,
...EvmTokens,
]

const chain = chainConfig(session.chainId)
Expand Down

0 comments on commit 05f10ab

Please sign in to comment.