Payouts switch on automatically when a wallet is linked (wallet screen, wallet sign-in, InstantAdPay sync): engine activateFor, gas on us, sponsors first; quiet in-app notice, email held by the pre-launch gate
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+8
-2
@@ -440,10 +440,16 @@ async function downline(email, depth = 3) {
|
|||||||
}
|
}
|
||||||
return levels;
|
return levels;
|
||||||
}
|
}
|
||||||
|
// wallet-linked hook (Marty, 2026-10-17): the engine switches payouts on as soon as a wallet lands on an account, however
|
||||||
|
// it got there (wallet screen, wallet sign-in, InstantAdPay sync). Set by server.js; runs after the link, never blocks it.
|
||||||
|
let walletHook = null;
|
||||||
|
function onWalletLinked(f) { walletHook = f; }
|
||||||
async function linkWallet(email, address) {
|
async function linkWallet(email, address) {
|
||||||
const a = normAddr(address);
|
const a = normAddr(address);
|
||||||
if (!/^0x[0-9a-f]{40}$/.test(a)) return { error: 'Bad wallet address.' };
|
if (!/^0x[0-9a-f]{40}$/.test(a)) return { error: 'Bad wallet address.' };
|
||||||
return impl().linkWallet(normEmail(email), a).then(tap(normEmail(email)));
|
const r = await impl().linkWallet(normEmail(email), a).then(tap(normEmail(email)));
|
||||||
|
if (r && !r.error && walletHook) { try { Promise.resolve(walletHook(normEmail(email))).catch(e => console.error('wallet hook', e.message)); } catch (e) {} }
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
async function count() { return impl().count(); }
|
async function count() { return impl().count(); }
|
||||||
// admin: newest-first account list, and re-pointing a member's sponsor (a
|
// admin: newest-first account list, and re-pointing a member's sponsor (a
|
||||||
@@ -474,7 +480,7 @@ async function getChatSettings(email) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { init, signup, login, ensure, onChange, byEmail, byAddress, byCode, byUsername, byMemberId: id => impl().byMemberId(Number(id) || 0), listAll, setSponsorRef,
|
module.exports = { init, signup, login, ensure, onChange, byEmail, byAddress, byCode, byUsername, byMemberId: id => impl().byMemberId(Number(id) || 0), listAll, setSponsorRef,
|
||||||
setUsername, setMemberId, namesForMembers, listByReferrer, downline, linkWallet, count,
|
setUsername, setMemberId, namesForMembers, listByReferrer, downline, linkWallet, onWalletLinked, count,
|
||||||
setLineBanner: (e, b, t) => impl().setLineBanner(String(e || '').toLowerCase(), b, t),
|
setLineBanner: (e, b, t) => impl().setLineBanner(String(e || '').toLowerCase(), b, t),
|
||||||
setWallOffers: (e, j) => impl().setWallOffers(String(e || '').toLowerCase(), j),
|
setWallOffers: (e, j) => impl().setWallOffers(String(e || '').toLowerCase(), j),
|
||||||
setProfile: (e, a, bio, socials) => impl().setProfile(String(e || '').toLowerCase(), a, bio, socials).then(tap(String(e || '').toLowerCase())),
|
setProfile: (e, a, bio, socials) => impl().setProfile(String(e || '').toLowerCase(), a, bio, socials).then(tap(String(e || '').toLowerCase())),
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ async function nearestWithWallet(email) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// activate `acct` on this contract via the engine, after its own sponsor is there (recursive, bounded)
|
// activate `acct` on this contract via the engine, after its own sponsor is there (recursive, bounded)
|
||||||
async function ensureOnChain(acct, depth) {
|
async function ensureOnChain(acct, depth, why) {
|
||||||
if (!acct || !acct.address) return 0;
|
if (!acct || !acct.address) return 0;
|
||||||
try { const id = await X.chain.memberIdByAccount(acct.address); if (id) return id; } catch (e) {}
|
try { const id = await X.chain.memberIdByAccount(acct.address); if (id) return id; } catch (e) {}
|
||||||
if (!engineReady() || depth > 25) return 0;
|
if (!engineReady() || depth > 25) return 0;
|
||||||
@@ -151,12 +151,13 @@ async function ensureOnChain(acct, depth) {
|
|||||||
}
|
}
|
||||||
if (!id) { logEvent({ type: 'activateFailed', email: acct.email, error: String((lastErr && (lastErr.shortMessage || lastErr.message)) || 'not on-chain after send').slice(0, 160) }); return 0; }
|
if (!id) { logEvent({ type: 'activateFailed', email: acct.email, error: String((lastErr && (lastErr.shortMessage || lastErr.message)) || 'not on-chain after send').slice(0, 160) }); return 0; }
|
||||||
logEvent({ type: 'activated', email: acct.email, id, sponsorId, tx: txHash });
|
logEvent({ type: 'activated', email: acct.email, id, sponsorId, tx: txHash });
|
||||||
await noticeActivated(acct);
|
await noticeActivated(acct, why);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
async function noticeActivated(acct) {
|
async function noticeActivated(acct, why) {
|
||||||
await tell(acct.email, X.seeding ? 'Your LinkSpin payouts are switched on' : 'We set up your LinkSpin position so you would not miss a payout',
|
const own = X.seeding || why === 'wallet'; // switched on because their own wallet arrived, not because someone below them bought
|
||||||
(X.seeding ? 'Your wallet was already on file with the network, so we switched on your LinkSpin payouts for you, at no cost to you. Your position on the LinkSpin contract is active for your wallet ' + acct.address.slice(0, 6) + '…' + acct.address.slice(-4) + ', bound to your own sponsor, and your team is already placed under you. When anyone in your line buys a LinkSpin package, your share lands in this wallet in the same transaction, and you will be notified.'
|
await tell(acct.email, own ? 'Your LinkSpin payouts are switched on' : 'We set up your LinkSpin position so you would not miss a payout',
|
||||||
|
(own ? 'Your wallet was already on file with the network, so we switched on your LinkSpin payouts for you, at no cost to you. Your position on the LinkSpin contract is active for your wallet ' + acct.address.slice(0, 6) + '…' + acct.address.slice(-4) + ', bound to your own sponsor, and your team is already placed under you. When anyone in your line buys a LinkSpin package, your share lands in this wallet in the same transaction, and you will be notified.'
|
||||||
: 'Someone in your line was about to buy on LinkSpin, so the network activated your position on the LinkSpin contract for your wallet ' + acct.address.slice(0, 6) + '…' + acct.address.slice(-4) + ', bound to your own sponsor. Nothing was charged and nothing else was touched. Your share of that purchase lands in this wallet in the same transaction.')
|
: 'Someone in your line was about to buy on LinkSpin, so the network activated your position on the LinkSpin contract for your wallet ' + acct.address.slice(0, 6) + '…' + acct.address.slice(-4) + ', bound to your own sponsor. Nothing was charged and nothing else was touched. Your share of that purchase lands in this wallet in the same transaction.')
|
||||||
+ '\n\nSee your line: https://' + (X.host || 'linkspin.co') + '/my');
|
+ '\n\nSee your line: https://' + (X.host || 'linkspin.co') + '/my');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -457,6 +457,8 @@ async function boot() {
|
|||||||
pipeline.init({ dataDir: DATA_DIR, accounts, coach, chain });
|
pipeline.init({ dataDir: DATA_DIR, accounts, coach, chain });
|
||||||
registry.init({ dataDir: DATA_DIR });
|
registry.init({ dataDir: DATA_DIR });
|
||||||
carry.init({ dataDir: DATA_DIR, accounts, registry, chain, mailer, messages, siteConfig, adminEmail: ADMIN_EMAIL, host: SITE_HOST });
|
carry.init({ dataDir: DATA_DIR, accounts, registry, chain, mailer, messages, siteConfig, adminEmail: ADMIN_EMAIL, host: SITE_HOST });
|
||||||
|
// payouts on the moment a wallet is linked (Marty, 2026-10-17); the engine pays the gas, sponsors above are activated first
|
||||||
|
accounts.onWalletLinked(async email => { const a = await accounts.byEmail(email); if (a && a.address) await carry.ensureOnChain(a, 0, 'wallet'); });
|
||||||
// reverse registry sync (2026-10-15): account changes reach InstantAdPay within seconds; a 2-minute reconcile catches the rest
|
// reverse registry sync (2026-10-15): account changes reach InstantAdPay within seconds; a 2-minute reconcile catches the rest
|
||||||
iapsync.init({ dataDir: DATA_DIR, accounts, registry, host: SITE_HOST }); accounts.onChange(email => iapsync.touch(email));
|
iapsync.init({ dataDir: DATA_DIR, accounts, registry, host: SITE_HOST }); accounts.onChange(email => iapsync.touch(email));
|
||||||
setTimeout(() => iapsync.tick().catch(e => console.error('iapsync', e.message)), 2 * 60 * 1000);
|
setTimeout(() => iapsync.tick().catch(e => console.error('iapsync', e.message)), 2 * 60 * 1000);
|
||||||
|
|||||||
Reference in New Issue
Block a user