From 42ddb4f26c5581cd2a86c3101e2168c5114a8478 Mon Sep 17 00:00:00 2001 From: Nicolas Gotchac Date: Fri, 13 Jan 2017 18:14:25 +0100 Subject: [PATCH] Fix token images // Error in Contract Queries (#4169) --- js/src/ui/Balance/balance.js | 14 +++++++++----- js/src/ui/Form/TypedInput/typedInput.js | 8 ++++++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/js/src/ui/Balance/balance.js b/js/src/ui/Balance/balance.js index b8f98c2ac..2010bdc78 100644 --- a/js/src/ui/Balance/balance.js +++ b/js/src/ui/Balance/balance.js @@ -62,11 +62,15 @@ class Balance extends Component { value = api.util.fromWei(balance.value).toFormat(3); } - let imagesrc = token.image; - if (!imagesrc) { - imagesrc = images[token.address] - ? `${api.dappsUrl}${images[token.address]}` - : unknownImage; + const imageurl = token.image || images[token.address]; + let imagesrc = unknownImage; + + if (imageurl) { + const host = /^(\/)?api/.test(imageurl) + ? api.dappsUrl + : ''; + + imagesrc = `${host}${imageurl}`; } return ( diff --git a/js/src/ui/Form/TypedInput/typedInput.js b/js/src/ui/Form/TypedInput/typedInput.js index 3b19bde08..dcdd599bb 100644 --- a/js/src/ui/Form/TypedInput/typedInput.js +++ b/js/src/ui/Form/TypedInput/typedInput.js @@ -71,7 +71,9 @@ export default class TypedInput extends Component { const { isEth, value } = this.props; if (typeof isEth === 'boolean' && value) { - const ethValue = isEth ? fromWei(value) : value; + // Remove formatting commas + const sanitizedValue = typeof value === 'string' ? value.replace(/,/g, '') : value; + const ethValue = isEth ? fromWei(sanitizedValue) : value; this.setState({ isEth, ethValue }); } } @@ -393,7 +395,9 @@ export default class TypedInput extends Component { return this.setState({ isEth: !isEth }); } - const value = isEth ? toWei(ethValue) : fromWei(ethValue); + // Remove formatting commas + const sanitizedValue = typeof ethValue === 'string' ? ethValue.replace(/,/g, '') : ethValue; + const value = isEth ? toWei(sanitizedValue) : fromWei(sanitizedValue); this.setState({ isEth: !isEth, ethValue: value }, () => { this.onEthValueChange(null, value); });