awaitExternalWalletConnection method
Waits for the wallet to approve the pairing started by beginExternalWalletConnect. Resolves once approved, with every address the wallet exposed, each as a Wallet.
Implementation
@override
Future<List<Wallet>> awaitExternalWalletConnection() async {
Future<List<Wallet>> instrumentationOperation() async {
final operationScope = _state.flowScope.capture(replace: false);
await operationScope.ready();
if (!_state.initialized) {
throw DynamicStateException("call initialize() before using the client");
}
final walletConnectProjectId = _state.projectSettings?.sdk?.walletConnect?.projectId;
if (walletConnectProjectId == null) {
throw DynamicStateException("This environment has no WalletConnect projectId — enable WalletConnect for it in the Dynamic dashboard");
}
operationScope.check();
await _externalWalletProvider.initialize(walletConnectProjectId, _config.appName, _config.appLogoUrl, _config.nativeLink, _config.universalLink);
operationScope.check();
operationScope.check();
final accounts = await _externalWalletProvider.awaitConnection();
operationScope.check();
operationScope.commit(() {
_externalWalletState.externalWalletAccounts = accounts;
_externalWalletState.externalWalletAccountsChanged.emit(_externalWalletState.externalWalletAccounts);
});
return accounts.map((account) => Wallet(id: account.address, chain: account.chain, address: account.address, client: _client, isEmbedded: false, walletProviderKey: "walletConnect", signer: _client.findCapability<ExternalWalletSigner>())).toList();
}
return await _api.instrumentation.runAsync("externalWallet.awaitExternalWalletConnection", instrumentationOperation);
}