Skip to content
This repository has been archived by the owner on Feb 25, 2019. It is now read-only.

Commit

Permalink
Merge pull request #29 from StellarCN/develop
Browse files Browse the repository at this point in the history
trade bug
  • Loading branch information
imloama authored Jan 10, 2018
2 parents a5fb020 + 8211501 commit 488433d
Show file tree
Hide file tree
Showing 19 changed files with 258 additions and 31 deletions.
1 change: 1 addition & 0 deletions config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@
<plugin name="cordova-sqlite-storage" spec="^2.1.2" />
<plugin name="cordova-disable-http-cache" spec="^1.0.0" />
<plugin name="cordova-plugin-inappbrowser" spec="^1.7.2" />
<plugin name="cordova-plugin-globalization" spec="^1.0.9" />
</widget>
1 change: 1 addition & 0 deletions docs/ROADMAP.MD
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
* []recharge and withdrawal support [SEP006 protocol](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0006.md)
* []improve operation and performance of trade
* []k line graph
* []reset password
1 change: 1 addition & 0 deletions docs/ROADMAP_CN.MD
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
* []充值提现支持[SEP006标准](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0006.md)
* []交易界面操作和性能优化
* []K线图功能
* []重置密码
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"cordova-plugin-swift-support": "^3.1.1",
"cordova-plugin-whitelist": "1",
"cordova-sqlite-storage": "^2.1.2",
"cordova-plugin-globalization": "^1.0.9",
"ed25519": "0.0.4",
"hammerjs": "^2.0.8",
"lodash": "^4.17.4",
Expand Down Expand Up @@ -128,7 +129,8 @@
"cordova-plugin-camera": {},
"cordova-sqlite-storage": {},
"cordova-disable-http-cache": {},
"cordova-plugin-inappbrowser": {}
"cordova-plugin-inappbrowser": {},
"cordova-plugin-globalization": {}
},
"platforms": [
"browser",
Expand Down
16 changes: 12 additions & 4 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
import { defaultTradePairsAPI } from '@/api/gateways'
import { closeStreams, initStreams } from '@/streams'
import { initStorage,checkPlatform } from '@/api/storage'
import { getDeviceLanguage } from '@/locales'
export default {
data () {
return {
pauseStart: null,//暂时的起始时间
pauseMaxSecond: 60,//最大
isios: false,
devicelang: null,
}
},
computed:{
Expand Down Expand Up @@ -69,7 +71,11 @@
this.$store.commit('CHANGE_IOSSTATUSBAR_COLOR','primary')
}
//加载系统配置
this.loadAppSetting().then(data=>{
getDeviceLanguage()
.then((locale) => {
this.devicelang = locale
return this.loadAppSetting()
}).then(data=>{
//if(this.alldata.app.enablePin){
// this.showConfirmPin = true
//}
Expand Down Expand Up @@ -115,11 +121,11 @@
initStorage().then(()=>{
console.log('---init storage ok---')
this.saveAppSetting({})
this.saveAppSetting({locale: this.devicelang})
}).catch(err=>{
console.error('---init storage error---')
console.error(err)
this.saveAppSetting({})
this.saveAppSetting({locale: this.devicelang})
})
//保存默认的设置数据
Expand All @@ -134,7 +140,9 @@
},
methods: {
...mapActions(['loadAppSetting',
...mapActions([
'deviceLang',
'loadAppSetting',
'getLedger',
'loadAccounts',
'saveAppSetting',
Expand Down
18 changes: 12 additions & 6 deletions src/api/offer.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ export function cancel(seed,offer) {

}

function undefinedToNull(val){
if(typeof val === 'undefined')return null
return val
}

export function myofferConvert(_sellasset,_buyasset,my){
let sellasset = Object.assign({}, _sellasset)
let buyasset = Object.assign({}, _buyasset)
Expand All @@ -109,11 +114,10 @@ export function myofferConvert(_sellasset,_buyasset,my){
if(stellarorg === buyasset.issuer){
buyasset.issuer = null
}
let codeandissuer_sb = `${sellcode}-${sellissuer}-${buycode}-${buyissuer}`
let codeandissuer_bs = `${buycode}-${buyissuer}-${sellcode}-${sellissuer}`
let codeandissuer_sb_target = `${sellasset.code}-${sellasset.issuer}-${buyasset.code}-${buyasset.issuer}`
let codeandissuer_bs_target = `${buyasset.code}-${buyasset.issuer}-${sellasset.code}-${sellasset.issuer}`

let codeandissuer_sb = `${sellcode}-${undefinedToNull(sellissuer)}-${buycode}-${undefinedToNull(buyissuer)}`
let codeandissuer_bs = `${buycode}-${undefinedToNull(buyissuer)}-${sellcode}-${undefinedToNull(sellissuer)}`
let codeandissuer_sb_target = `${sellasset.code}-${undefinedToNull(sellasset.issuer)}-${buyasset.code}-${undefinedToNull(buyasset.issuer)}`
let codeandissuer_bs_target = `${buyasset.code}-${undefinedToNull(buyasset.issuer)}-${sellasset.code}-${undefinedToNull(sellasset.issuer)}`

let obj = null
if(codeandissuer_sb === codeandissuer_sb_target && codeandissuer_bs === codeandissuer_bs_target){
Expand All @@ -125,10 +129,12 @@ export function myofferConvert(_sellasset,_buyasset,my){
}else if(
codeandissuer_sb === codeandissuer_bs_target && codeandissuer_bs === codeandissuer_sb_target
){
console.log("----------------xxxxxxx")
console.log(ele)
obj = Object.assign({}, ele, {type: 'buy'})
obj.amount = Number(obj.amount)
obj.price = Number(obj.price)
obj.base = Number((obj.amount * obj.price).toFixed(7))
obj.base = Number((obj.amount * obj.price_r.n / obj.price_r.d).toFixed(7))
obj.price = Number((1 / obj.price).toFixed(4))
data.push(obj)
}
Expand Down
48 changes: 48 additions & 0 deletions src/api/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// toFixed兼容方法
Number.prototype.toFixed = function (n) {
if (n > 20 || n < 0) {
throw new RangeError('toFixed() digits argument must be between 0 and 20');
}
const number = this;
if (isNaN(number) || number >= Math.pow(10, 21)) {
return number.toString();
}
if (typeof (n) == 'undefined' || n == 0) {
return (Math.round(number)).toString();
}

let result = number.toString();
const arr = result.split('.');

// 整数的情况
if (arr.length < 2) {
result += '.';
for (let i = 0; i < n; i += 1) {
result += '0';
}
return result;
}

const integer = arr[0];
const decimal = arr[1];
if (decimal.length == n) {
return result;
}
if (decimal.length < n) {
for (let i = 0; i < n - decimal.length; i += 1) {
result += '0';
}
return result;
}
result = integer + '.' + decimal.substr(0, n);
const last = decimal.substr(n, 1);

// 四舍五入,转换为整数再处理,避免浮点数精度的损失
if (parseInt(last, 10) >= 5) {
const x = Math.pow(10, n);
result = (Math.round((parseFloat(result) * x)) + 1) / x;
result = result.toFixed(n);
}

return result;
};
12 changes: 12 additions & 0 deletions src/api/xdr.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,16 @@ export function xdrMsg(err){
return resultXdr.result().results()[0].value().value().switch().name;
}
return null
}

export function getXdrResultCode(err){
if(err.data.extras && err.data.extras.result_codes){
let codes = err.data.extras.result_codes
if(codes.transaction){
return codes.transaction
}
if(codes.operation){
return codes.operation
}
}
}
11 changes: 8 additions & 3 deletions src/components/OrderBook.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<div :class="'selloffer offermenu' + (active==='sell'?' active':'')"
@click.stop="active='sell'">{{$t('Trade.SellOffer')}}</div>
<div :class="'myoffer offermenu' + (active==='myoffer'?' active':'')"
@click.stop="active='myoffer'">{{$t('Trade.MyOffer')}}</div>
@click.stop="active='myoffer'">{{$t('Trade.MyOffer')}}({{myofferlen}})</div>
<!-- <div :class="'myoffer offermenu' + (active==='myTradeHistory'?' active':'')"
@click.stop="active='myTradeHistory'">{{$t('Trade.MyTradeHistory')}}</div> -->
</div>
Expand Down Expand Up @@ -62,7 +62,6 @@
<div class="headcol">{{BaseAsset.code}}</div>
<div class="headcol">{{CounterAsset.code}}</div>
<div class="headcol">&nbsp;</div>

</div>
<div class="table-row body-2"
v-for="(item,index) in myoffers" :key="index" :class='item.type'>
Expand Down Expand Up @@ -98,6 +97,7 @@
</div>
</div>
</div> -->

</card>
</scroll>
</template>
Expand Down Expand Up @@ -173,6 +173,10 @@ export default {
CounterAsset(){
return this.selectedTrade.to
},
myofferlen(){
if(this.blank)return 0;
return this.myoffers.length;
},
myoffers(){
if(this.blank)return []
if(this.my){
Expand All @@ -189,7 +193,8 @@ export default {
let obj = Object.assign({}, this.bids[i])
obj.num = Number(obj.amount).toFixed(4)
obj.price = Number(obj.price).toFixed(this.decimal)
obj.amount = (obj.num / obj.price).toFixed(2)
// obj.amount = (obj.num / obj.price).toFixed(2)
obj.amount = (obj.num * obj.price_r.n / obj.price_r.d).toFixed(2)
dep += Number(obj.num)
obj.depth = dep.toFixed(2)
obj.origin = this.bids[i]
Expand Down
3 changes: 1 addition & 2 deletions src/components/Toolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,7 @@ export default {
this.checkPwd = false
this.password = null
this.showaccounts = false
//重新处理stream
closeStreams()
//重新处理stream closeStreams()
initStreams(this.account.address)
}).catch(err=>{
Expand Down
6 changes: 3 additions & 3 deletions src/components/WithdrawInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ import { mapState, mapActions, mapGetters } from 'vuex'
import { getAssetWithdrawUrl,submitQuote } from '../api/withdraw'
import Loading from './Loading'
import ContactBook from '@/components/ContactBook'
import { xdrMsg } from '@/api/xdr'
import { xdrMsg,getXdrResultCode } from '@/api/xdr'
export default {
data(){
return {
Expand Down Expand Up @@ -294,10 +294,10 @@ export default {
this.sendfail = true
this.hideLoading()
this.$toasted.error(this.$t('Error.SendAssetFail'))
let msg = xdrMsg(err)
let msg = getXdrResultCode(err)
setTimeout(()=>{
if(msg){
this.$toasted.error(msg)
this.$toasted.error(this.$t(msg))
}else{
this.$toasted.error(this.$t(err.message))
}
Expand Down
60 changes: 59 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -244,5 +244,63 @@

"About.Title":"about",

"App.ClickOneMoreTimeExit":"click one more time to exit!"
"App.ClickOneMoreTimeExit":"click one more time to exit!",


"op_success":"operation success",
"op_malformed":"opernation incorrect",
"op_underfunded":"operation under funded",
"op_low_reserve":"operation low reserve",
"op_line_full" :"operation trust line too many",
"op_no_issuer":"operation missing issuer",

"tx_success" : "transaction success",
"tx_failed" : "transaction failed",
"tx_too_early" : "transaction error, too early",
"tx_too_late" : "transaction error, too late",
"tx_missing_operation": "transaction error, missing operation",
"tx_bad_seq": "transaction error, bad sequence",
"tx_bad_auth": "transaction error, bad auth",
"tx_insufficient_balance": "transaction error, insufficient balance",
"tx_no_source_account": "transaction error, no source account" ,
"tx_insufficient_fee": "transaction error, insufficient fee",
"tx_bad_auth_extra": "transaction error, bad auth extra",
"tx_internal_error": "transaction error, internal error",

"op_inner":"operation inner error",
"op_bad_auth": "operation error, bad auth",
"op_no_source_account": "operation error, no source account",
"op_already_exists" : "operation already exists",
"op_src_no_trust" : "operation error, source account not trust",
"op_src_not_authorized" : "operation error, source account not authorized",
"op_no_destination": "operation error, no destination",
"op_no_trust": "operation error, no trust",
"op_not_authorized": "operation error, not authorized",
"op_too_few_offers": "operation error, too few offers",
"op_cross_self": "operation error,cross self",
"op_over_source_max": "operation error, over source max",
"op_sell_no_trust": "operation error, sell no trust",
"op_buy_no_trust": "operation error, buy no trust",
"sell_not_authorized": "sell not authorized",
"buy_not_authorized": "buy not authorized",
"op_sell_no_issuer": "operation error, sell no issuer",
"buy_no_issuer": "buy no issuer",
"op_offer_not_found": "operation error, offer not found",
"op_too_many_signers": "operation error, too many signers",
"op_bad_flags": "operation error, bad flags",
"op_invalid_inflation": "operation error,invalid inflation",
"op_cant_change": "operation error,cannot change",
"op_unknown_flag": "operation error,unknown flag",
"op_threshold_out_of_range": "operation error,threshold out of range",
"op_bad_signer": "operation error,bad signer",
"op_invalid_home_domain": "operation error, invalid home domain",
"op_invalid_limit": "operation error, invalid limit",
"op_no_trustline": "operation error, not trustline",
"op_not_required": "operation error, not required",
"op_cant_revoke": "operation error, cannot revoke",
"op_no_account": "operation error,no account",
"op_immutable_set": "operation error, immutable set",
"op_has_sub_entries": "operation error, has sub entries",
"op_not_time": "operation error, not time"

}
25 changes: 23 additions & 2 deletions src/locales/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,30 @@ export const LANGUAGES = [
ZH_CN
]

export function getDeviceLanguage(){
return new Promise((resolve,reject) => {
console.log(navigator.globalization)
navigator.globalization.getLocaleName(locale=>{
console.log('-----locale---')
console.log(locale)
let val = locale.value
if (['zh','zh-CN', 'zh-TW', 'zh-HK'].includes(navigator.language)) {
resolve(ZH_CN)
} else {
resolve(EN)
}
},()=>{
//reject()
resolve(ZH_CN)
}
);
})
}


export const DEVICE_LANGUAGE = function getDeviceLanguage() {
// console.log("getDeviceLanguage: " + navigator.language);
if (['zh-CN', 'zh-TW', 'zh-HK'].includes(navigator.language)) {

if (['zh','zh-CN', 'zh-TW', 'zh-HK'].includes(navigator.language)) {
return ZH_CN
} else {
return EN
Expand Down
Loading

0 comments on commit 488433d

Please sign in to comment.