Browse Source

claim interest native address check failsafe

v0.25
pbca26 7 years ago
parent
commit
a31643fbfa
  1. 38
      react/src/actions/actions/nativeSend.js
  2. 46
      react/src/components/dashboard/claimInterestModal/claimInterestModal.js

38
react/src/actions/actions/nativeSend.js

@ -224,4 +224,42 @@ export function clearLastSendToResponseState() {
type: DASHBOARD_ACTIVE_COIN_SENDTO,
lastSendToResponse: null,
}
}
export function validateAddressPromise(coin, address) {
return new Promise((resolve, reject) => {
const payload = {
mode: null,
chain: coin,
cmd: 'validateaddress',
params: [ address ],
};
const _fetchConfig = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ payload: payload }),
};
fetch(
`http://127.0.0.1:${Config.agamaPort}/shepherd/cli`,
_fetchConfig
)
.catch((error) => {
console.log(error);
dispatch(
triggerToaster(
'validateAddressPromise',
'Error',
'error'
)
);
})
.then(response => response.json())
.then(json => {
resolve(json);
});
});
}

46
react/src/components/dashboard/claimInterestModal/claimInterestModal.js

@ -12,6 +12,7 @@ import {
shepherdElectrumListunspent,
shepherdElectrumSendPreflight,
shepherdElectrumSendPromise,
validateAddressPromise,
} from '../../../actions/actionCreators';
import { translate } from '../../../translate/translate';
import {
@ -237,11 +238,11 @@ class ClaimInterestModal extends React.Component {
}
});
} else {
sendToAddressPromise(
validateAddressPromise(
this.props.ActiveCoin.coin,
this.state.selectedAddress,
this.props.ActiveCoin.balance.transparent
).then((json) => {
this.state.selectedAddress
)
.then((json) => {
if (json.error &&
json.error.code) {
Store.dispatch(
@ -251,16 +252,41 @@ class ClaimInterestModal extends React.Component {
'error'
)
);
} else if (json.result && json.result.length && json.result.length === 64) {
} else if (json.result && !json.result.iswatchonly && json.result.ismine) {
sendToAddressPromise(
this.props.ActiveCoin.coin,
this.state.selectedAddress,
this.props.ActiveCoin.balance.transparent
).then((json) => {
if (json.error &&
json.error.code) {
Store.dispatch(
triggerToaster(
json.error.message,
'Error',
'error'
)
);
} else if (json.result && json.result.length && json.result.length === 64) {
Store.dispatch(
triggerToaster(
`${translate('TOASTR.CLAIM_INTEREST_BALANCE_SENT_P1')} ${this.state.selectedAddress}. ${translate('TOASTR.CLAIM_INTEREST_BALANCE_SENT_P2')}`,
translate('TOASTR.WALLET_NOTIFICATION'),
'success',
false
)
);
this.closeModal();
}
});
} else {
Store.dispatch(
triggerToaster(
`${translate('TOASTR.CLAIM_INTEREST_BALANCE_SENT_P1')} ${this.state.selectedAddress}. ${translate('TOASTR.CLAIM_INTEREST_BALANCE_SENT_P2')}`,
translate('TOASTR.WALLET_NOTIFICATION'),
'success',
false
`Failed to verify address ${this.state.selectedAddress}`,
'Error',
'error'
)
);
this.closeModal();
}
});
}

Loading…
Cancel
Save