From f9052e2fe0394d81caaf74b057d7010a8ae40290 Mon Sep 17 00:00:00 2001 From: liangping <18786721@qq.com> Date: Mon, 29 Nov 2021 22:38:03 +0800 Subject: [PATCH] add deposit --- src/libs/data/data.js | 7 +- src/libs/osmos.js | 68 ++-- .../components/KlineTrade/DepositeWindow.vue | 290 +++++++----------- src/views/components/KlineTrade/PlaceForm.vue | 22 +- 4 files changed, 164 insertions(+), 223 deletions(-) diff --git a/src/libs/data/data.js b/src/libs/data/data.js index a19c679c..a4924cb5 100644 --- a/src/libs/data/data.js +++ b/src/libs/data/data.js @@ -327,9 +327,12 @@ export function isTestnet() { || window.location.search.indexOf('testnet') > -1) } -export function formatToken(token, IBCDenom = {}, decimals = 2) { +export function formatToken(token, IBCDenom = {}, decimals = 2, withDenom = true) { if (token) { - return `${formatTokenAmount(token.amount, decimals, token.denom)} ${formatTokenDenom(IBCDenom[token.denom] || token.denom)}` + if (withDenom) { + return `${formatTokenAmount(token.amount, decimals, token.denom)} ${formatTokenDenom(IBCDenom[token.denom] || token.denom)}` + } + return formatTokenAmount(token.amount, decimals, token.denom) } return token } diff --git a/src/libs/osmos.js b/src/libs/osmos.js index cebe89e4..572cdbfb 100644 --- a/src/libs/osmos.js +++ b/src/libs/osmos.js @@ -35,34 +35,46 @@ export const poolIds = { } export const CoinGeckoMap = { - ATOM: 'cosmos', - OSMO: 'osmosis', - IRIS: 'iris-network', - AKT: 'akash-network', - LUNA: 'terra-luna', - UST: 'terrausd', - KRT: 'terra-krw', - BAND: 'band-protocol', - CRO: 'crypto-com-chain', - KAVA: 'kava', - OKT: 'okexchain', - CTK: 'certik', - XPRT: 'persistence', - REGEN: 'regen', - SCRT: 'secret', - DVPN: 'sentinel', - ION: 'ion', - ROWAN: 'sifchain', - IOV: 'starname', - BTSG: 'bitsong', - NGM: 'e-money', - EEUR: 'e-money-eur', - LIKE: 'likecoin', - JUNO: 'juno-network', - STGZ: 'stargaze-protocol', - VDL: 'vidulum', - XKI: 'ki', - INJ: 'injective-protocol', + ATOM: ['cosmos'], + OSMO: ['osmosis'], + IRIS: ['iris-network'], + AKT: ['akash-network'], + LUNA: ['terra-luna'], + UST: ['terrausd'], + KRT: ['terra-krw'], + BAND: ['band-protocol'], + CRO: ['crypto-com-chain'], + KAVA: ['kava'], + OKT: ['okexchain'], + CTK: ['certik'], + XPRT: ['persistence'], + REGEN: ['regen'], + SCRT: ['secret'], + DVPN: ['sentinel'], + ION: ['ion'], + ROWAN: ['sifchain'], + IOV: ['starname'], + BTSG: ['bitsong'], + NGM: ['e-money'], + EEUR: ['e-money-eur'], + LIKE: ['likecoin'], + JUNO: ['juno-network'], + STGZ: ['stargaze-protocol'], + VDL: ['vidulum'], + XKI: ['ki'], + INJ: ['injective-protocol'], +} + +export function getChainConfigForSymbol(symbol) { + const key = CoinGeckoMap[symbol] + if (key) { + const confs = getLocalChains() + return Object.values(confs).find(x => { + console.log(x.coingecko, key) + return x.coingecko === key[0] + }) + } + return null } export function getPairName(pool, denomTrace, type = 'base', isFormat = true) { diff --git a/src/views/components/KlineTrade/DepositeWindow.vue b/src/views/components/KlineTrade/DepositeWindow.vue index 681a14d1..12a528f6 100644 --- a/src/views/components/KlineTrade/DepositeWindow.vue +++ b/src/views/components/KlineTrade/DepositeWindow.vue @@ -4,14 +4,14 @@ id="trading-deposte-window" centered size="md" - title="Deposit / Withdraw" + title="Cross Chain Deposit Tokens" ok-title="Send" hide-header-close scrollable :ok-disabled="!address" @hidden="resetModal" @ok="handleOk" - @show="loadBalance" + @show="init" > @@ -283,23 +286,25 @@ export default { const p1 = this.$store.state.chains.quotes[this.target] return p1 && this.total > 0 ? (p1.usd * this.total).toFixed(2) : '-' }, - computeAccounts() { + currentDenom() { + if (this.pool && this.pool.poolAssets) { + const mode = this.type === 1 ? 0 : 1 + const { denom } = this.pool.poolAssets[mode].token + return denom + } return '' }, available() { if (this.pool && this.pool.poolAssets) { - const mode = this.type === 1 ? 0 : 1 - const { denom } = this.pool.poolAssets[mode].token let amount = 0 if (Array.isArray(this.balance)) { - console.log('balance', this.balance) this.balance.forEach(x => { - if (x.denom === denom) { + if (x.denom === this.currentDenom) { amount = x.amount } }) } - return formatTokenAmount(amount, 6, denom) + return formatTokenAmount(amount, 6, this.currentDenom) } return 0 }, @@ -327,10 +332,11 @@ export default { }, methods: { initialAddress() { + const { chain } = this.$route.params const accounts = getLocalAccounts() const current = this.$store.state.chains.defaultWallet if (accounts && accounts[current]) { - const acc = accounts[current].address.find(x => x.chain === 'osmosis') + const acc = accounts[current].address.find(x => x.chain === chain) if (acc) { this.address = acc.addr }