buildWalletReturnLink function
- required String base,
- required String clientId,
- ReturnStrategy? returnStrategy = ReturnStrategy.back,
Builds the link that brings an already-connected wallet to the foreground.
A wallet app does not surface a request the moment the bridge delivers it — not even while it is on screen. It works through what is waiting when it is activated through its own link, so a dApp on the same device has to open one after posting a request, or the customer is left looking at a wallet that shows nothing.
This is the "empty" deep link: no r, because there is no new connect to
make, just the session's clientId and where to go afterwards. Opening the
bare scheme instead — tonkeeper-tc:// with nothing after it — gets an
"unsupported deeplink" from the wallet.
base should be the wallet's universal URL where it has one. A custom
scheme works too, but an HTTPS link degrades to a web page when the wallet
turns out not to be installed.
Implementation
String buildWalletReturnLink({
required String base,
required String clientId,
ReturnStrategy? returnStrategy = ReturnStrategy.back,
}) {
final parameters = <String, String>{
'id': clientId,
'ret': ?returnStrategy?.value,
};
final query = parameters.entries
.map((e) => '${e.key}=${Uri.encodeComponent(e.value)}')
.join('&');
final separator = base.contains('?') ? '&' : '?';
return '$base$separator$query';
}