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, type: DASHBOARD_ACTIVE_COIN_SENDTO,
lastSendToResponse: null, 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, shepherdElectrumListunspent,
shepherdElectrumSendPreflight, shepherdElectrumSendPreflight,
shepherdElectrumSendPromise, shepherdElectrumSendPromise,
validateAddressPromise,
} from '../../../actions/actionCreators'; } from '../../../actions/actionCreators';
import { translate } from '../../../translate/translate'; import { translate } from '../../../translate/translate';
import { import {
@ -237,11 +238,11 @@ class ClaimInterestModal extends React.Component {
} }
}); });
} else { } else {
sendToAddressPromise( validateAddressPromise(
this.props.ActiveCoin.coin, this.props.ActiveCoin.coin,
this.state.selectedAddress, this.state.selectedAddress
this.props.ActiveCoin.balance.transparent )
).then((json) => { .then((json) => {
if (json.error && if (json.error &&
json.error.code) { json.error.code) {
Store.dispatch( Store.dispatch(
@ -251,16 +252,41 @@ class ClaimInterestModal extends React.Component {
'error' '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( Store.dispatch(
triggerToaster( triggerToaster(
`${translate('TOASTR.CLAIM_INTEREST_BALANCE_SENT_P1')} ${this.state.selectedAddress}. ${translate('TOASTR.CLAIM_INTEREST_BALANCE_SENT_P2')}`, `Failed to verify address ${this.state.selectedAddress}`,
translate('TOASTR.WALLET_NOTIFICATION'), 'Error',
'success', 'error'
false
) )
); );
this.closeModal();
} }
}); });
} }

Loading…
Cancel
Save