From 73f5a77f498547e16fa47e25b680f0174afbf13a Mon Sep 17 00:00:00 2001 From: ety001 Date: Wed, 14 Mar 2018 20:55:20 +0800 Subject: [PATCH 1/4] show console log when error occured --- src/components/common/OrderList.vue | 4 ++-- src/components/common/WalletInfo.vue | 2 +- src/components/common/WalletInfoItem.vue | 2 +- src/lib/Api.js | 2 +- src/main.js | 10 +++++----- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/components/common/OrderList.vue b/src/components/common/OrderList.vue index e1f9dc8..bbf1930 100644 --- a/src/components/common/OrderList.vue +++ b/src/components/common/OrderList.vue @@ -236,7 +236,7 @@ export default { Api.getOrderBook(window.server, sellingAsset, buyingAsset, (res) => { this.orderbook = res; }, (errRes) => { - window.Sconsole(['updateOrderbook fail', errRes]); + window.Sconsole(['updateOrderbook fail', errRes], 'msg'); }); }, updateMyOrderList(pair) { @@ -278,7 +278,7 @@ export default { this.myOrderList = tmpMyOrder; } }, (errRes) => { - window.Sconsole(['updateMyList fail', errRes]); + window.Sconsole(['updateMyList fail', errRes], 'msg'); }); }, }, diff --git a/src/components/common/WalletInfo.vue b/src/components/common/WalletInfo.vue index 7b641b0..6614c8d 100644 --- a/src/components/common/WalletInfo.vue +++ b/src/components/common/WalletInfo.vue @@ -210,7 +210,7 @@ export default { this.assetIssuer = ''; }, (errRes) => { - window.Sconsole(['addTrustline fail', errRes]); + window.Sconsole(['addTrustline fail', errRes], 'msg'); this.$store.commit('updateIsloading', false); this.$store.commit('updateSnackmsg', 'wallet.add_trustline_fail'); this.assetCode = ''; diff --git a/src/components/common/WalletInfoItem.vue b/src/components/common/WalletInfoItem.vue index 6fcb2aa..ca93181 100644 --- a/src/components/common/WalletInfoItem.vue +++ b/src/components/common/WalletInfoItem.vue @@ -67,7 +67,7 @@ export default { this.$store.commit('updateSnackmsg', 'wallet.remove_trustline_succ'); }, (errRes) => { - window.Sconsole(['removeTrustline fail', errRes]); + window.Sconsole(['removeTrustline fail', errRes], 'msg'); this.$store.commit('updateIsloading', false); this.$store.commit('updateSnackmsg', 'wallet.remove_trustline_fail'); }, diff --git a/src/lib/Api.js b/src/lib/Api.js index 6567b46..76f691b 100644 --- a/src/lib/Api.js +++ b/src/lib/Api.js @@ -155,7 +155,7 @@ export default { }); return null; }).then(function(e) { - window.Sconsole([e]); + window.Sconsole(['makeOrderResult', e]); return null; }) .catch(function(e) { diff --git a/src/main.js b/src/main.js index a94e871..6c234db 100644 --- a/src/main.js +++ b/src/main.js @@ -85,7 +85,7 @@ new Vue({ this.updateOrderbookPrice(); this.updateOffers(); }, (errRes) => { - window.Sconsole(['update wallet info fail', errRes]); + window.Sconsole(['update wallet info fail', errRes], 'msg'); }); } }, @@ -116,7 +116,7 @@ new Vue({ } this.$store.commit('updateExchangePrices', exchangePrice); }, (errRes) => { - window.Sconsole(['updateOrderbookPrice fail', errRes]); + window.Sconsole(['updateOrderbookPrice fail', errRes], 'msg'); }); }); } @@ -128,7 +128,7 @@ new Vue({ this.$store.commit('updateOffers', res.records); this.robot(); }, (errRes) => { - window.Sconsole(['updateOffers fail', errRes]); + window.Sconsole(['updateOffers fail', errRes], 'msg'); }); }, robot() { @@ -198,7 +198,7 @@ new Vue({ console.log(err); }); }, (err) => { - window.Sconsole(['create_buy_order', err]); + window.Sconsole(['create_buy_order', err], 'msg'); }); } else { // charge current order @@ -245,7 +245,7 @@ new Vue({ console.log(err); }); }, (err) => { - window.Sconsole(['create_buy_order', err]); + window.Sconsole(['create_buy_order', err], 'msg'); }); } else { // charge current order From 4e36e8342b163e5eee78ec5b38d53146c4cc0464 Mon Sep 17 00:00:00 2001 From: ety001 Date: Wed, 14 Mar 2018 21:06:05 +0800 Subject: [PATCH 2/4] fix losting my order list init --- src/components/common/OrderList.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/common/OrderList.vue b/src/components/common/OrderList.vue index bbf1930..585cd8b 100644 --- a/src/components/common/OrderList.vue +++ b/src/components/common/OrderList.vue @@ -188,6 +188,7 @@ export default { window.Sconsole(['selectedPair', pair]); clearInterval(this.orderbookInterval); this.updateOrderBook(pair); + this.updateMyOrderList(pair); this.orderbookInterval = setInterval(() => { this.updateOrderBook(pair); this.updateMyOrderList(pair); From 0825e78ef3e40417be9623dcb498e8535ab4afbc Mon Sep 17 00:00:00 2001 From: ety001 Date: Thu, 15 Mar 2018 02:16:22 +0800 Subject: [PATCH 3/4] add cancel order feature into my order list --- src/components/common/OrderList.vue | 23 ++++++++++++++++++- src/i18n/en.json | 3 ++- src/i18n/zh-CN.json | 3 ++- src/lib/Api.js | 35 +++++++++++++++++++++++++++-- src/main.js | 4 ++-- 5 files changed, 61 insertions(+), 7 deletions(-) diff --git a/src/components/common/OrderList.vue b/src/components/common/OrderList.vue index 585cd8b..311178d 100644 --- a/src/components/common/OrderList.vue +++ b/src/components/common/OrderList.vue @@ -139,7 +139,9 @@ {{ order.amount | fixNumCustom(7) }} - + + {{ $t('myorder.cancel') }} + @@ -172,6 +174,7 @@ export default { orderbookInterval: null, orderbook: null, myOrderList: [], + pairOrderObj: {}, }; }, computed: { @@ -256,6 +259,7 @@ export default { Api.getOffers(window.server, this.$store.getters.privateKey, (res) => { if (res.records.length > 0) { const tmpMyOrder = []; + const tmpPairOrder = {}; res.records.forEach((record) => { if (JSON.stringify(record.buying) === JSON.stringify(sellingAsset) && JSON.stringify(record.selling) === JSON.stringify(buyingAsset)) { @@ -265,6 +269,7 @@ export default { price: 1 / record.price, // record.price = baseAsset / counterAsset amount: record.price * record.amount, // record.amount = counterAsset }); + tmpPairOrder[record.id] = record; } if (JSON.stringify(record.selling) === JSON.stringify(sellingAsset) && JSON.stringify(record.buying) === JSON.stringify(buyingAsset)) { @@ -274,14 +279,30 @@ export default { price: record.price, // counterAsset / baseAsset amount: record.amount, // baseAsset }); + tmpPairOrder[record.id] = record; } }); this.myOrderList = tmpMyOrder; + this.pairOrderObj = tmpPairOrder; } }, (errRes) => { window.Sconsole(['updateMyList fail', errRes], 'msg'); }); }, + cancel(orderId) { + if (this.pairOrderObj[orderId]) { + this.$store.commit('updateSnackmsg', this.$i18n.translate('myorder.cancel_msg')); + Api.cancelOrder( + window.server, + this.$store.getters.privateKey, + this.pairOrderObj[orderId], + (transResult) => { + window.Sconsole(['cancel order result', transResult]); + }, (errRes) => { + window.Sconsole(['cancel order err', errRes, errRes.message], 'msg'); + }); + } + }, }, }; diff --git a/src/i18n/en.json b/src/i18n/en.json index f95cbc4..d55b244 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -73,6 +73,7 @@ "sell": "Sell", "price": "Price{pair}", "cancel": "Cancel", - "amount": "Amount{asset}" + "amount": "Amount{asset}", + "cancel_msg": "Order canceling, please wait ...." } } diff --git a/src/i18n/zh-CN.json b/src/i18n/zh-CN.json index 5d50444..a1bcb6f 100644 --- a/src/i18n/zh-CN.json +++ b/src/i18n/zh-CN.json @@ -73,6 +73,7 @@ "sell": "卖出", "price": "价格{pair}", "cancel": "撤单", - "amount": "数量{asset}" + "amount": "数量{asset}", + "cancel_msg": "订单取消中, 请等待生效..." } } diff --git a/src/lib/Api.js b/src/lib/Api.js index 76f691b..0cb229f 100644 --- a/src/lib/Api.js +++ b/src/lib/Api.js @@ -138,7 +138,6 @@ export default { price : Number(price).toFixed(7) // The exchange rate ratio (selling / buying) }) let tx = new StellarSdk.TransactionBuilder(account).addOperation(op).build(); - // console.log(tx); tx.sign(keyPair); // lock store.commit('updateOrderLock', {skey, lock: true}); @@ -167,6 +166,39 @@ export default { window.Sconsole(['lock', lockStatus]); } }, + cancelOrder: function(server, privateKey, order, cb, cbErr) { + const keyPair = StellarSdk.Keypair.fromSecret(privateKey); + let buying, selling; + if (order.buying.asset_type === 'native') { + buying = StellarSdk.Asset.native(); + } else { + buying = new StellarSdk.Asset(order.buying.asset_code, order.buying.asset_issuer); + } + if (order.selling.asset_type === 'native') { + selling = StellarSdk.Asset.native(); + } else { + selling = new StellarSdk.Asset(order.selling.asset_code, order.selling.asset_issuer); + } + server.loadAccount(keyPair.publicKey()) + .then((account) => { + const op = StellarSdk.Operation.manageOffer({ + selling: selling, + buying: buying, + amount: '0', + price : Number(order.price).toFixed(7), + offerId: order.id, + }); + const tx = new StellarSdk.TransactionBuilder(account).addOperation(op).build(); + tx.sign(keyPair); + return server.submitTransaction(tx); + }).then(function(transactionResult) { + window.Sconsole(['cancel transaction result', transactionResult]); + cb(transactionResult); + return; + }).catch(function(e) { + cbErr(e); + }); + }, findOrder: function (offers, pair, cb) { const buyOrders = offers.filter((detail) => { const buyingAsset = { @@ -298,7 +330,6 @@ export default { buying = {asset_code: pair.counterAsset, asset_issuer: pair.counterIssuer}; } this.getOrderBook(server, selling, buying, (res) => { - console.log(res, selling, buying); const bids = res.bids; // buy 'buying' from these orders const asks = res.asks; // sell 'buying' from these orders if (t === 'base') { diff --git a/src/main.js b/src/main.js index 6c234db..1b2f171 100644 --- a/src/main.js +++ b/src/main.js @@ -81,9 +81,10 @@ new Vue({ }); } this.$store.commit('updateAllIssuers', allIssuers); - // other Actions + // other actions must be after updating balance this.updateOrderbookPrice(); this.updateOffers(); + this.robot(); }, (errRes) => { window.Sconsole(['update wallet info fail', errRes], 'msg'); }); @@ -126,7 +127,6 @@ new Vue({ Api.getOffers(this.server, this.$store.getters.privateKey, (res) => { window.Sconsole(['updateOffers success', res]); this.$store.commit('updateOffers', res.records); - this.robot(); }, (errRes) => { window.Sconsole(['updateOffers fail', errRes], 'msg'); }); From 8f696f663ace238362d1a95f58a94f7dc1d61a75 Mon Sep 17 00:00:00 2001 From: ety001 Date: Thu, 15 Mar 2018 09:20:49 +0800 Subject: [PATCH 4/4] auto cancel order --- src/components/common/OrderList.vue | 3 + src/lib/Api.js | 34 +++---- src/main.js | 133 ++++++++++++++++++++++------ src/store/index.js | 2 + 4 files changed, 124 insertions(+), 48 deletions(-) diff --git a/src/components/common/OrderList.vue b/src/components/common/OrderList.vue index 311178d..5e7b57d 100644 --- a/src/components/common/OrderList.vue +++ b/src/components/common/OrderList.vue @@ -167,6 +167,7 @@ import Api from '@/lib/Api'; export default { data() { return { + pair: null, selectedPair: '', selectedPairStr: '', selectedPairBaseAsset: '', @@ -185,6 +186,7 @@ export default { watch: { selectedPair(newPair) { const pair = this.parseExchangeKey(newPair); + this.pair = pair; this.selectedPairStr = `${pair.baseAsset}/${pair.counterAsset}`; this.selectedPairBaseAsset = pair.baseAsset; this.selectedPairCounterAsset = pair.counterAsset; @@ -298,6 +300,7 @@ export default { this.pairOrderObj[orderId], (transResult) => { window.Sconsole(['cancel order result', transResult]); + this.updateMyOrderList(this.pair); }, (errRes) => { window.Sconsole(['cancel order err', errRes, errRes.message], 'msg'); }); diff --git a/src/lib/Api.js b/src/lib/Api.js index 0cb229f..a6ae3aa 100644 --- a/src/lib/Api.js +++ b/src/lib/Api.js @@ -137,27 +137,17 @@ export default { amount: Number(amount).toFixed(7), // The total amount you're selling price : Number(price).toFixed(7) // The exchange rate ratio (selling / buying) }) - let tx = new StellarSdk.TransactionBuilder(account).addOperation(op).build(); + const tx = new StellarSdk.TransactionBuilder(account).addOperation(op).build(); tx.sign(keyPair); // lock store.commit('updateOrderLock', {skey, lock: true}); - server.submitTransaction(tx) - .then(function(transactionResult) { - window.Sconsole(['transactionResult', transactionResult]); - // unlock - store.commit('updateOrderLock', {skey, lock: false}); - return null; - }).catch((err) => { - // unlock - store.commit('updateOrderLock', {skey, lock: false}); - cbErr(err); - }); - return null; - }).then(function(e) { - window.Sconsole(['makeOrderResult', e]); - return null; - }) - .catch(function(e) { + return server.submitTransaction(tx); + }).then(function(transactionResult) { + window.Sconsole(['transactionResult', transactionResult]); + // unlock + store.commit('updateOrderLock', {skey, lock: false}); + return; + }).catch(function(e) { // unlock store.commit('updateOrderLock', {skey, lock: false}); cbErr(e); @@ -245,7 +235,7 @@ export default { const skey = `${pair.baseAsset}_${pair.baseIssuer}`; const tmp = store.getters.maxes.filter(detail => detail.skey === skey); if (tmp.length > 0) { - return tmp[0].max; + return Number(tmp[0].max); } else { return 0; } @@ -258,7 +248,7 @@ export default { const skey = `${pair.counterAsset}_${pair.counterIssuer}`; const tmp = store.getters.maxes.filter(detail => detail.skey === skey); if (tmp.length > 0) { - return tmp[0].max; + return Number(tmp[0].max); } else { return 0; } @@ -301,7 +291,7 @@ export default { const skey = `${pair.baseAsset}_${pair.baseIssuer}`; const res = store.getters.exchangeVals.filter(detail => detail.skey === skey); if (res.length > 0) { - return res[0].exchangeVal; + return Number(res[0].exchangeVal); } else { return 0; } @@ -313,7 +303,7 @@ export default { const skey = `${pair.counterAsset}_${pair.counterIssuer}`; const res = store.getters.exchangeVals.filter(detail => detail.skey === skey); if (res.length > 0) { - return res[0].exchangeVal; + return Number(res[0].exchangeVal); } else { return 0; } diff --git a/src/main.js b/src/main.js index 1b2f171..a4ca081 100644 --- a/src/main.js +++ b/src/main.js @@ -12,8 +12,10 @@ import transEn from './i18n/en.json'; import transZhCn from './i18n/zh-CN.json'; import Api from './lib/Api'; -const VERSION = '0.0.6'; -const intervalTime = 20; +const VERSION = '0.0.7'; +const intervalTime = 5; +const robotIntervalTime = 20; +const priceSensitivity = 4; window.progress = 0; // Debug @@ -56,6 +58,7 @@ new Vue({ serverTestUrl: 'https://horizon-testnet.stellar.org', serverUrl: 'https://horizon.stellar.org', server: null, + robotInterval: null, }, router, store, @@ -80,11 +83,12 @@ new Vue({ allIssuers.push(val.asset_issuer); }); } + // update all issuers this.$store.commit('updateAllIssuers', allIssuers); // other actions must be after updating balance this.updateOrderbookPrice(); this.updateOffers(); - this.robot(); + // this.robot(); }, (errRes) => { window.Sconsole(['update wallet info fail', errRes], 'msg'); }); @@ -94,25 +98,26 @@ new Vue({ window.Sconsole(['update orderbook and price']); // get balances from vuex store const balances = this.$store.getters.balances; - if (balances.length > 1) { + if (balances.length >= 1) { balances.forEach((detail) => { const sellingAsset = { asset_code: detail.asset_code, asset_issuer: detail.asset_issuer }; const buyingAsset = { asset_code: 'XLM' }; Api.getOrderBook(this.server, sellingAsset, buyingAsset, (res) => { const skey = `${detail.asset_code}_${detail.asset_issuer}`; - // this.$store.commit('updateOrderBook', { skey, orderBook: res }); const bids = res.bids; // buy xlm from these orders const asks = res.asks; // sell xlm from these orders + // update price for exchanging between ONE ASSET and XLM const exchangePrice = { skey, - bidPrice: 0, - askPrice: 0, + bidPrice: 0, // buy price + askPrice: 0, // sell price }; if (bids[0]) { exchangePrice.bidPrice = bids[0].price; + // ONE ASSET 's value(XLM), sell XLM and get ONE ASSET + this.$store.commit('updateExchangeVals', { skey, exchangeVal: window.fixNumCustom(detail.balance * bids[0].price) }); } if (asks[0]) { - this.$store.commit('updateExchangeVals', { skey, exchangeVal: window.fixNumCustom(detail.balance * asks[0].price) }); exchangePrice.askPrice = asks[0].price; } this.$store.commit('updateExchangePrices', exchangePrice); @@ -155,16 +160,24 @@ new Vue({ const counterAssetMax = Api.getCounterAssetMax(this.$store, pair); const baseExchangeVal = Api.getExchangeVal(this.$store, pair, 'base'); const counterExchangeVal = Api.getExchangeVal(this.$store, pair, 'counter'); - window.Sconsole(['pair:', privateKey, pair, baseInfo, counterInfo, baseAssetMax, counterAssetMax]); + window.Sconsole(['pair:', pair, baseInfo, counterInfo, baseAssetMax, counterAssetMax]); // To find whether this pair has orders Api.findOrder(this.$store.getters.offers, pair, (orders) => { window.Sconsole(['findOrdersResult:', orders]); // buyOrder if (orders.buyOrders.length === 0) { - window.Sconsole([`${pair.baseAsset} has no buy order`]); + window.Sconsole([`${pair.baseAsset}/${pair.counterAsset} has no buy order`]); // max limit - if (baseExchangeVal > baseAssetMax) { - window.Sconsole([`${pair.baseAsset} max limit`]); + if (baseExchangeVal - baseAssetMax > 0) { + window.Sconsole([`${pair.baseAsset} max limit`, baseExchangeVal, baseAssetMax]); + // cancel all buy order + orders.buyOrders.forEach((order) => { + Api.cancelOrder(this.server, privateKey, order, (transResult) => { + window.Sconsole(['cancel all buy order result', transResult]); + }, (errRes) => { + window.Sconsole(['cancel all buy order err', errRes, errRes.message], 'msg'); + }); + }); return; } // make order @@ -182,7 +195,7 @@ new Vue({ amount = 0; } } - window.Sconsole([orderPrice, pair, amount]); + window.Sconsole(['make buy order', orderPrice, pair, amount]); Api.makeOrder( 'buy', this.server, @@ -193,25 +206,61 @@ new Vue({ amount, // selling amount (1 / orderPrice), // selling / buying (res) => { - console.log('buy_order', res); + window.Sconsole(['buy_order', res], 'msg'); }, (err) => { - console.log(err); + window.Sconsole(['buy_order_err', err], 'msg'); }); }, (err) => { window.Sconsole(['create_buy_order', err], 'msg'); }); } else { - // charge current order - // TODO: cancel order - window.Sconsole([`${pair.baseAsset} has buy orders`, orders.buyOrders]); + // make sure there is only one buy order + let tmp; + while (orders.buyOrders.length > 1) { + tmp = orders.buyOrders.shift(); + Api.cancelOrder(this.server, privateKey, tmp, (transResult) => { + window.Sconsole(['cancel buy order result', transResult]); + }, (errRes) => { + window.Sconsole(['cancel buy order err', errRes, errRes.message], 'msg'); + }); + } + // check if the current order price is fitting + Api.getCurrentPrice(this.server, pair, 'base', (buyPrice) => { + // current order + const currentOrder = orders.buyOrders[0]; + // new price + const orderPrice = (1 / buyPrice) * (1 - (pair.baseRate / 100)); + if ( + Math.round(orderPrice, priceSensitivity) + - Math.round((1 / currentOrder.price), priceSensitivity) + > 0) { + // cancel current order + Api.cancelOrder(this.server, privateKey, currentOrder, (transResult) => { + window.Sconsole(['cancel buy order result', transResult]); + }, (errRes) => { + window.Sconsole(['cancel buy order err', errRes, errRes.message], 'msg'); + }); + } + }, (err) => { + window.Sconsole(['cancel current order| get current price', err], 'msg'); + }); + window.Sconsole([`${pair.baseAsset} cancel orders`, orders.buyOrders]); } // sellOrder if (orders.sellOrders.length === 0) { // make order - window.Sconsole([`${pair.counterAsset} has no sell order`]); + window.Sconsole([`${pair.baseAsset}/${pair.counterAsset} has no sell order`]); // max limit - if (counterExchangeVal > counterAssetMax) { - window.Sconsole([`${pair.counterAsset} max limit`]); + if (counterExchangeVal - counterAssetMax > 0) { + window.Sconsole([`${pair.counterAsset} max limit`, counterExchangeVal, counterAssetMax]); + // cancel all sell order + orders.sellOrders.forEach((order) => { + Api.cancelOrder(this.server, privateKey, order, (transResult) => { + window.Sconsole(['cancel all sell order result', transResult]); + }, (errRes) => { + window.Sconsole(['cancel all sell order err', errRes, errRes.message], 'msg'); + }); + }); return; } // make order @@ -229,7 +278,7 @@ new Vue({ amount = 0; } } - window.Sconsole([orderPrice, pair, amount, price]); + window.Sconsole(['make sell order', orderPrice, pair, amount, price]); Api.makeOrder( 'sell', this.server, @@ -240,16 +289,45 @@ new Vue({ amount, // selling amount orderPrice, // selling / buying (res) => { - console.log('buy_order', res); + window.Sconsole(['sell_order', res], 'msg'); }, (err) => { - console.log(err); + window.Sconsole(['sell_order_err', err], 'msg'); }); }, (err) => { window.Sconsole(['create_buy_order', err], 'msg'); }); } else { - // charge current order - window.Sconsole([`${pair.baseAsset} has sell orders`, orders.buyOrders]); + // make sure there is only one sell order + let tmp; + while (orders.sellOrders.length > 1) { + tmp = orders.sellOrders.shift(); + Api.cancelOrder(this.server, privateKey, tmp, (transResult) => { + window.Sconsole(['cancel buy order result', transResult]); + }, (errRes) => { + window.Sconsole(['cancel buy order err', errRes, errRes.message], 'msg'); + }); + } + // check if the current order price is fitting + Api.getCurrentPrice(this.server, pair, 'counter', (sellPrice) => { + // current order + const currentOrder = orders.sellOrders[0]; + // new price + const orderPrice = sellPrice * (1 + (pair.baseRate / 100)); + if ( + Math.round(orderPrice, priceSensitivity) + - Math.round(currentOrder.price, priceSensitivity) + < 0) { + // cancel current order + Api.cancelOrder(this.server, privateKey, currentOrder, (transResult) => { + window.Sconsole(['cancel sell order result', transResult]); + }, (errRes) => { + window.Sconsole(['cancel sell order err', errRes, errRes.message], 'msg'); + }); + } + }, (err) => { + window.Sconsole(['cancel current order| get current price', err], 'msg'); + }); + window.Sconsole([`${pair.baseAsset} cancel orders`, orders.sellOrders]); } }); }); @@ -268,6 +346,9 @@ new Vue({ this.interval = setInterval(() => { this.intervalFunc(); }, intervalTime * 1000); + this.robotInterval = setInterval(() => { + this.robot(); + }, robotIntervalTime * 1000); this.$store.commit('intervalTime', intervalTime); }, }); diff --git a/src/store/index.js b/src/store/index.js index 3c92826..bfa1e41 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -63,8 +63,10 @@ export default new Vuex.Store({ // init maxes balances.forEach((detail) => { const key = `${detail.asset_code}_${detail.asset_issuer}`; + // find if current balance exists const tmp = state.maxes.filter(val => val.skey === key); if (tmp.length === 0) { + // if not exist, add it. state.maxes.push({ skey: key, max: 0 }); } });