Skip to content

Commit 6adc70f

Browse files
author
jagdeep sidhu
committed
validate sys and eth addresses on input
1 parent 42ef4d6 commit 6adc70f

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/wizard/Step1EthToSys.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,16 @@ class Step1ES extends Component {
387387
let fromAccount = userInput.sysxFromAccount;
388388
let assetGUID = userInput.toSysAssetGUID;
389389
let syscoinWitnessAddress = userInput.syscoinWitnessAddress;
390+
try {
391+
sjs.utils.bitcoinjs.address.toOutputScript(syscoinWitnessAddress, CONFIGURATION.SysNetwork)
392+
} catch (e) {
393+
console.log('e ' + e.message, " address " + syscoinWitnessAddress)
394+
validateNewInput.buttonVal = false;
395+
validateNewInput.buttonValMsg = this.props.t("step1FSInvalidDestination");
396+
this.setState(Object.assign(userInput, validateNewInput, this._validationErrors(validateNewInput)));
397+
this.setState({working: false});
398+
return;
399+
}
390400
let allowance = web3.utils.toBN(0);
391401
if (assetGUID !== CONFIGURATION.SYSXAsset) {
392402
allowance = await contractBase.methods.allowance(fromAccount, CONFIGURATION.ERC20Manager).call();

src/wizard/Step1SysToEth.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11

22
import React, { Component } from 'react';
33
import CONFIGURATION from '../config';
4+
import Web3 from 'web3';
45
const satoshibitcoin = require("satoshi-bitcoin");
5-
const sjs = require('syscoinjs-lib')
6+
const sjs = require('syscoinjs-lib');
7+
const web3 = new Web3(Web3.givenProvider);
68
class Step1 extends Component {
79
constructor(props) {
810
super(props);
@@ -137,14 +139,20 @@ class Step1 extends Component {
137139
if(!userInput.ethaddress || userInput.ethaddress === ""){
138140
validateNewInput.ethaddressVal = false;
139141
valid = false;
140-
}
142+
}
143+
if (!web3.utils.isAddress(userInput.ethaddress)) {
144+
validateNewInput.buttonVal = false;
145+
validateNewInput.buttonValMsg = this.props.t("step1FSInvalidDestination");
146+
self.setState({working: false});
147+
self.setState(Object.assign(userInput, validateNewInput, this._validationErrors(validateNewInput)));
148+
return;
149+
}
141150
let self = this;
142151

143152
if(valid === true){
144153
this.setState({working: true});
145154
if(userInput.asset.length > 0 && userInput.asset !== 0 && userInput.asset !== "0"){
146155
let assetGuid = userInput.asset.toString();
147-
148156
let ethAddressStripped = userInput.ethaddress.toString();
149157
if(ethAddressStripped && ethAddressStripped.startsWith("0x")){
150158
ethAddressStripped = ethAddressStripped.substr(2, ethAddressStripped.length);

0 commit comments

Comments
 (0)