This is the first step in connecting to the wallet. Before doing anything
else, you have to wait for the wallet to announce itself.
This function waits for the wallet to announce itself
Wait for wallet to announce itself, and then return.
Example
// example call awaitsk.detect(sk.TIMEOUT_DEF_DETECT_MS, // timeout "failed to detect wallet", // error on timeout sk.cl()); // cl = console logger // example return data (positive case) {ok : true, result : {id : "{aee9e933-52b6-410a-8c3f-99c6be596b4e}", name : "Superhero", networkId : "ae_uat", origin : "moz-extension://ee425d81-d5b2-44b6-9406-4da31b019e7c", type : "extension"}} // example return data (negative case) {ok : false, error : {code : 420, message : "failed to detect wallet", data : {}}}
Example
// example calling code // from: https://github.com/aeternity/Vanillae/blob/0e030cb39554e9f09e4460d1da4e7654fe7456de/sidekick/examples/src/connection.ts#L34-L66 // document has a button with id=detect // this is the function that is triggered when the button is clicked asyncfunctiondetect(logger: sk.Logger): Promise<void> { leth4 = document.getElementById("detected")!; letpre = document.getElementById("detect-info")!;
// try to detect the wallet // will fail on timeout error // console logger letmaybe_wallet_info =//: sk.Safe<awcp.EventData_W2A_connection_announcePresence, sk.TimeoutError> = awaitsk.detect(sk.TIMEOUT_DEF_DETECT_MS, "failed to detect wallet", logger);
console.log(maybe_wallet_info);
// ok means wallet was detected if (maybe_wallet_info.ok) { h4.innerHTML = "detected"; h4.style.color = "green"; pre.innerHTML = JSON.stringify(maybe_wallet_info.result, undefined, 4); } else { h4.innerHTML = "error"; h4.style.color = "crimson"; pre.innerHTML = JSON.stringify(maybe_wallet_info.error, undefined, 4); } }
// want to create a logger down here letlogger = sk.cl(); // detect button. The ! turns off a typescript warning, does not change the // code behavior document.getElementById('detect')!.onclick = function() { detect(logger); } ;
This is the first step in connecting to the wallet. Before doing anything else, you have to wait for the wallet to announce itself.
This function waits for the wallet to announce itself
Wait for wallet to announce itself, and then return.
Example
Example