From f0ef39e96a27c4c5fe00ff16a45fd92ea3de69e6 Mon Sep 17 00:00:00 2001 From: liangping <18786721@qq.com> Date: Tue, 30 Nov 2021 11:59:17 +0800 Subject: [PATCH] fetch timeout and channel/port from encounterpart --- src/libs/fetch.js | 6 ++++++ src/libs/osmos.js | 5 +---- .../components/KlineTrade/DepositeWindow.vue | 21 ++++++++++--------- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/libs/fetch.js b/src/libs/fetch.js index 244c8c24..4b7b2990 100644 --- a/src/libs/fetch.js +++ b/src/libs/fetch.js @@ -335,6 +335,12 @@ export default class ChainFetch { return this.get(`/ibc/core/channel/v1beta1/channels/${channel_id}/ports/${port_id}/client_state`, config).then(data => commonProcess(data)) } + // eslint-disable-next-line camelcase + async getIBCChannel(channel_id, port_id, config = null) { + // eslint-disable-next-line camelcase + return this.get(`/ibc/core/channel/v1beta1/channels/${channel_id}/ports/${port_id}`, config).then(data => commonProcess(data)) + } + static async getBankBalance(baseurl, address) { return ChainFetch.fetch(baseurl, '/bank/balances/'.concat(address)).then(data => commonProcess(data)) } diff --git a/src/libs/osmos.js b/src/libs/osmos.js index 572cdbfb..c5bd64ce 100644 --- a/src/libs/osmos.js +++ b/src/libs/osmos.js @@ -69,10 +69,7 @@ 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 Object.values(confs).find(x => x.coingecko === key[0]) } return null } diff --git a/src/views/components/KlineTrade/DepositeWindow.vue b/src/views/components/KlineTrade/DepositeWindow.vue index 12a528f6..62084d3d 100644 --- a/src/views/components/KlineTrade/DepositeWindow.vue +++ b/src/views/components/KlineTrade/DepositeWindow.vue @@ -302,6 +302,7 @@ export default { paths: {}, destination: {}, channels: [], + timeoutHeight: {}, required, password, @@ -328,7 +329,6 @@ export default { } } this.selectedChain = getChainConfigForSymbol(this.symbol) - console.log('selected chain: ', this.selectedChain) }, computeAccount() { this.recipientAddress() @@ -351,11 +351,12 @@ export default { this.token = '' this.computeAccount() this.loadBalance() - console.log('denom trace:', this.denomTrace) if (this.denomTrace) { const part = this.denomTrace.path.split('/') - this.destination = { sourcePort: part[0], sourceChannel: part[1] } - console.log(this.destination) + this.$http.getIBCChannel(part[1], part[0]).then(data => { + this.destination = data.channel.counterparty + this.timeoutHeight = data.proof_height + }) } }, loadBalance() { @@ -415,13 +416,13 @@ export default { { typeUrl: '/ibc.applications.transfer.v1.MsgTransfer', value: { - sourcePort: this.destination.sourcePort, - sourceChannel: 'channel-141', // this.destination.sourceChannel, + sourcePort: this.destination.port_id, + sourceChannel: this.destination.channel_id, token: coin(Number(getUnitAmount(this.amount, this.denomTrace.base_denom)), this.denomTrace.base_denom), sender: this.address, receiver: this.recipient, - // timeoutHeight: undefined, // { revisionHeight: '0', revisionNumber: '0' }, - timeoutTimestamp: String((Math.floor(Date.now() / 1000) + 10) * 1_000_000_000), + timeoutHeight: this.timeoutHeight, + // timeoutTimestamp: '0', }, }, ] @@ -454,8 +455,8 @@ export default { signerData, ).then(bodyBytes => { this.$http.broadcastTx(bodyBytes, this.selectedChain).then(res => { - setLocalTxHistory({ op: 'send', hash: res.txhash, time: new Date() }) - this.$bvModal.hide('ibc-transfer-window') + setLocalTxHistory({ op: 'ibc_sender', hash: res.txhash, time: new Date() }) + this.$bvModal.hide('trading-deposte-window') this.$toast({ component: ToastificationContent, props: {