start method
Future<NetworkParams?>
start(
- Keyring keyring, {
- List<
NetworkParams> ? nodes, - KeyringEVM? keyringEVM,
- NetworkParams? nodeEVM,
This method will be called while App switched to a plugin. In this method, the plugin will:
- connect to nodes.
- retrieve network const & state.
- subscribe balances & set balancesStore.
Implementation
Future<NetworkParams?> start(Keyring keyring,
{List<NetworkParams>? nodes,
KeyringEVM? keyringEVM,
NetworkParams? nodeEVM}) async {
if (nodeEVM == null) {
final res = await sdk.api.connectNode(keyring, nodes ?? nodeList);
if (res == null) return null;
keyring.setSS58(res.ss58);
await updateNetworkState();
if (keyring.current.address != null) {
sdk.api.account.subscribeBalance(keyring.current.address,
(BalanceData data) {
_updateBalances(keyring.current, data);
});
}
onStarted(keyring);
return res;
}
final evmRes = await sdk.api.connectEVM(nodeEVM);
if (evmRes == null) return null;
if (keyringEVM?.current.address != null) {
final data = await sdk.api.eth.account
.getNativeTokenBalance(keyringEVM?.current.address ?? '');
_updateBalances(
keyringEVM!.current.toKeyPairData(),
BalanceData()
..accountId = keyringEVM.current.address
..freeBalance = data
..availableBalance = data
..lockedBalance = '0'
..reservedBalance = '0');
}
onStartedEVM(keyringEVM!);
return evmRes;
}