Link the wallet that should receive your payouts. One free signature, no transaction. SafePal is the recommended wallet; MetaMask, Phantom and any WalletConnect wallet work too.
Own another wallet? Add it as a position, then pick it under Buy from and buy a package marked qualifies. Each position that buys counts as a qualifying buyer for you, its credits pool with yours, and you stay signed in as you.
'
+ + (list.length < max ? '
' + list.length + ' of ' + max + ' used
' : '
All ' + max + ' positions are linked.
')
+ + '
';
+ }
+ // pick a different account in the wallet (MetaMask's account picker; a fresh session for WalletConnect) and say what it is
+ async function switchAccount() {
+ const a = String(await IAPWallet.pickAccount() || '').toLowerCase(); if (!a) return;
+ const i = posList().findIndex(x => String(x.address).toLowerCase() === a);
+ if (ME && a === String(ME.address || '').toLowerCase()) { FROM = 'main'; CR.toast('Connected as ' + short(a) + ', your main wallet.'); }
+ else if (i >= 0) { FROM = a; CR.toast('Connected as ' + short(a) + ', position ' + (i + 2) + '. It is selected under Buy from.'); }
+ else CR.toast('Connected as ' + short(a) + '. That account is not on LinkSpin yet. To buy from it, use Add a position wallet.');
+ paintFrom(); paintQuote();
+ }
+ async function addPosition() {
+ const me = await CR.me(true);
+ if (!me.address) throw new Error('Link your main wallet first, then add positions under it.');
+ if (!me.memberId) throw new Error('Switch on payouts for your main wallet first. Positions register under your member number.');
+ const ok = await CR.dialog({ title: 'Add a position wallet', html: '
Your wallet asks which account to connect. Choose only the new account (not ' + esc(short(me.address)) + '), then sign once. No transaction, no cost.
No second account yet? MetaMask: account menu, Add account. SafePal or Trust: create or switch wallet. Phone with WalletConnect: pick the other wallet app in the list.
', ok: 'Ready', no: 'Cancel' });
+ if (!ok) return;
+ CR.toast('Pick the new account in your wallet, then sign once…');
+ const r = await IAPWallet.signIn({ asPosition: true, pick: true });
+ FROM = String(r.address || '').toLowerCase();
+ CR.toast('Position added: ' + short(r.address) + '. It is selected under Buy from. Pick a qualifying package and buy.');
+ await load();
}
function paintBuys(E) {
const buys = E && Array.isArray(E.purchases) ? E.purchases : [];
@@ -99,14 +149,21 @@
const p = sel(); if (!p || !p.costWei) return;
$('holdBox').hidden = true;
let me = await CR.me(true);
- if (!me.address) { CR.toast('Link your wallet first: one quick signature…'); await IAPWallet.signIn(); me = await CR.me(true); }
- const want = String(me.address || '').toLowerCase(); if (!want) throw new Error('No wallet linked.');
+ // which wallet buys: the main one, or a position picked under "Buy from" (it registers under the main member id
+ // on its first buy, so its sponsor is always this member)
+ const fp = fromPos(), row = fp ? posList().find(x => String(x.address).toLowerCase() === fp) : (POS && POS.main);
+ if (fp && !me.memberId) throw new Error('Switch on payouts for your main wallet first, so this position can register under you.');
+ if (fp && p.priceCents < 2000 && !(await CR.dialog({ title: 'This package does not qualify', text: 'A ' + usd(p.priceCents) + ' package from a position adds credits but does not count toward your qualification. Pick a package marked qualifies to count this position.', ok: 'Buy anyway', no: 'Pick another' }))) return;
+ if (row && row.noPayout) throw new Error('This ' + (fp ? 'position' : 'wallet') + ' is kept for linkage only. A purchase from it would pay a retired wallet. Buy from another one.');
+ if (!fp && !me.address) { CR.toast('Link your wallet first: one quick signature…'); await IAPWallet.signIn(); me = await CR.me(true); }
+ const want = fp || String(me.address || '').toLowerCase(); if (!want) throw new Error('No wallet linked.');
+ // never buy from a wallet other than the one chosen: a stray wallet would register a brand-new member
await IAPWallet.connect();
let cur = String(await IAPWallet.activeAddress() || '').toLowerCase();
- if (cur !== want) { CR.toast('Pick ' + want.slice(0, 6) + '…' + want.slice(-4) + ' in your wallet\'s account picker…'); cur = String(await IAPWallet.pickAccount() || '').toLowerCase(); }
- if (cur !== want) throw new Error('Your wallet connected as ' + cur.slice(0, 6) + '…' + cur.slice(-4) + ' but your linked wallet is ' + want.slice(0, 6) + '…' + want.slice(-4) + '. Switch accounts in the wallet app and try again.');
- const sp = await CR.get('/api/sponsor?intent=buy');
- if (!me.memberId && sp.sponsorBlocked) { $('holdBox').textContent = holdText(sp); $('holdBox').hidden = false; return; }
+ if (cur !== want) { CR.toast('Pick ' + short(want) + ' in your wallet\'s account picker…'); cur = String(await IAPWallet.pickAccount() || '').toLowerCase(); }
+ if (cur !== want) throw new Error('Your wallet connected as ' + short(cur) + ' but you are buying from ' + short(want) + '. Switch accounts in the wallet app (or change Buy from) and try again.');
+ const sp = fp ? { sponsorId: me.memberId } : await CR.get('/api/sponsor?intent=buy');
+ if (!fp && !me.memberId && sp.sponsorBlocked) { $('holdBox').textContent = holdText(sp); $('holdBox').hidden = false; return; }
try { // pre-flight: the POL has to be there; Trust Wallet refuses transactions that spend most of a balance
const need = BigInt(p.costWei) + BigInt(p.costWei) / 50n;
const bal = await IAPWallet.balance(want);
@@ -120,10 +177,11 @@
CR.toast('Confirm the purchase in your wallet…');
const r = await IAPWallet.buy(Number(p.id), sp.sponsorId || 0, p.costWei);
if (!r.receipt || r.receipt.status !== '0x1') throw new Error('Transaction reverted. Nothing was charged beyond gas.');
- CR.toast('Settled on-chain. Your credits are in Ads now.');
+ CR.toast(fp ? 'Settled on-chain. That position now counts toward your qualification, and its credits pool with yours.' : 'Settled on-chain. Your credits are in Ads now.');
await load();
}
$('buyBtn').addEventListener('click', () => guard($('buyBtn'), buy));
+ $('buyFrom').addEventListener('change', () => { FROM = $('buyFrom').value || 'main'; paintFrom(); paintQuote(); });
$('cardBtn').addEventListener('click', () => guard($('cardBtn'), async () => {
const p = sel(); const need = p && p.costWei ? Math.max(10, Math.ceil(Number(BigInt(p.costWei) / 1000000000000000000n)) + 3) : 30;
const q = '/api/moonpay-url?pol=' + need + (ME && ME.address ? '&address=' + encodeURIComponent(ME.address) : '');
@@ -135,9 +193,10 @@
try { [CFG, ME] = await Promise.all([CR.get('/api/config'), CR.me(true)]); } catch (e) { CR.sub('could not load'); return; }
let cat = null, E = null;
try { [cat, CAMP, DASH, E] = await Promise.all([CR.get('/api/catalog'), CR.get('/api/my/campaigns'), CR.get('/api/my/dashboard'), CR.get('/api/my/activity')]); } catch (e) {}
+ try { POS = ME.address ? await CR.get('/api/my/positions') : null; } catch (e) { POS = null; }
CAT = (cat && cat.products) || [];
CR.sub((CAMP ? fmt(CAMP.availableCredits) + ' free to spend · ' + fmt(CAMP.inCampaigns) + ' in live ads' : '') + (CAT[0] && CAT[0].costWei ? '' : ' · price feed catching up'));
- paintTiles(); paintPkgs(); paintQuote(); paintGoes(); paintWallet(); paintBuys(E);
+ paintTiles(); paintPkgs(); paintFrom(); paintQuote(); paintGoes(); paintWallet(); paintBuys(E);
const spName = ME.sponsorName ? ('@' + String(ME.sponsorName).replace(/^@/, '')) : null;
$('sponsorLine').innerHTML = spName
? 'Your sponsor ' + esc(spName) + ' is placed on the contract. The moment you confirm, half of the package lands in their wallet and the rest splits as shown. Credits appear in Ads right away.'
diff --git a/public/assets/wallet-screen.js b/public/assets/wallet-screen.js
index 8087778..e53195a 100644
--- a/public/assets/wallet-screen.js
+++ b/public/assets/wallet-screen.js
@@ -19,7 +19,7 @@
$('payFoot').textContent = 'every line is a Polygon transaction · nothing is held by the site';
const rows = Array.isArray(POS) ? POS : (POS && (POS.positions || POS.list)) || [];
$('posRows').innerHTML = rows.length ? rows.map(p => '
' + (addr ? 'Main wallet only. Own another wallet? Add it as a position on Credits and buy from it to self-qualify.' : 'No positions yet.') + '
';
}
CR.requireSession(load);
})();
diff --git a/public/assets/wallet.js b/public/assets/wallet.js
index 13f4a1f..b2b4c18 100644
--- a/public/assets/wallet.js
+++ b/public/assets/wallet.js
@@ -113,13 +113,19 @@ window.IAPWallet = (function () {
try {
await inj.request({ method: 'wallet_requestPermissions', params: [{ eth_accounts: {} }] });
const accs = await inj.request({ method: 'eth_accounts' });
- if (accs && accs[0]) { provider = inj; await ensureChain(c).catch(() => {}); return accs[0]; }
+ if (accs && accs[0]) { provider = inj; clearPick(); await ensureChain(c).catch(() => {}); return accs[0]; }
} catch (e) {
- if (e && (e.code === 4001 || /reject|denied/i.test(String(e.message || '')))) throw new Error('You closed the account picker. Pick the account you want and try again.');
+ // closed the picker right after a Disconnect: they may want a different wallet app, so offer the full wallet list
+ if (e && (e.code === 4001 || /reject|denied/i.test(String(e.message || ''))) && !pickPending()) throw new Error('You closed the account picker. Pick the account you want and try again.');
}
}
- return freshConnect(c);
+ const a = await freshConnect(c, 'Pick the wallet to connect…'); clearPick(); return a;
}
+ // After Disconnect the next connect is a fresh choice (testers 2026-10-18: Disconnect, then the site snapped straight
+ // back to the first MetaMask account, so a second wallet could never buy). The flag survives the reload some screens do.
+ const PICK_KEY = 'ls.wallet.pick';
+ const pickPending = () => { try { return localStorage.getItem(PICK_KEY) === '1'; } catch (e) { return false; } };
+ function clearPick() { try { localStorage.removeItem(PICK_KEY); } catch (e) {} }
// A WalletConnect session can die underneath AppKit's cached "connected"
// state: the wallet app rejects or kills it (Trust does this after its own
@@ -128,9 +134,9 @@ window.IAPWallet = (function () {
// Detect that, wipe the stale session, and re-open the picker for a fresh one.
const DEAD_RE = /disconnect|not connected|no matching key|session (topic|expired|deleted|not found)|call connect|please call connect|missing or invalid|relay/i;
const isDead = e => DEAD_RE.test(String((e && e.message) || e || ''));
- async function freshConnect(c) {
- try { IAP.status('Your wallet session dropped. Reconnect in the picker…'); } catch (e) {}
- await disconnect();
+ async function freshConnect(c, msg) {
+ try { IAP.status(msg || 'Your wallet session dropped. Reconnect in the picker…'); } catch (e) {}
+ await dropSession();
try { await modal.open(); } catch (e) {}
const addr = await waitForConnection(180000);
try { if (modal && modal.close) await modal.close(); } catch (e) {}
@@ -142,6 +148,9 @@ window.IAPWallet = (function () {
async function connect() {
const c = await IAP.getConfig();
await initAppKit(c);
+ if (pickPending()) return pickAccount(); // the member pressed Disconnect: open the account picker, never the old session
+ // an injected account chosen through pickAccount() is driven directly; AppKit may still hold (or lack) another one
+ if (provider && provider === window.ethereum) { try { const a = await provider.request({ method: 'eth_accounts' }); if (a && a[0]) return a[0]; } catch (e) {} }
let addr = currentAddress();
if (!addr) {
// give AppKit a moment to rehydrate an existing session before popping the
@@ -269,12 +278,24 @@ window.IAPWallet = (function () {
return { hash, receipt: await waitTx(hash) };
}
- async function disconnect() {
+ // end the wallet session (a dead WalletConnect session, or the first half of a user Disconnect)
+ async function dropSession() {
// AppKit's disconnect can hang on the WalletConnect relay (esp. mobile) —
// never block on it, so the UI can't get stuck "disconnecting".
try { if (modal && modal.disconnect) await Promise.race([modal.disconnect(), new Promise(r => setTimeout(r, 1200))]); } catch (e) {}
provider = null;
- try { Object.keys(localStorage).forEach(k => { if (/wc@2|walletconnect|w3m|wcm|reown|wagmi|appkit/i.test(k)) localStorage.removeItem(k); }); } catch (e) {}
+ // keep wagmi/AppKit's own "user disconnected" markers: wiping them made the next page load auto-reconnect the
+ // injected wallet (MetaMask still trusts the site), the snap-back testers hit on 2026-10-18
+ try { Object.keys(localStorage).forEach(k => { if (/wc@2|walletconnect|w3m|wcm|reown|wagmi|appkit/i.test(k) && !/disconnected|connection_status/i.test(k)) localStorage.removeItem(k); }); } catch (e) {}
+ }
+ // the member's Disconnect: let go for real, so the next connect can be a different account or wallet.
+ // MetaMask keeps the site's permission across a plain disconnect; wallet_revokePermissions drops it
+ // (wallets without it just ignore the call), and the pick flag makes the next connect open the picker.
+ async function disconnect() {
+ try { localStorage.setItem(PICK_KEY, '1'); } catch (e) {}
+ const inj = window.ethereum;
+ if (inj && inj.request) { try { await Promise.race([inj.request({ method: 'wallet_revokePermissions', params: [{ eth_accounts: {} }] }), new Promise(r => setTimeout(r, 1000))]); } catch (e) {} }
+ await dropSession();
}
// native balance of the connected wallet (pre-flight check before a buy)
diff --git a/public/credits.html b/public/credits.html
index 04f52d9..28a99e7 100644
--- a/public/credits.html
+++ b/public/credits.html
@@ -6,7 +6,7 @@
Credits · LinkSpin
-
+
@@ -41,6 +42,7 @@
you pay·