From 03ac4ed3af15a82c9017e3c9820aa79b1dbcb5d8 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Mon, 4 Jun 2018 16:17:18 +0200 Subject: [PATCH 1/2] Use real values for tokens --- package.json | 4 +-- src/Send/Send.js | 2 +- .../TokensList/BalanceLayout/BalanceLayout.js | 14 +++++++---- .../TokensList/EthBalance/EthBalance.js | 2 +- .../TokensList/TokenBalance/TokenBalance.js | 25 ++++++++++++++++--- yarn.lock | 16 ++++++------ 6 files changed, 42 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index d9354580..15a00584 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,8 @@ }, "dependencies": { "@parity/api": "^2.1.22", - "@parity/light.js": "https://github.com/parity-js/light.js#898e90f43327fd50d0560b8e4db6d5c670bc1b20", + "@parity/light.js": "https://github.com/parity-js/light.js#bd5838dea1fdf2260d4df92e02d5028459824917", + "@parity/shared": "^3.0.1", "async-retry": "^1.2.1", "axios": "^0.18.0", "checksum": "^0.1.1", @@ -67,7 +68,6 @@ "rxjs": "^6.1.0" }, "devDependencies": { - "@parity/shared": "^2.2.28", "babel-eslint": "^8.2.3", "cross-env": "^5.1.4", "node-sass": "^4.9.0", diff --git a/src/Send/Send.js b/src/Send/Send.js index 2a8899a0..1b20b22d 100644 --- a/src/Send/Send.js +++ b/src/Send/Send.js @@ -13,7 +13,7 @@ import ethereumIcon from '../assets/img/tokens/ethereum.png'; import light from '../hoc'; @light({ - balance: () => myBalance$().pipe(map(value => +fromWei(value.toString()))), + balance: () => myBalance$().pipe(map(value => +fromWei(value))), me: defaultAccount$ }) class Send extends PureComponent { diff --git a/src/Tokens/TokensList/BalanceLayout/BalanceLayout.js b/src/Tokens/TokensList/BalanceLayout/BalanceLayout.js index 3a49f3f6..d662b1b6 100644 --- a/src/Tokens/TokensList/BalanceLayout/BalanceLayout.js +++ b/src/Tokens/TokensList/BalanceLayout/BalanceLayout.js @@ -4,19 +4,23 @@ // SPDX-License-Identifier: MIT import React from 'react'; +import PropTypes from 'prop-types'; -const BalanceLayout = ({ balance, token }) => +const BalanceLayout = ({ balance, token }) => (
{token.symbol}
-
- {token.name} -
+
{token.name}
{Number.isFinite(balance) ? balance.toFixed(2) : '...'}{' '} {token.symbol}
-
; + +); + +BalanceLayout.propTypes = { + balance: PropTypes.number +}; export default BalanceLayout; diff --git a/src/Tokens/TokensList/EthBalance/EthBalance.js b/src/Tokens/TokensList/EthBalance/EthBalance.js index 779ec222..e092c908 100644 --- a/src/Tokens/TokensList/EthBalance/EthBalance.js +++ b/src/Tokens/TokensList/EthBalance/EthBalance.js @@ -14,7 +14,7 @@ import BalanceLayout from '../BalanceLayout'; import light from '../../../hoc'; @light({ - balance: () => myBalance$().pipe(map(value => +fromWei(value.toString()))) + balance: () => myBalance$().pipe(map(value => +fromWei(value))) }) class EthBalance extends PureComponent { static propTypes = { diff --git a/src/Tokens/TokensList/TokenBalance/TokenBalance.js b/src/Tokens/TokensList/TokenBalance/TokenBalance.js index 5bcadc1b..a12ed43f 100644 --- a/src/Tokens/TokensList/TokenBalance/TokenBalance.js +++ b/src/Tokens/TokensList/TokenBalance/TokenBalance.js @@ -3,19 +3,36 @@ // // SPDX-License-Identifier: MIT -import React, { PureComponent } from 'react'; +import React, { Component } from 'react'; +import abi from '@parity/shared/lib/contracts/abi/eip20'; +import { defaultAccount$, makeContract$ } from '@parity/light.js'; +import { Link } from 'react-router-dom'; +import { map, switchMap } from 'rxjs/operators'; import PropTypes from 'prop-types'; import BalanceLayout from '../BalanceLayout'; +import light from '../../../hoc'; -class TokenBalance extends PureComponent { +@light({ + balance: ({ token: { address, decimals } }) => + defaultAccount$().pipe( + switchMap(defaultAccount => + makeContract$(address, abi).balanceOf(defaultAccount) + ), + map(value => +value.div(10 ** decimals)) + ) +}) +class TokenBalance extends Component { static propTypes = { token: PropTypes.object.isRequired }; render () { - const balance = Math.round(Math.random() * 100); - return ; + return ( + + + + ); } } diff --git a/yarn.lock b/yarn.lock index bee3629e..65f6c896 100644 --- a/yarn.lock +++ b/yarn.lock @@ -131,18 +131,18 @@ u2f-api "0.0.9" u2f-api-polyfill "0.4.3" -"@parity/light.js@https://github.com/parity-js/light.js#898e90f43327fd50d0560b8e4db6d5c670bc1b20": +"@parity/light.js@https://github.com/parity-js/light.js#bd5838dea1fdf2260d4df92e02d5028459824917": version "1.0.0" - resolved "https://github.com/parity-js/light.js#898e90f43327fd50d0560b8e4db6d5c670bc1b20" + resolved "https://github.com/parity-js/light.js#bd5838dea1fdf2260d4df92e02d5028459824917" dependencies: "@babel/runtime" "^7.0.0-beta.46" "@parity/api" "^2.1.22" memoizee "^0.4.12" rxjs "^6.1.0" -"@parity/shared@^2.2.28": - version "2.2.28" - resolved "https://registry.yarnpkg.com/@parity/shared/-/shared-2.2.28.tgz#5a68188de1ce9c30f7964423ebffdece6a5963ea" +"@parity/shared@^3.0.1": + version "3.0.1" + resolved "https://registry.yarnpkg.com/@parity/shared/-/shared-3.0.1.tgz#3506cc235ed9e73f88e20dca1d7300746ec050ff" dependencies: "@parity/ledger" "~2.1.3" bignumber.js "4.1.0" @@ -2939,8 +2939,8 @@ es5-ext@^0.10.14, es5-ext@^0.10.35, es5-ext@^0.10.9, es5-ext@~0.10.14: next-tick "1" es5-ext@^0.10.30, es5-ext@~0.10.2: - version "0.10.44" - resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.10.44.tgz#7a877e994bb190aebd4718aa2d62784a12e2ca20" + version "0.10.45" + resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.10.45.tgz#0bfdf7b473da5919d5adf3bd25ceb754fccc3653" dependencies: es6-iterator "~2.0.3" es6-symbol "~3.1.1" @@ -8406,7 +8406,7 @@ sockjs@0.3.18: faye-websocket "^0.10.0" uuid "^2.0.2" -solc@ngotchac/solc-js: +"solc@github:ngotchac/solc-js": version "0.4.4" resolved "https://codeload.github.com/ngotchac/solc-js/tar.gz/04eb38cc3003fba8cb3656653a7941ed36408818" dependencies: -- GitLab From 1ffee33f4e0f3b44b0dd7928b41c52345015cd46 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Mon, 4 Jun 2018 16:37:30 +0200 Subject: [PATCH 2/2] Update latest version of light.js --- package.json | 2 +- src/Tokens/TokensList/TokenBalance/TokenBalance.js | 2 +- yarn.lock | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 15a00584..9c220170 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ }, "dependencies": { "@parity/api": "^2.1.22", - "@parity/light.js": "https://github.com/parity-js/light.js#bd5838dea1fdf2260d4df92e02d5028459824917", + "@parity/light.js": "https://github.com/parity-js/light.js#2052c910d1ff4f4e38d4cba7fb5578ac4500f0ae", "@parity/shared": "^3.0.1", "async-retry": "^1.2.1", "axios": "^0.18.0", diff --git a/src/Tokens/TokensList/TokenBalance/TokenBalance.js b/src/Tokens/TokensList/TokenBalance/TokenBalance.js index a12ed43f..2ea1ba33 100644 --- a/src/Tokens/TokensList/TokenBalance/TokenBalance.js +++ b/src/Tokens/TokensList/TokenBalance/TokenBalance.js @@ -17,7 +17,7 @@ import light from '../../../hoc'; balance: ({ token: { address, decimals } }) => defaultAccount$().pipe( switchMap(defaultAccount => - makeContract$(address, abi).balanceOf(defaultAccount) + makeContract$(address, abi).balanceOf$(defaultAccount) ), map(value => +value.div(10 ** decimals)) ) diff --git a/yarn.lock b/yarn.lock index 65f6c896..792be438 100644 --- a/yarn.lock +++ b/yarn.lock @@ -131,9 +131,9 @@ u2f-api "0.0.9" u2f-api-polyfill "0.4.3" -"@parity/light.js@https://github.com/parity-js/light.js#bd5838dea1fdf2260d4df92e02d5028459824917": +"@parity/light.js@https://github.com/parity-js/light.js#2052c910d1ff4f4e38d4cba7fb5578ac4500f0ae": version "1.0.0" - resolved "https://github.com/parity-js/light.js#bd5838dea1fdf2260d4df92e02d5028459824917" + resolved "https://github.com/parity-js/light.js#2052c910d1ff4f4e38d4cba7fb5578ac4500f0ae" dependencies: "@babel/runtime" "^7.0.0-beta.46" "@parity/api" "^2.1.22" @@ -8406,7 +8406,7 @@ sockjs@0.3.18: faye-websocket "^0.10.0" uuid "^2.0.2" -"solc@github:ngotchac/solc-js": +solc@ngotchac/solc-js: version "0.4.4" resolved "https://codeload.github.com/ngotchac/solc-js/tar.gz/04eb38cc3003fba8cb3656653a7941ed36408818" dependencies: -- GitLab