diff --git a/src/libs/osmos.js b/src/libs/osmos.js index 5ba235c9..8a6f403b 100644 --- a/src/libs/osmos.js +++ b/src/libs/osmos.js @@ -14,21 +14,42 @@ export default class OsmosAPI { async getOHCL4Pairs(from, to) { this.exe_time = '' - const ohlc = await Promise.all( + return Promise.all( [fetch(`https://api.coingecko.com/api/v3/coins/${from}/ohlc?vs_currency=usd&days=7`).then(res => res.json()), fetch(`https://api.coingecko.com/api/v3/coins/${to}/ohlc?vs_currency=usd&days=7`).then(res => res.json())], - ) - const output = [] - ohlc[0].forEach((e, i) => { - console.log(e, i, ohlc[1][i]) - const price = [e[0]] - for (let j = 1; j <= 4; j += 1) { - price.push(e[j] / ohlc[1][i][j]) - } - output.push(price) + ).then(ohlc => { + const output = [] + console.log(ohlc) + ohlc[0].forEach((e, i) => { + console.log(e, i, ohlc[1][i]) + const price = [e[0]] + for (let j = 1; j <= 4; j += 1) { + price.push(e[j] / ohlc[1][i][j]) + } + output.push(price) + }) + return output }) + } - return output + getCoinGeckoId(symbol) { + this.pairs = { + ATOM: 'cosmos', + OSMO: 'osmosis', + IRIS: 'iris-network', + AKT: 'akash-network', + } + return this.pairs[symbol] + } + + getIBCDenomHash(symbol) { + this.IBChash = { + ATOM: 'cosmos', + OSMO: 'uosmo', + IRIS: 'iris-network', + AKT: 'akash-network', + } + return this.IBChash[symbol] } // Custom Module diff --git a/src/views/OsmosisTrade.vue b/src/views/OsmosisTrade.vue index 8deb98b6..eae74cb1 100644 --- a/src/views/OsmosisTrade.vue +++ b/src/views/OsmosisTrade.vue @@ -9,7 +9,6 @@
- 59300 + {{ latestPrice }}
24h Change -
460 +0.78%
+
{{ changesIn24H }}%
24h High @@ -68,7 +67,10 @@ sm="12" > - + @@ -107,11 +109,23 @@ export default { ], } }, + computed: { + latestPrice() { + const p1 = this.$store.state.chains.quotes[this.base] + const p2 = this.$store.state.chains.quotes[this.target] + return p1 && p2 ? (p1.usd / p2.usd).toFixed(4) : '-' + }, + changesIn24H() { + const p1 = this.$store.state.chains.quotes[this.base] + const p2 = this.$store.state.chains.quotes[this.target] + return p1 && p2 ? (p1.usd_24h_change / p2.usd_24h_change).toFixed(2) : '-' + }, + }, created() { const { base, target } = this.$route.params this.init(base, target) // 所有方法添加到 $http.osmosis - this.$http.osmosis.getOHCL4Pairs('cosmos', 'osmosis').then(data => { + this.$http.osmosis.getOHCL4Pairs(this.$http.osmosis.getCoinGeckoId(this.base), this.$http.osmosis.getCoinGeckoId(this.target)).then(data => { console.log(data) }) }, diff --git a/src/views/components/KlineTrade/Place.vue b/src/views/components/KlineTrade/Place.vue index a72e7ed9..3c923bdd 100644 --- a/src/views/components/KlineTrade/Place.vue +++ b/src/views/components/KlineTrade/Place.vue @@ -16,7 +16,11 @@ no-body /> - +
@@ -32,6 +36,16 @@ export default { BTabs, PlaceForm, }, + props: { + base: { + type: String, + required: true, + }, + target: { + type: String, + required: true, + }, + }, data: () => ({ tabIndex: 0, }), diff --git a/src/views/components/KlineTrade/PlaceForm.vue b/src/views/components/KlineTrade/PlaceForm.vue index e468a405..4cd4cddd 100644 --- a/src/views/components/KlineTrade/PlaceForm.vue +++ b/src/views/components/KlineTrade/PlaceForm.vue @@ -122,22 +122,35 @@ export default { }, props: { type: { + type: Number, + required: true, + }, + base: { + type: String, + required: true, + }, + target: { type: String, required: true, }, }, data() { return { - base: 'ATOM', - target: 'OSMO', available: 0, amount: 0, total: 0, - price: 50000, + // price: 50000, slippage: 0.05, marks: [0, 0.01, 0.025, 0.05], } }, + computed: { + price() { + const p1 = this.$store.state.chains.quotes[this.base] + const p2 = this.$store.state.chains.quotes[this.target] + return p1 && p2 ? (p1.usd / p2.usd).toFixed(4) : '-' + }, + }, methods: { changeAmount() { this.total = this.amount * this.price