Newer
Older
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
import { balanceOf$, makeContract } from '@parity/light.js';
import branch from 'recompose/branch';
import compose from 'recompose/compose';
import { fromWei } from '@parity/api/lib/util/wei';
import light from '@parity/light.js-react';
import { map, startWith } from 'rxjs/operators';
erc20Balance: ({ token, account: { address } }) =>
.pipe(
map(value => value && value.div(10 ** token.decimals)),
startWith(undefined)
)
});
export const withEthBalance = light({
ethBalance: ({ account: { address } }) =>
balanceOf$(address).pipe(
map(value => value && fromWei(value)),
startWith(undefined)
)
* A HOC on light.js to get the current balance of the account.
*
* The component needs to receive a `token` prop as well as an
* `account: {address}` prop (i.e. needs to be decorated with withAccount).
* class MyComponent extends React.Component{
*
* }
*/
withErc20Balance,
withEthBalance
),
withProps(props => ({
balance: props.erc20Balance || props.ethBalance
}))
);