Skip to content

Commit

Permalink
APIService: Throw error for non-zero return codes in getSubmitStatus()
Browse files Browse the repository at this point in the history
Make getSubmitStatus() throw error if StakingAllow transaction doesn't
return code: 0.
  • Loading branch information
lvshaoping007 authored and tjanez committed Nov 19, 2021
1 parent 06b5f49 commit 5f5adc9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
21 changes: 16 additions & 5 deletions src/background/service/APIService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) => {
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/popup/pages/Send/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 5f5adc9

Please sign in to comment.