Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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]);