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 pagination styling for pages > 5 (#416)
* Fixed sizing on squat videos (#419) * Fixed sizing on squat videos (#419)
* Support claims no longer show up on Published page (#384) * Support claims no longer show up on Published page (#384)
* Check for valid address when sending credits (#445)
### Deprecated ### Deprecated
* *

View file

@ -2,6 +2,7 @@ import * as types from "constants/action_types";
import lbry from "lbry"; import lbry from "lbry";
import { import {
selectDraftTransaction, selectDraftTransaction,
selectDraftTransactionAddress,
selectDraftTransactionAmount, selectDraftTransactionAmount,
selectBalance, selectBalance,
} from "selectors/wallet"; } from "selectors/wallet";
@ -69,6 +70,7 @@ export function doSendDraftTransaction() {
return function(dispatch, getState) { return function(dispatch, getState) {
const state = getState(); const state = getState();
const draftTx = selectDraftTransaction(state); const draftTx = selectDraftTransaction(state);
const address = selectDraftTransactionAddress(state);
const balance = selectBalance(state); const balance = selectBalance(state);
const amount = selectDraftTransactionAmount(state); const amount = selectDraftTransactionAmount(state);
@ -76,6 +78,15 @@ export function doSendDraftTransaction() {
return dispatch(doOpenModal("insufficientBalance")); return dispatch(doOpenModal("insufficientBalance"));
} }
lbry
.is_address({ address })
.then(addressIsValid => {
if (!addressIsValid) {
dispatch(doOpenModal("invalidAddress"));
reject();
}
})
.then(() => {
dispatch({ dispatch({
type: types.SEND_TRANSACTION_STARTED, type: types.SEND_TRANSACTION_STARTED,
}); });
@ -109,6 +120,7 @@ export function doSendDraftTransaction() {
address: draftTx.address, address: draftTx.address,
}) })
.then(successCallback, errorCallback); .then(successCallback, errorCallback);
});
}; };
} }

View file

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