Newer
Older
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.
//
import { balanceOf$, makeContract, withoutLoading } 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';
erc20Balance: ({ token, accountAddress }) =>
makeContract(token.address, abi)
.balanceOf$(accountAddress)
.pipe(
map(value => value && value.div(10 ** token.decimals))
)
});
export const withEthBalance = light({
balanceOf$(accountAddress).pipe(
withoutLoading(),
map(value => value && fromWei(value))
)
});
* A HOC on light.js to get the current balance. The inner component needs to
* have a `token` field and a `accountAddress` field in its props.
* class MyComponent extends React.Component{
*
* }
*/
withErc20Balance,
withEthBalance
),
withProps(props => ({
balance: props.erc20Balance || props.ethBalance
}))
);