How to use the web3.utils.fromWei function in web3

To help you get started, we’ve selected a few web3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Giveth / giveth-dapp / src / services / DonationService.jsx View on Github external
const getPledges = () => {
      const maxAmount = new BigNumber(utils.fromWei(amount));
      let currentAmount = new BigNumber('0');
      let fullyDonated = true;

      donations.every(donation => {
        const pledge = pledges.find(n => n.id === donation.pledgeId);

        let delegatedAmount = donation.amountRemaining; // 0.1

        // The next donation is too big, we have to split it
        if (currentAmount.plus(delegatedAmount).isGreaterThan(maxAmount)) {
          delegatedAmount = maxAmount.minus(currentAmount);
          fullyDonated = false;

          // This donation would have value of 0, stop the iteration before it is added
          if (delegatedAmount.isEqualTo(new BigNumber('0'))) return fullyDonated;
        }
github Giveth / giveth-dapp / src / components / views / Delegations.js View on Github external
{ delegations.map((d, index) =>
                            
                              {moment(d.createdAt).format("MM/DD/YYYY")}

                              {d.delegate > 0 &&
                                DAC <em>{getTruncatedText(d.delegateEntity.title, 45)}</em>
                              }
                              {!d.delegate &amp;&amp;
                                {d.ownerType.toUpperCase()} <em>{d.ownerEntity.title}</em>
                              }
                              Ξ{utils.fromWei(d.amount)}                              
                              
                                
                                {getUserName(d.giver)}
                              {d.giverAddress}
                              {d.status}
                                                              

                                {/* when donated to a dac, allow delegation to campaigns and milestones */}
                                {(d.delegate &gt; 0  || d.ownerId === currentUser.address )&amp;&amp;
                                  
                                }
github Giveth / giveth-dapp / src / components / DonateButton.jsx View on Github external
<div>
                  {model.type !== 'milestone' &amp;&amp; (
                     this.setToken(address)}
                      disabled={model.type === 'milestone'}
                    /&gt;
                  )}
                  {/* TODO: remove this b/c the wallet provider will contain this info */}
                  {config.homeNetworkName} {selectedToken.symbol} balance:&nbsp;
                  <em>{utils.fromWei(balance ? balance.toFixed() : '')}</em>
                </div>
              )}

            <span>How much {selectedToken.symbol} do you want to donate?</span>

            {validProvider &amp;&amp;
              maxAmount.toNumber() &gt; 0 &amp;&amp;
              balance.gt(0) &amp;&amp; (
                <div>
                  </div>
github Giveth / giveth-dapp / src / components / DonateButton.jsx View on Github external
getGasPrice().then(gasPrice =>
      this.setState({
        gasPrice: utils.fromWei(gasPrice, 'gwei'),
      }),
    );
github Giveth / giveth-dapp / src / components / CardStats.js View on Github external
render(){
    const { totalDonated, donationCount, maxAmount, campaignsCount, milestonesCount, type, status } = this.props

    return(
      <div>
        <div>
          <span><i></i>{donationCount}</span>
          <p>people</p>
        </div>

        <div>
          { maxAmount &amp;&amp; 
            <span>Ξ{totalDonated &amp;&amp; utils.fromWei(totalDonated)} of Ξ {utils.fromWei(maxAmount)}</span>
          }

          { !maxAmount &amp;&amp;
            <span>Ξ {totalDonated &amp;&amp; utils.fromWei(totalDonated)}</span>
          }
          <p>donated</p>
        </div>  

        <div>
          {type === 'dac' &amp;&amp;
            <div>
              <span><i></i>{campaignsCount}</span>
              <p>campaign(s)</p>
            </div>
          }
</div></div>
github Giveth / giveth-dapp / src / components / DelegateButton.jsx View on Github external
selectedObject({ target }) {
    const admin = this.props.types.find(t => t._id === target.value[0]);

    let maxAmount = utils.fromWei(this.props.donation.amountRemaining);

    if (admin && admin.type === Milestone.type) {
      const diff = utils
        .toBN(admin.maxAmount)
        .sub(utils.toBN(admin.totalDonated || 0))
        .toString();
      if (utils.toBN(diff).lt(utils.toBN(this.props.donation.amountRemaining)))
        maxAmount = utils.fromWei(diff);
    }

    this.setState({ maxAmount, amount: maxAmount, objectsToDelegateTo: target.value });
  }
github Giveth / giveth-dapp / src / lib / blockchain / GivethWallet.js View on Github external
getBalance(unit) {
    return this.balance ? utils.fromWei(this.balance, unit || 'ether') : undefined;
  }
github Giveth / giveth-dapp / src / components / DonateButton.jsx View on Github external
getMaxAmount() {
    const { selectedToken } = this.state;
    const { NativeTokenBalance, model } = this.props;

    const balance =
      selectedToken.symbol === config.nativeTokenName ? NativeTokenBalance : selectedToken.balance;

    if (model.maxDonation && balance.gt(model.maxDonation)) return model.maxDonation;

    return new BigNumber(utils.fromWei(balance.toFixed()));
  }