Skip to content

Latest commit

 

History

History
31 lines (23 loc) · 1.06 KB

Wallets iteration.md

File metadata and controls

31 lines (23 loc) · 1.06 KB

Wallets iteration

Often you may want to be able an action on all wallets aviable (eg. checking if it has been ingected );

this can easly be done with a simple for loop iterating over Wallet.stringNames array as follows

NOTE: it is assumed that all the wallet are already enabled

for( let i = 0; i < Wallet.stringNames.length; i++ )
{
    const thisCycleWallet = Wallet.get( Wallet.stringNames[i] );

    doStuffWithWallet( thisCycleWallet );
}

this way we can also define our own utility function such as:

function allWalletsAreInjected()
{
    return Wallet.stringNames.every(
        wName => Wallet.has( wName )
    );
}

NOTE: Array.every acts as arr.map( arrElem => hasProperty( arrElem ) ).reduce( (a,b) => a && b , true ) but should be overall more efficient since it does not have to test every element but can return false at the first element that is indeed false

Array.prototype.every documentation