From f3d40bcb68f9e0a64790b00b3361c0c2ca0983e6 Mon Sep 17 00:00:00 2001 From: meriadec Date: Mon, 2 Jul 2018 13:58:26 +0200 Subject: [PATCH] Prevent check recipient valid if empty And add a catch to fallback + warning if check throwed --- src/bridge/LibcoreBridge.js | 1 + .../modals/Send/fields/RecipientField.js | 17 +++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/bridge/LibcoreBridge.js b/src/bridge/LibcoreBridge.js index 5e6bd289..c99dfbe1 100644 --- a/src/bridge/LibcoreBridge.js +++ b/src/bridge/LibcoreBridge.js @@ -52,6 +52,7 @@ const isRecipientValid = (currency, recipient) => { const key = `${currency.id}_${recipient}` let promise = recipientValidLRU.get(key) if (promise) return promise + if (!recipient) return Promise.resolve(false) promise = libcoreValidAddress .send({ address: recipient, diff --git a/src/components/modals/Send/fields/RecipientField.js b/src/components/modals/Send/fields/RecipientField.js index f7974c54..9a3afe72 100644 --- a/src/components/modals/Send/fields/RecipientField.js +++ b/src/components/modals/Send/fields/RecipientField.js @@ -3,6 +3,7 @@ import React, { Component } from 'react' import type { Account } from '@ledgerhq/live-common/lib/types' import type { T } from 'types/common' import type { WalletBridge } from 'bridge/types' +import logger from 'logger' import Box from 'components/base/Box' import Label from 'components/base/Label' import LabelInfoTooltip from 'components/base/LabelInfoTooltip' @@ -39,12 +40,16 @@ class RecipientField extends Component, { isVali async resync() { const { account, bridge, transaction } = this.props const syncId = ++this.syncId - const isValid = await bridge.isRecipientValid( - account.currency, - bridge.getTransactionRecipient(account, transaction), - ) - if (syncId !== this.syncId) return - this.setState({ isValid }) + try { + const isValid = await bridge.isRecipientValid( + account.currency, + bridge.getTransactionRecipient(account, transaction), + ) + if (syncId !== this.syncId) return + this.setState({ isValid }) + } catch (err) { + logger.warn(`Can't check if recipient is valid`, err) + } } onChange = (recipient: string, maybeExtra: ?Object) => {