mirror of
https://github.com/pezkuwichain/pezkuwi-wallet-utils.git
synced 2026-11-05 08:41:07 +00:00
Name each wallet step on the root signing page (#82)
The wallet answers DApp requests one at a time and waits without limit for each, so a tap that reaches a stalled wallet showed nothing. The page now names the step it is waiting on, says after 45 s that the wallet is not answering and how to reset it, and disables the button while a request is pending so repeated taps do not queue more.
This commit is contained in:
1 parent
6864b8c0aa
commit
306c65532e
1 file changed
+23
-3
@@ -216,16 +216,34 @@
|
||||
return;
|
||||
}
|
||||
show('signButton');
|
||||
// The wallet answers DApp requests one at a time and waits without limit for each, so a request it never
|
||||
// shows blocks every later one. Each step is named on the page, so a stalled wallet says where it stopped.
|
||||
const step = (text) => {
|
||||
$('signResult').textContent = text;
|
||||
$('signResult').className = 'note';
|
||||
show('signResult');
|
||||
};
|
||||
const waitFor = (promise, text) => {
|
||||
step(text);
|
||||
const stalled = setTimeout(() => {
|
||||
$('signResult').textContent = text + ' Cîzdan bersiv nade: geroka DApp bi tevahî bigire, rûpelê dîsa veke û carekê bitikîne.';
|
||||
$('signResult').className = 'note warn';
|
||||
}, 45000);
|
||||
return promise.finally(() => clearTimeout(stalled));
|
||||
};
|
||||
$('signButton').onclick = async () => {
|
||||
$('signButton').disabled = true;
|
||||
try {
|
||||
const extension = await injected.enable('Pezkuwi root signing');
|
||||
const accounts = await extension.accounts.get();
|
||||
const extension = await waitFor(injected.enable('Pezkuwi root signing'), 'Bi cîzdanê ve tê girêdan…');
|
||||
const accounts = await waitFor(extension.accounts.get(), 'Hesab têne xwendin…');
|
||||
const mine = accounts.map((a) => ({ address: a.address, keyId: null, public: pz.decodeAddress(a.address) }));
|
||||
for (const account of mine) account.keyId = hex(await sha256(account.public));
|
||||
const holder = mine.find((a) => holders.has(a.keyId));
|
||||
if (!holder) throw new Error('Di vê cîzdanê de hesabekî xwediyê kokê tune.');
|
||||
|
||||
const { signature } = await extension.signer.signRaw({ address: holder.address, data: pzu.u8aToHex(message), type: 'bytes' });
|
||||
const { signature } = await waitFor(
|
||||
extension.signer.signRaw({ address: holder.address, data: pzu.u8aToHex(message), type: 'bytes' }),
|
||||
'Li benda îmzeyê ye: di cîzdanê de peyamê piştrast bike…');
|
||||
let sig = pzu.hexToU8a(signature);
|
||||
if (sig.length === 65 && sig[0] === 1) sig = sig.slice(1); // MultiSignature: 0x01 = sr25519
|
||||
const context = classify(holder.keyId, sig);
|
||||
@@ -250,6 +268,8 @@
|
||||
$('signResult').textContent = e.message || String(e);
|
||||
$('signResult').className = 'note bad';
|
||||
show('signResult');
|
||||
} finally {
|
||||
$('signButton').disabled = false;
|
||||
}
|
||||
};
|
||||
} catch (e) {
|
||||
|
||||
Reference in new issue
Block a user