Positions: force the wallet's account picker (wallet_requestPermissions) when adding a position or when the Buy-from wallet doesn't match; sign/send with the wallet's active account

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-09-10 06:11:38 -05:00
parent 70b96bf862
commit 15a881a72b
3 changed files with 39 additions and 13 deletions
+7 -8
View File
@@ -1249,10 +1249,9 @@
const me = await (await fetch('/api/me')).json();
if (!me.address) throw new Error('Link your main wallet first (Wallet tab), then add positions under it.');
if (!me.memberId) throw new Error('Switch on payouts for your main wallet first (Wallet tab). Positions register under your member number.');
if (!confirm('In your wallet app, switch to a DIFFERENT account than ' + short(me.address) + ' first (MetaMask: account menu, Add account. Trust or SafePal: switch wallet). The wallet picker will open again so you can connect that account.\n\nReady?')) return;
await IAPWallet.disconnect();
IAP.status('Connect the new account in the picker, then sign once…');
const r = await IAPWallet.signIn({ asPosition: true });
if (!confirm('Your wallet will ask which account to connect. Tick ONLY the new account (not ' + short(me.address) + '), then sign once.\n\nIf you have not created the extra account yet: MetaMask, account menu, Add account. Trust or SafePal: switch wallet.\n\nReady?')) return;
IAP.status('Pick the new account in your wallet, then sign once…');
const r = await IAPWallet.signIn({ asPosition: true, pick: true });
$('qsHint').textContent = 'Added ' + short(r.address) + '. Now choose it under "Buy from" and buy a $20 or larger package.';
IAP.status('Position added: ' + short(r.address) + '. Pick it under "Buy from" above and buy a $20+ package to count it.', 'ok');
await loadPositions();
@@ -1299,11 +1298,11 @@
}
const wantAddr = fromPos || (meNow.address ? meNow.address.toLowerCase() : null);
if (wantAddr) { // never buy from a wallet other than the one selected: a stray wallet would register a brand-new member
let cur = (IAPWallet.address() || await IAPWallet.connect() || '').toLowerCase();
await IAPWallet.connect();
let cur = String(await IAPWallet.activeAddress() || '').toLowerCase();
if (cur !== wantAddr) {
IAP.status('Switch your wallet app to ' + wantAddr.slice(0, 6) + '…' + wantAddr.slice(-4) + ', then pick it in the picker…');
await IAPWallet.disconnect();
cur = String(await IAPWallet.connect() || '').toLowerCase();
IAP.status('Pick ' + wantAddr.slice(0, 6) + '…' + wantAddr.slice(-4) + ' in your wallet\'s account picker…');
cur = String(await IAPWallet.pickAccount() || '').toLowerCase();
}
if (cur !== wantAddr) throw new Error('Your wallet connected as ' + cur.slice(0, 6) + '…' + cur.slice(-4) + ' but you chose ' + wantAddr.slice(0, 6) + '…' + wantAddr.slice(-4) + '. Switch accounts in your wallet app and try again.');
}