How to use the @cityofzion/neon-js.api.getBalanceFrom function in @cityofzion/neon-js

To help you get started, we’ve selected a few @cityofzion/neon-js 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 CityOfZion / neon-wallet / app / actions / balancesActions.js View on Github external
determineIfBalanceUpdated(
      { [token.symbol]: token.balance },
      soundEnabled,
      networkHasChanged,
      adressHasChanged,
    )
    inMemoryBalances[token.symbol] = token.balance
    parsedTokenBalances.push({
      [token.scriptHash]: {
        ...token,
      },
    })
  })

  // asset balances
  const assetBalances = await api
    .getBalanceFrom({ net, address }, api.neoscan)
    .catch(e => console.error(e))

  const assets = get(assetBalances, 'balance.assets', {})
  // The API doesn't always return NEO or GAS keys if, for example, the address only has one asset
  const neoBalance = assets.NEO ? assets.NEO.balance.toString() : '0'
  const gasBalance = assets.GAS
    ? assets.GAS.balance.round(COIN_DECIMAL_LENGTH).toString()
    : '0'
  const parsedAssets = [
    { [ASSETS.NEO]: neoBalance },
    { [ASSETS.GAS]: gasBalance },
  ]
  determineIfBalanceUpdated(
    { [ASSETS.NEO]: neoBalance },
    soundEnabled,
github CityOfZion / neon-wallet / app / modules / transactions.js View on Github external
const config = {
      net,
      tokensBalanceMap,
      address: fromAddress,
      publicKey,
      privateKey: new wallet.Account(wif).privateKey,
      signingFunction: isHardwareSend ? signingFunction : null,
      fees,
      url,
      balance: undefined,
      tx: undefined,
      intents: undefined,
      script: undefined,
      gas: undefined,
    }
    const balanceResults = await api
      .getBalanceFrom({ net, address: fromAddress }, api.neoscan)
      .catch(e => {
        // indicates that neo scan is down and that api.sendAsset and api.doInvoke
        // will fail unless balances are supplied
        console.error(e)
        config.balance = generateBalanceInfo(tokensBalanceMap, fromAddress, net)
      })
    if (balanceResults) config.balance = balanceResults.balance

    try {
      const script = buildTransferScript(
        config.net,
        sendEntries,
        config.address,
        // $FlowFixMe
        config.tokensBalanceMap,
github nos / client / src / shared / util / getBalances.js View on Github external
promises.push((async () => {
    const assetBalances = await api.getBalanceFrom({ net, address }, api.neoscan);

    const { assets } = assetBalances.balance;

    // The API doesn't always return NEO or GAS keys if, for example, the address only has one asset
    const neoBalance = assets.NEO ? assets.NEO.balance.toString() : '0';
    const gasBalance = assets.GAS ? assets.GAS.balance.round(8).toString() : '0';

    return {
      [NEO]: { scriptHash: NEO, balance: neoBalance, decimals: 0 },
      [GAS]: { scriptHash: GAS, balance: gasBalance, decimals: 8 }
    };
  })());
github nos / client / src / renderer / shared / util / claimGas.js View on Github external
async function fetchBalance({ net, address }) {
  const response = await api.getBalanceFrom({ net, address }, api.neoscan);
  const { NEO } = response.balance.assets;
  return NEO ? NEO.balance : new BigNumber(0);
}