How to use the nahmii-sdk/lib/wallet/balance-tracker-contract function in nahmii-sdk

To help you get started, we’ve selected a few nahmii-sdk 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 hubiinetwork / hubii-core / src / containers / NahmiiHoc / saga.js View on Github external
export function* loadStagedBalances({ address }, network) {
  if (network.provider._network.chainId === 1) {
    yield put(actions.loadStagedBalancesSuccess(address, []));
    return;
  }
  let supportedAssets = (yield select(makeSelectSupportedAssets())).toJS();
  if (supportedAssets.loading) {
    yield take(LOAD_SUPPORTED_TOKENS_SUCCESS);
    supportedAssets = (yield select(makeSelectSupportedAssets())).toJS();
  }

  const { nahmiiProvider } = network;
  const balanceTrackerContract = new BalanceTrackerContract(nahmiiProvider);

  while (true) { // eslint-disable-line no-constant-condition
    try {
      const balanceTrackerContractAddress = balanceTrackerContract.address;

      // derive function selector
      const balanceType = yield balanceTrackerContract.stagedBalanceType();
      const funcBytes = utils.solidityKeccak256(['string'], ['get(address,bytes32,address,uint256)']);
      const funcSelector = funcBytes.slice(0, 10);

      // send a batch of RPC requests asking for all staged balances
      // https://www.jsonrpc.org/specification#batch
      const currencyCtList = supportedAssets.assets.map((a) => a.currency);
      const requestBatch = currencyCtList.map((ct) => {
        // encode arguments, prepare them for being sent
        const encodedArgs = utils.defaultAbiCoder.encode(['address', 'bytes32', 'address', 'int256'], [address, balanceType, ct, 0]);