diff --git a/package-lock.json b/package-lock.json index 730d987..0d2966b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1998,11 +1998,12 @@ } }, "babel-runtime": { - "version": "4.7.16", - "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-4.7.16.tgz", - "integrity": "sha1-ejmVrYyetbTQ3TX+vxcNDRQgJis=", + "version": "6.26.0", + "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz", + "integrity": "sha1-llxwWGaOgrVde/4E/yM3vItWR/4=", "requires": { - "core-js": "0.6.1" + "core-js": "2.5.3", + "regenerator-runtime": "0.11.1" } }, "babel-template": { @@ -3016,9 +3017,9 @@ } }, "core-js": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-0.6.1.tgz", - "integrity": "sha1-G0lwhz6BAb+MQ1rwlfqpAk9Lm1g=" + "version": "2.5.3", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.5.3.tgz", + "integrity": "sha1-isw4NFgk8W2DZbfJtCWRaOjtYD4=" }, "core-util-is": { "version": "1.0.2", @@ -7117,6 +7118,19 @@ "sequencify": "0.0.7" }, "dependencies": { + "babel-runtime": { + "version": "4.7.16", + "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-4.7.16.tgz", + "integrity": "sha1-ejmVrYyetbTQ3TX+vxcNDRQgJis=", + "requires": { + "core-js": "0.6.1" + } + }, + "core-js": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-0.6.1.tgz", + "integrity": "sha1-G0lwhz6BAb+MQ1rwlfqpAk9Lm1g=" + }, "lodash": { "version": "3.10.1", "resolved": "https://registry.npmjs.org/lodash/-/lodash-3.10.1.tgz", @@ -11321,8 +11335,7 @@ "regenerator-runtime": { "version": "0.11.1", "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz", - "integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==", - "dev": true + "integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==" }, "regenerator-transform": { "version": "0.10.1", diff --git a/package.json b/package.json index 6ee37f7..11318b5 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs" }, "dependencies": { + "babel-runtime": "^6.26.0", "stellar-sdk": "^0.7.3", "vue": "^2.3.3", "vue-material": "^0.7.4", diff --git a/src/components/Home.vue b/src/components/Home.vue index 55e537b..aac218f 100644 --- a/src/components/Home.vue +++ b/src/components/Home.vue @@ -1,5 +1,9 @@ - diff --git a/src/components/common/OrderList.vue b/src/components/common/OrderList.vue new file mode 100644 index 0000000..e1f9dc8 --- /dev/null +++ b/src/components/common/OrderList.vue @@ -0,0 +1,288 @@ + + + + diff --git a/src/components/common/RobotExchangePair.vue b/src/components/common/RobotExchangePair.vue index 6cff136..5d2d66a 100644 --- a/src/components/common/RobotExchangePair.vue +++ b/src/components/common/RobotExchangePair.vue @@ -54,21 +54,33 @@ @close="onClose" :md-dialog-width="'50%'" ref="add_exchange_pair"> - - - + + + + XLM + {{ balance.asset_code }} + - - - + + + + + {{ `${balance.asset_issuer} ( ${balance.asset_code} )` }} + - - - + + + + XLM + {{ balance.asset_code }} + - - - + + + + + {{ `${balance.asset_issuer} ( ${balance.asset_code} )` }} + @@ -98,6 +110,9 @@ export default { exchangePairs() { return this.$store.getters.exchangePairs; }, + balances() { + return this.$store.getters.balances; + }, }, watch: { }, @@ -116,17 +131,55 @@ export default { switch (ref) { case 'add_exchange_pair': if (type === 'ok') { - // TODO: detect pair exist. - // const issuers = this.$store.getters.issuers; - // if (issuers.indexOf(this.baseIssuer.toUpperCase()) || - // issuers.indexOf(this.counterIssuer.toUpperCase())) { - // this.$store.commit('updateSnackmsg', 'exchange.has_existed'); - // return; - // } const baseAsset = this.baseAsset ? this.baseAsset.toUpperCase() : null; const baseIssuer = this.baseIssuer ? this.baseIssuer.toUpperCase() : null; const counterAsset = this.counterAsset ? this.counterAsset.toUpperCase() : null; const counterIssuer = this.counterIssuer ? this.counterIssuer.toUpperCase() : null; + const balances = this.balances; + + // check if base asset is the same as counter asset + if (baseAsset === counterAsset) { + this.$store.commit('updateSnackmsg', 'exchange.base_asset_cannot_be_the_same_as_counter_asset'); + return; + } + + // check if the asset and issuer are paired + let baseErr = false; + console.log(baseAsset, baseIssuer, counterAsset, counterIssuer); + if (baseIssuer === null && baseAsset !== 'XLM') { + this.$store.commit('updateSnackmsg', 'exchange.base_asset_and_issuer_not_paired'); + return; + } + balances.forEach((el) => { + if (el.asset_issuer === baseIssuer) { + if (el.asset_code !== baseAsset) { + baseErr = true; + } + } + }); + if (baseErr) { + this.$store.commit('updateSnackmsg', 'exchange.base_asset_and_issuer_not_paired'); + return; + } + + let counterErr = false; + if (counterIssuer === null && counterAsset !== 'XLM') { + this.$store.commit('updateSnackmsg', 'exchange.counter_asset_and_issuer_not_paired'); + return; + } + balances.forEach((el) => { + if (el.asset_issuer === counterIssuer) { + if (el.asset_code !== counterAsset) { + counterErr = true; + } + } + }); + if (counterErr) { + this.$store.commit('updateSnackmsg', 'exchange.counter_asset_and_issuer_not_paired'); + return; + } + + // add exchange pair const pair = { skey: `${baseAsset}${baseIssuer}_${counterAsset}${counterIssuer}`, skey2: `${counterAsset}${counterIssuer}_${baseAsset}${baseIssuer}`, @@ -165,5 +218,5 @@ export default { }, }; - diff --git a/src/components/common/RobotSwitch.vue b/src/components/common/RobotSwitch.vue new file mode 100644 index 0000000..ec94575 --- /dev/null +++ b/src/components/common/RobotSwitch.vue @@ -0,0 +1,31 @@ + + + diff --git a/src/components/common/TopNav.vue b/src/components/common/TopNav.vue index 8228215..abc1c80 100644 --- a/src/components/common/TopNav.vue +++ b/src/components/common/TopNav.vue @@ -15,9 +15,6 @@ - - {{ $t('robot_status', {'robotStatus': $t(robotStatusTxt)}) }} - {{ 'home' | translate }} @@ -54,17 +51,11 @@ export default { }, data() { return { - lang: 'en', - robotStatus: false, - robotStatusTxt: 'off', + lang: this.$store.getters.lang, // progress: 0, }; }, watch: { - robotStatus() { - this.robotStatusTxt = this.robotStatus ? 'on' : 'off'; - this.$store.commit('updateRobotStatus', this.robotStatus); - }, lang(val) { this.$i18n.set(val); this.$store.commit('updateLang', val); diff --git a/src/i18n/en.json b/src/i18n/en.json index 2429ef1..f95cbc4 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -18,6 +18,7 @@ "lang": "Language", "reset": "Reset Configuration", "exchange_pair": "Exchange Pair", + "select_one": "Select One", "wallet": { "base": "Wallet", "config_your_private_key": "Config Your Wallet Private Key", @@ -49,7 +50,29 @@ "base_asset": "Base Asset (Example: XLM)", "base_issuer": "Base Issuer (Example: If asset is XLM, please empty this input)", "counter_asset": "Counter Asset (Example: CNY)", - "counter_issuer": "Counter Issuer (Example: GAREELUB43IRHWEASCFBLKHURCGMHE5IF6XSE7EXDLACYHGRHM43RFOX)" + "counter_issuer": "Counter Issuer (Example: GAREELUB43IRHWEASCFBLKHURCGMHE5IF6XSE7EXDLACYHGRHM43RFOX)", + "set_base_asset_first": "Please set base asset first!", + "base_asset_and_issuer_not_paired": "Base asset and issuer are not PAIRED!", + "counter_asset_and_issuer_not_paired": "Counter asset and issuer are not PAIRED!", + "base_asset_cannot_be_the_same_as_counter_asset": "Base asset cannot be the same as counter asset!" }, - "save_success": "Save Success!" -} \ No newline at end of file + "save_success": "Save Success!", + "manage_offers": "Manage Offers", + "order_list": { + "title": "Order", + "buy_list": "Buy List", + "sell_list": "Sell List", + "my_list": "My Order List", + "price": "{pair} Price", + "buy": "Buy {asset}", + "sell": "Sell {asset}" + }, + "myorder": { + "type": "Type", + "buy": "Buy", + "sell": "Sell", + "price": "Price{pair}", + "cancel": "Cancel", + "amount": "Amount{asset}" + } +} diff --git a/src/i18n/zh-CN.json b/src/i18n/zh-CN.json index 1146778..5d50444 100644 --- a/src/i18n/zh-CN.json +++ b/src/i18n/zh-CN.json @@ -18,6 +18,7 @@ "lang": "语言", "reset": "重置配置", "exchange_pair": "交易对", + "select_one": "请选择一项", "wallet": { "base": "钱包", "config_your_private_key": "设置你的钱包私钥", @@ -49,7 +50,29 @@ "base_asset": "基础货币 (例如: XLM)", "base_issuer": "基础发行网关 (例如: 如果货币填写的是XLM,则此处留空)", "counter_asset": "对手货币 (例如: CNY)", - "counter_issuer": "对手发行网关 (Example: GAREELUB43IRHWEASCFBLKHURCGMHE5IF6XSE7EXDLACYHGRHM43RFOX)" + "counter_issuer": "对手发行网关 (Example: GAREELUB43IRHWEASCFBLKHURCGMHE5IF6XSE7EXDLACYHGRHM43RFOX)", + "set_base_asset_first": "请先设置基础货币", + "base_asset_and_issuer_not_paired": "基础货币和基础发行网关不匹配!", + "counter_asset_and_issuer_not_paired": "对手货币和对手发行网关不匹配!", + "base_asset_cannot_be_the_same_as_counter_asset": "基础货币和对手货币不能相同!" }, - "save_success": "保存成功" -} \ No newline at end of file + "save_success": "保存成功", + "manage_offers": "管理委托", + "order_list": { + "title": "委托单", + "buy_list": "买单列表", + "sell_list": "卖单列表", + "my_list": "我的委托单", + "price": "{pair} 价格", + "buy": "买入 {asset}", + "sell": "卖出 {asset}" + }, + "myorder": { + "type": "类型", + "buy": "买入", + "sell": "卖出", + "price": "价格{pair}", + "cancel": "撤单", + "amount": "数量{asset}" + } +} diff --git a/src/main.js b/src/main.js index 08bef49..a94e871 100644 --- a/src/main.js +++ b/src/main.js @@ -12,7 +12,7 @@ import transEn from './i18n/en.json'; import transZhCn from './i18n/zh-CN.json'; import Api from './lib/Api'; -const VERSION = '0.0.5'; +const VERSION = '0.0.6'; const intervalTime = 20; window.progress = 0; @@ -26,7 +26,7 @@ window.Sconsole = (resultArrOrStr, msgType = 'debug') => { }; // Global Func -window.fixNumCustom = (number, fixed = 6) => Number(number).toFixed(fixed); +window.fixNumCustom = (number, fixed = 7) => Number(number).toFixed(fixed); // init VueMaterial Vue.use(VueMaterial); diff --git a/src/store/index.js b/src/store/index.js index 01d6e5e..3c92826 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -244,6 +244,16 @@ export default new Vuex.Store({ exchangePairs(state) { return state.exchangePairs; }, + exchangePairsSelector(state) { + const res = []; + state.exchangePairs.forEach((pair) => { + res.push({ + skey: `${pair.baseAsset}|${pair.baseIssuer}_${pair.counterAsset}|${pair.counterIssuer}`, + text: `[${pair.baseAsset}] ${pair.baseIssuer} / [${pair.counterAsset}] ${pair.counterIssuer}`, + }); + }); + return res; + }, robotStatus(state) { return state.robotStatus; },