From 5f5adc916f4a8d816588e4b12b684f0f340df7d7 Mon Sep 17 00:00:00 2001 From: lvshaoping007 <1244849816@qq.com> Date: Tue, 16 Nov 2021 20:15:11 +0800 Subject: [PATCH] APIService: Throw error for non-zero return codes in getSubmitStatus() Make getSubmitStatus() throw error if StakingAllow transaction doesn't return code: 0. --- src/background/service/APIService.js | 21 ++++++++++++++++----- src/popup/pages/Send/index.js | 2 +- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/background/service/APIService.js b/src/background/service/APIService.js index 3948396d..b9eeac60 100644 --- a/src/background/service/APIService.js +++ b/src/background/service/APIService.js @@ -668,14 +668,18 @@ class APIService { const tw = oasis.staking.allowWrapper() params.method = TRANSACTION_TYPE.StakingAllow params.toAddress = oasis.staking.addressToBech32(await oasis.staking.addressFromRuntimeID(oasis.misc.fromHex(params.runtimeId))) - let result = await this.submitTxBody(params, tw,true,()=>this.onBroadcastEnd(params,resolve,reject)).catch(err=>err) + let result = await this.submitTxBody(params, tw,true,(data)=>this.onBroadcastEnd(params,resolve,reject,data)).catch(err=>err) if(result&&result.error){ reject({error:result.error}) } } }) } - onBroadcastEnd= async(params,resolve)=>{ + onBroadcastEnd= async(params,resolve,reject,data)=>{ + if(data && data.code !== 0){ + reject(data) + return + } const consensusWrapper = new oasisRT.consensusAccounts.Wrapper(oasis.misc.fromHex(params.runtimeId)); const depositWrapper = consensusWrapper.callDeposit() let submitRuntime = await this.submitRuntimeBody(params, depositWrapper).catch(err=>err) @@ -789,11 +793,18 @@ class APIService { checkTxStatus = (hash,hideNotify,callback) => { this.fetchTransactionStatus(hash,hideNotify,callback) } - onSuccess=(hash,hideNotify,callback)=>{ + onSuccess=(data,hash,hideNotify,callback)=>{ if(!hideNotify){ this.notification(hash) } - callback && callback() + if(callback){ + try { + let rawData = JSON.parse(data.raw) + callback(rawData.error) + } catch (error) { + callback({error}) + } + } } fetchTransactionStatus = (hash,hideNotify,callback) => { getSubmitStatus(hash).then((data) => { @@ -803,7 +814,7 @@ class APIService { action: TX_SUCCESS, data }); - this.onSuccess(hash,hideNotify,callback) + this.onSuccess(data,hash,hideNotify,callback) if (this.statusTimer[hash]) { clearTimeout(this.statusTimer[hash]); this.statusTimer[hash] = null; diff --git a/src/popup/pages/Send/index.js b/src/popup/pages/Send/index.js index 1020624a..c0c3ebec 100644 --- a/src/popup/pages/Send/index.js +++ b/src/popup/pages/Send/index.js @@ -574,7 +574,7 @@ class SendPage extends React.Component { this.props.history.goBack() }, 100); }else{ - let errMessage = data?.error?.metadata?.["grpc-message"] || getLanguage('postFailed') + let errMessage = data?.error?.metadata?.["grpc-message"] || data?.message || getLanguage('postFailed') Toast.info(errMessage) } }