Skip to content

Commit

Permalink
[DDW-879] Reverting back address validator with TRUE response
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomislav Horaček committed Sep 11, 2019
1 parent bdad856 commit 690cc78
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
15 changes: 15 additions & 0 deletions source/renderer/app/api/api.js
Expand Up @@ -597,6 +597,21 @@ export default class AdaApi {
}
};

async isValidAddress(address: string): Promise<boolean> {
Logger.debug('AdaApi::isValidAdaAddress called', {
parameters: { address },
});
/* try {
const response: Address = await getAddress(this.config, { address });
Logger.debug('AdaApi::isValidAdaAddress success', { response });
return true;
} catch (error) {
Logger.error('AdaApi::isValidAdaAddress error', { error });
return false;
} */
return true;
}

isValidMnemonic = (mnemonic: string): boolean =>
isValidMnemonic(mnemonic, WALLET_RECOVERY_PHRASE_WORD_COUNT);

Expand Down
30 changes: 9 additions & 21 deletions source/renderer/app/components/wallet/WalletSendForm.js
Expand Up @@ -108,6 +108,7 @@ type Props = {
address: string,
amount: number
) => Promise<BigNumber>,
addressValidator: Function,
openDialogAction: Function,
isDialogOpen: Function,
onExternalLinkClick?: Function,
Expand Down Expand Up @@ -177,6 +178,7 @@ export default class WalletSendForm extends Component<Props, State> {
validators: [
async ({ field, form }) => {
const { value } = field;

if (value === '') {
this._resetTransactionFee();
return [
Expand All @@ -187,13 +189,12 @@ export default class WalletSendForm extends Component<Props, State> {
const amountField = form.$('amount');
const amountValue = amountField.value;
const isAmountValid = amountField.isValid;
const transactionFee = await this._calculateTransactionFee(
value,
amountValue
);
const { isValidAddress } = transactionFee;
if (!isAmountValid || !isValidAddress) {
const isValidAddress = await this.props.addressValidator(value);

if (isValidAddress && isAmountValid) {
this._resetTransactionFee();
} else {
await this._calculateTransactionFee(value, amountValue);
}
return [
isValidAddress,
Expand Down Expand Up @@ -376,18 +377,10 @@ export default class WalletSendForm extends Component<Props, State> {
transactionFeeError: null,
});
}
return {
isValidAddress: true,
hasError: false,
amount: fee,
};
} catch (error) {
// @API TODO - address is not correct on fee check
if (error.message === 'NotValidAddress') {
return {
isValidAddress: false,
hasError: true,
amount: null,
};
return;
}
const errorHasLink = !!error.values.linkLabel;
const transactionFeeError = errorHasLink ? (
Expand All @@ -407,10 +400,5 @@ export default class WalletSendForm extends Component<Props, State> {
});
}
}
return {
isValidAddress: true,
hasError: true,
fee: null,
};
}
}
2 changes: 2 additions & 0 deletions source/renderer/app/containers/wallet/WalletSendPage.js
Expand Up @@ -27,6 +27,7 @@ export default class WalletSendPage extends Component<Props> {
const { intl } = this.context;
const { uiDialogs, wallets, transactions, app } = this.props.stores;
const { actions } = this.props;
const { isValidAddress } = wallets;
const { calculateTransactionFee, validateAmount } = transactions;
const activeWallet = wallets.active;

Expand All @@ -51,6 +52,7 @@ export default class WalletSendPage extends Component<Props> {
amount,
})
}
addressValidator={isValidAddress}
isDialogOpen={uiDialogs.isOpen}
openDialogAction={actions.dialogs.open.trigger}
isRestoreActive={isRestoreActive}
Expand Down
2 changes: 2 additions & 0 deletions source/renderer/app/stores/WalletsStore.js
Expand Up @@ -372,6 +372,8 @@ export default class WalletsStore extends Store {
});
};

isValidAddress = (address: string) => this.api.ada.isValidAddress(address);

isValidMnemonic = (mnemonic: string) =>
this.api.ada.isValidMnemonic(mnemonic);

Expand Down

0 comments on commit 690cc78

Please sign in to comment.