Check for valid address when sending credits on Wallet page #489

Closed
alexliebowitz wants to merge 2 commits from validate-address-send into master
3 changed files with 52 additions and 31 deletions

View file

@ -30,6 +30,7 @@ Web UI version numbers should always match the corresponding version of LBRY App
* Fixed pagination styling for pages > 5 (#416)
* Fixed sizing on squat videos (#419)
* Support claims no longer show up on Published page (#384)
* Check for valid address when sending credits (#445)
### Deprecated
*

View file

@ -2,6 +2,7 @@ import * as types from "constants/action_types";
import lbry from "lbry";
import {
selectDraftTransaction,
selectDraftTransactionAddress,
selectDraftTransactionAmount,
selectBalance,
} from "selectors/wallet";
@ -69,6 +70,7 @@ export function doSendDraftTransaction() {
return function(dispatch, getState) {
const state = getState();
const draftTx = selectDraftTransaction(state);
const address = selectDraftTransactionAddress(state);
const balance = selectBalance(state);
const amount = selectDraftTransactionAmount(state);
@ -76,39 +78,49 @@ export function doSendDraftTransaction() {
return dispatch(doOpenModal("insufficientBalance"));
}
dispatch({
type: types.SEND_TRANSACTION_STARTED,
});
const successCallback = results => {
if (results === true) {
dispatch({
type: types.SEND_TRANSACTION_COMPLETED,
});
dispatch(doOpenModal("transactionSuccessful"));
} else {
dispatch({
type: types.SEND_TRANSACTION_FAILED,
data: { error: results },
});
dispatch(doOpenModal("transactionFailed"));
}
};
const errorCallback = error => {
dispatch({
type: types.SEND_TRANSACTION_FAILED,
data: { error: error.message },
});
dispatch(doOpenModal("transactionFailed"));
};
lbry
.wallet_send({
amount: draftTx.amount,
address: draftTx.address,
.is_address({ address })
.then(addressIsValid => {
if (!addressIsValid) {
dispatch(doOpenModal("invalidAddress"));
reject();
}
})
.then(successCallback, errorCallback);
.then(() => {
dispatch({
type: types.SEND_TRANSACTION_STARTED,
});
const successCallback = results => {
if (results === true) {
dispatch({
type: types.SEND_TRANSACTION_COMPLETED,
});
dispatch(doOpenModal("transactionSuccessful"));
} else {
dispatch({
type: types.SEND_TRANSACTION_FAILED,
data: { error: results },
});
dispatch(doOpenModal("transactionFailed"));
}
};
const errorCallback = error => {
dispatch({
type: types.SEND_TRANSACTION_FAILED,
data: { error: error.message },
});
dispatch(doOpenModal("transactionFailed"));
};
lbry
.wallet_send({
amount: draftTx.amount,
address: draftTx.address,
})
.then(successCallback, errorCallback);
});
};
}

View file

@ -53,6 +53,14 @@ const WalletSend = props => {
<input type="submit" className="hidden" />
</div>
</form>
{modal == "invalidAddress" &&
<Modal
isOpen={true}
contentLabel={__("Invalid address")}
onConfirmed={closeModal}
>
{__("You have entered an invalid LBRY address.")}
</Modal>}
{modal == "insufficientBalance" &&
<Modal
isOpen={true}