@ninsei-labs/sdk 0.57.2 → 0.58.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/README.md +64 -27
- package/THIRD_PARTY_NOTICES.md +2 -2
- package/assets/vendors/MANIFEST.json +1 -9
- package/assets/vendors/sdk/sdk-browser.js +4 -4
- package/engine/core/config.js +3 -22
- package/engine/core/rfqSource.js +6 -133
- package/engine/core/swap.js +1 -1
- package/engine/evm/index.js +3 -2
- package/engine/evm/session.js +46 -277
- package/engine/monero/address.js +15 -33
- package/engine/monero/keys.js +124 -0
- package/engine/monero/mnemonic.js +104 -0
- package/engine/monero/scan.js +23 -9
- package/engine/monero/wallet.js +31 -68
- package/engine/monero/wordlist.en.js +210 -0
- package/engine/recovery/restore.js +1 -1
- package/engine/sdk/bridge.js +7 -182
- package/engine/ui/walletModal.js +7 -27
- package/index.d.ts +187 -252
- package/package.json +4 -5
- package/src/codes.mjs +12 -0
- package/src/config.mjs +16 -54
- package/src/engine.mjs +3 -0
- package/src/index.mjs +24 -45
- package/src/order.mjs +2 -2
- package/src/public/recovery.d.ts +17 -1
- package/src/public/recovery.mjs +1 -0
- package/src/quotePolicy.mjs +25 -0
- package/src/quotes.mjs +21 -751
- package/src/readyWindow.mjs +76 -0
- package/src/recovery-key.mjs +39 -2
- package/src/recovery.mjs +11 -28
- package/src/relayClaim.mjs +132 -0
- package/src/relayFirmClient.mjs +3 -0
- package/src/relayQuote.mjs +5 -1
- package/src/swap-flow.mjs +49 -5
- package/src/swaps.mjs +301 -307
- package/src/sweep-action.mjs +73 -0
- package/src/sweep.mjs +7 -1
- package/src/version.mjs +1 -1
- package/src/xmr-arrival.mjs +275 -7
- package/src/xmrAmountPolicy.mjs +35 -0
- package/assets/vendors/monero/monero-js-browser.js +0 -58
- package/assets/vendors/monero-js/LICENSE +0 -9
- package/assets/vendors/walletconnect/wc-browser.js +0 -6202
package/engine/sdk/bridge.js
CHANGED
|
@@ -11,8 +11,6 @@
|
|
|
11
11
|
//
|
|
12
12
|
// WHAT THE SHIM PASSES TO THE CORE - exactly the seams the core asks for from outside and cannot get itself:
|
|
13
13
|
// storage - the page's storage: deals and session are read from where the page puts them (core/store.js);
|
|
14
|
-
// serverAuth - a pass to our service: only the wallet can sign the sign-in message (evm/auth.js signIn),
|
|
15
|
-
// so the core gets the pass READY-MADE;
|
|
16
14
|
// evmCall - chain reads WITH THE PAGE'S WALLET: the core has no provider of its own and must not;
|
|
17
15
|
// wallet - the page wallet adapter (sdk/src/adapters/evm-wallet.mjs): signing happens only in it.
|
|
18
16
|
//
|
|
@@ -38,7 +36,6 @@
|
|
|
38
36
|
|
|
39
37
|
import { chainById, DEFAULT_CHAIN, MONERO, allowedProvidersFor, knownFactoryCodesFor, knownImplementationCodesFor } from "../core/config.js";
|
|
40
38
|
import { storage as pageStorage } from "../core/store.js";
|
|
41
|
-
import { token as authToken, signIn } from "../evm/auth.js";
|
|
42
39
|
import * as evm from "../evm/index.js";
|
|
43
40
|
// ORDER TERMS FOR THE CORE ARE ASSEMBLED FROM DATA, NOT FROM RULES: the windows come from the finality policy
|
|
44
41
|
// (core/finality.js), the salt from the engine's generator (evm/funding.js). No deadlines or numbers of its own here.
|
|
@@ -48,9 +45,8 @@ import { newSecret } from "../evm/funding.js";
|
|
|
48
45
|
// exposes EXACTLY the same names (markReadyOrder/claimOrder/refundOrder/orderStatus/orderDeadlines), so a screen
|
|
49
46
|
// changes only the import source, not the call expression - and the guard that fixes the call site sees the old call.
|
|
50
47
|
//
|
|
51
|
-
// THE DEAL LIST AND ITS UPKEEP (the #/swaps screen). States come from the CORE: swaps.list - display, swaps.
|
|
52
|
-
//
|
|
53
|
-
// (the pass and the storage), and both are already passed above - the shim adds no rules of its own.
|
|
48
|
+
// THE DEAL LIST AND ITS UPKEEP (the #/swaps screen). States come from the CORE: swaps.list - display, swaps.forget -
|
|
49
|
+
// dropping a record. The core needs only the page's storage, and the shim adds no rules of its own.
|
|
54
50
|
//
|
|
55
51
|
// WATCHING IS A PAGE MECHANISM, NOT THE CORE'S: the poll tick lives in app.js, so the focus stays in
|
|
56
52
|
// core/swap.js and the screen only declares it to the shim.
|
|
@@ -70,7 +66,7 @@ import { height as nodeHeightValue } from "../monero/node.js";
|
|
|
70
66
|
// published `engine/` tree and in the page that serves this shim from `www/js/sdk/`; ?v=<hash> keeps the cache fresh.
|
|
71
67
|
const SDK_BUNDLE = new URL("../../assets/vendors/sdk/sdk-browser.js?v=fa7dc71a", import.meta.url).href;
|
|
72
68
|
|
|
73
|
-
// A NAMED SEAM FOR CHECKS
|
|
69
|
+
// A NAMED SEAM FOR CHECKS. The asynchronous path is driven against a
|
|
74
70
|
// stand-in order book (the demo network has no provider), and the ordinary escrow funding that follows a settled
|
|
75
71
|
// swap can be replaced while that runs, because deploying an escrow factory on a throwaway chain is the stand's
|
|
76
72
|
// job, not a check's. The replacement is named, set only by a check, and unset by the same function; production
|
|
@@ -127,12 +123,6 @@ function optionsFor(chain) {
|
|
|
127
123
|
mode: modeOf(chain),
|
|
128
124
|
// THE PAGE STORAGE BECOMES THE CORE STORAGE: deal records and the session live in one place.
|
|
129
125
|
storage: pageStorage(),
|
|
130
|
-
// A PASS TO OUR SERVICE: the core only presents it; the page wallet obtains it.
|
|
131
|
-
serverAuth: async () => {
|
|
132
|
-
if (authToken()) return authToken();
|
|
133
|
-
try { await signIn(); } catch { return null; }
|
|
134
|
-
return authToken();
|
|
135
|
-
},
|
|
136
126
|
// CHAIN READS - WITH THE PAGE'S WALLET (the core needs this seam: it has no provider of its own).
|
|
137
127
|
evmCall: (request) => evm.readContract(request),
|
|
138
128
|
// CONTRACT CODE - WITH THE PAGE'S WALLET: needed by the factory-code check, extcodehash is computed from it.
|
|
@@ -238,142 +228,6 @@ export async function sdkOpenRecovery(file, passphrase) {
|
|
|
238
228
|
// The core is served to the page as a bundle, so these calls go through the REAL facade. They answer null only
|
|
239
229
|
// if the bundle itself did not load - and then the cause is named in the console, not hidden.
|
|
240
230
|
|
|
241
|
-
export async function sdkWatchQuotes(request, onSnapshot) {
|
|
242
|
-
const ctx = await instanceFor(request && request.chain);
|
|
243
|
-
if (!ctx) return null;
|
|
244
|
-
return ctx.sdk.quotes.watch(request, onSnapshot);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
export async function sdkQuotesSnapshot(chainSlug) {
|
|
248
|
-
const ctx = await instanceFor(chainSlug);
|
|
249
|
-
return ctx ? ctx.sdk.quotes.snapshot() : null;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
// --- THE INDICATIVE QUOTE BOOK ON THE CORE ---------------------------------------------------------
|
|
253
|
-
// THE BOOK (offers and refusals) COMES FROM THE CORE: quotes.watch subscribes to the core poll, quotes.snapshot
|
|
254
|
-
// returns the last snapshot without waiting. The shim does exactly ONE job here - TRANSLATION OF SHAPE: the core
|
|
255
|
-
// snapshot's field names are mapped to those the screen already draws. There is no selection or priority rule
|
|
256
|
-
// here: offer, refusal or best is decided by the core (sdk/src/quotes.mjs, readBook). The core is silent or
|
|
257
|
-
// refused - the book is empty, and the former (engine) book is not substituted: it no longer exists.
|
|
258
|
-
//
|
|
259
|
-
// SUBSCRIPTION IS ONE. The core polls for the duration of the subscription; a second listener would be a second
|
|
260
|
-
// poll, so the previous subscription is removed BEFORE the new one. The last snapshot survives re-subscription:
|
|
261
|
-
// the reader sees the previous book until a fresh one arrives - not emptiness on every tick.
|
|
262
|
-
let bookStop = null; // unsubscribe from the core's current subscription
|
|
263
|
-
let bookKey = null; // which request (network|side|token|size) this subscription is for
|
|
264
|
-
let bookCore = null; // the last CORE snapshot (not the translation): the translation is done on read
|
|
265
|
-
let bookResume = null; // waiting for the first tick after subscribing
|
|
266
|
-
// A SEAM HOOK (sdkBookUse): a core quote surface brought from outside. Needed by checks that run WITHOUT a
|
|
267
|
-
// browser: the core itself is not in the bundle there, and the book must be checked. Not set in production.
|
|
268
|
-
let bookQuotes = null;
|
|
269
|
-
|
|
270
|
-
// THE CORE FOR CHECKS WITHOUT A BROWSER: put in a quote surface (watch/snapshot) and work with it.
|
|
271
|
-
export function sdkBookUse(quotesApi) {
|
|
272
|
-
bookQuotes = quotesApi || null;
|
|
273
|
-
bookCore = null;
|
|
274
|
-
bookKey = null;
|
|
275
|
-
bookResume = null;
|
|
276
|
-
if (bookStop) { try { bookStop(); } catch { /* already removed */ } }
|
|
277
|
-
bookStop = null;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
// TRANSLATING A CORE ROW INTO A SCREEN ROW. Names only: values are carried as is. The age is computed
|
|
281
|
-
// HERE (from the quote's own timestamp): the core computed it on its own tick, while display asks for freshness
|
|
282
|
-
// now - otherwise the quote's lifetime would be rejuvenated by a poll tick.
|
|
283
|
-
function bookRow(o) {
|
|
284
|
-
const at = Number.isFinite(Number(o.at)) ? Number(o.at) : null;
|
|
285
|
-
return {
|
|
286
|
-
providerId: o.providerId, displayName: o.displayName, pair: o.pair,
|
|
287
|
-
asset: o.asset, currency: o.currency,
|
|
288
|
-
assetNetwork: o.assetNetwork, currencyNetwork: o.currencyNetwork, networkStated: o.networkStated === true,
|
|
289
|
-
rateQuote: o.rateQuote, rate: o.rate,
|
|
290
|
-
min: o.min, max: o.max, step: o.step, ttlMs: o.ttlMs,
|
|
291
|
-
at, ageMs: at === null ? null : Math.max(0, Date.now() - at),
|
|
292
|
-
seq: o.seq, why: o.why, signature: o.signature, keyId: o.keyId, finality: o.finality,
|
|
293
|
-
networksDerived: o.networksDerived === true, networksUnnamed: o.networksUnnamed === true,
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
// THE REFUSAL KIND WITH WHICH THE SCREEN NAMES THE CAUSE. The core code `disabled` is called `off` by the
|
|
298
|
-
// screen; other code names match, and there is no reason to rename them.
|
|
299
|
-
const REFUSAL_KIND = { disabled: "off" };
|
|
300
|
-
function bookRefusal(r) {
|
|
301
|
-
return { ...bookRow(r), code: r.code, kind: REFUSAL_KIND[r.code] || r.code, why: r.why };
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
// CORE SNAPSHOT -> SCREEN SNAPSHOT. The shape is the one the screen had: ok/error/data/at, and in data -
|
|
305
|
-
// references (the reference rate) and best. A connection failure does not turn into the former numbers: ok is
|
|
306
|
-
// dropped and the screen shows an honest state. Core silence (no snapshot) is also an empty book, not the former one.
|
|
307
|
-
function bookOf(core) {
|
|
308
|
-
if (!core) return { ok: false, error: null, data: null, at: 0, fetching: false };
|
|
309
|
-
const offers = (Array.isArray(core.offers) ? core.offers : []).map(bookRow);
|
|
310
|
-
const refused = (Array.isArray(core.refused) ? core.refused : []).map(bookRefusal);
|
|
311
|
-
const stamps = offers.map((o) => o.at).filter((v) => Number.isFinite(v));
|
|
312
|
-
return {
|
|
313
|
-
ok: !core.error,
|
|
314
|
-
error: core.error ? String(core.error.code || "unknown") : null,
|
|
315
|
-
at: core.at,
|
|
316
|
-
fetching: false,
|
|
317
|
-
data: {
|
|
318
|
-
offers, refused, quotes: offers,
|
|
319
|
-
// THE BEST, AS THE SERVICE NAMED IT: by it the screen confirms its "best" mark by pair and provider.
|
|
320
|
-
best: core.best || null,
|
|
321
|
-
seq: core.seq === undefined ? null : core.seq,
|
|
322
|
-
references: Array.isArray(core.references) ? core.references : [],
|
|
323
|
-
at: stamps.length ? Math.max(...stamps) : null,
|
|
324
|
-
},
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
// ASKING THE CORE FOR THE BOOK. The subscription is ONE and is replayed only when the REQUEST CHANGED: while
|
|
329
|
-
// size and side are the same, the core polls the book on its own tick and no second poll is created. When the
|
|
330
|
-
// request changed, the caller waits for the first tick and gets a FRESH snapshot, not a previous one. The core
|
|
331
|
-
// did not come up - empty (and the console names why).
|
|
332
|
-
export async function sdkBook({ chain, direction, token, size } = {}) {
|
|
333
|
-
let quotes = bookQuotes;
|
|
334
|
-
let instance = "injected"; // the hook (seam) has no network: its instance is one
|
|
335
|
-
if (!quotes) {
|
|
336
|
-
const ctx = await instanceFor(chain);
|
|
337
|
-
if (!ctx) {
|
|
338
|
-
if (bookStop) { try { bookStop(); } catch { /* already removed */ } bookStop = null; }
|
|
339
|
-
bookKey = null;
|
|
340
|
-
bookResume = null;
|
|
341
|
-
bookCore = null;
|
|
342
|
-
return null;
|
|
343
|
-
}
|
|
344
|
-
quotes = ctx.sdk.quotes;
|
|
345
|
-
instance = ctx.chain.id; // books of different networks must not be mixed: the network is part of the key
|
|
346
|
-
}
|
|
347
|
-
const dir = direction === "sell" ? "sell" : "buy";
|
|
348
|
-
const key = instance + "|" + dir + "|" + String(token || "") + "|" + String(size === undefined || size === null ? "" : size);
|
|
349
|
-
// THE SAME REQUEST - A POLL IS ALREADY RUNNING: return the last snapshot, do not create a second subscription.
|
|
350
|
-
// Otherwise every screen tick would reset the core state and briefly serve an empty book to a direct reader.
|
|
351
|
-
if (bookStop && bookKey === key) return bookCore;
|
|
352
|
-
if (bookStop) { try { bookStop(); } catch { /* already removed */ } bookStop = null; }
|
|
353
|
-
bookKey = key;
|
|
354
|
-
bookResume = null;
|
|
355
|
-
const wait = new Promise((resolve) => { bookResume = resolve; });
|
|
356
|
-
try {
|
|
357
|
-
bookStop = quotes.watch({ direction: dir, token, size }, (snap) => {
|
|
358
|
-
bookCore = snap;
|
|
359
|
-
if (bookResume) { const resume = bookResume; bookResume = null; resume(); }
|
|
360
|
-
});
|
|
361
|
-
} catch (error) {
|
|
362
|
-
bookResume = null;
|
|
363
|
-
bookCore = null;
|
|
364
|
-
console.warn("[bridge] the quote book was not served to the core (" + ((error && error.message) || error) +
|
|
365
|
-
"): there will be no offers; see www/js/sdk/bridge.js");
|
|
366
|
-
return null;
|
|
367
|
-
}
|
|
368
|
-
await wait;
|
|
369
|
-
return bookCore;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
// THE LAST SNAPSHOT WITHOUT WAITING - in the screen's shape. The core has not been polled once - empty (and that is honest).
|
|
373
|
-
export function sdkBookSnapshot() {
|
|
374
|
-
return bookOf(bookCore);
|
|
375
|
-
}
|
|
376
|
-
|
|
377
231
|
export async function sdkListSwaps(chainSlug) {
|
|
378
232
|
const ctx = await instanceFor(chainSlug);
|
|
379
233
|
return ctx ? ctx.sdk.swaps.list() : null;
|
|
@@ -414,21 +268,6 @@ export function sdkOrderTerms({ chain, amountWei, finality = null, salt = null,
|
|
|
414
268
|
};
|
|
415
269
|
}
|
|
416
270
|
|
|
417
|
-
// A FIRM QUOTE FOR THE ORDER - BEFORE SIGNING. The screen shows the fee rate and recipient BEFORE the person
|
|
418
|
-
// signs, and hands THE SAME quote to the swap start (sdkStartSwap, field orderQuote): exactly what is shown is
|
|
419
|
-
// signed, and no second request to the node is made.
|
|
420
|
-
//
|
|
421
|
-
// WHY THIS PLACE AND NOT THE SCREEN. The order terms (network, factory, depositor, amount, windows, salt) are
|
|
422
|
-
// assembled in ONE place - sdkOrderTerms; the screen must not assemble them in a second edition. Here they are
|
|
423
|
-
// assembled, a firm quote is requested by them through the core's path, and both go outward: `order` and `quote`.
|
|
424
|
-
export async function sdkOrderQuote({ chain, providerId, amountWei, finality = null, salt = null, asset = "XMR" } = {}) {
|
|
425
|
-
const ctx = await instanceFor(chain);
|
|
426
|
-
if (!ctx) return null;
|
|
427
|
-
const order = sdkOrderTerms({ chain: ctx.chain, amountWei, finality, salt, asset });
|
|
428
|
-
const quote = await ctx.sdk.quotes.firm({ providerId, order });
|
|
429
|
-
return { order, quote };
|
|
430
|
-
}
|
|
431
|
-
|
|
432
271
|
// STARTING THE SWAP WHOLE, BY THE CORE. Step order, the order side, deadlines into the contract, the escrow
|
|
433
272
|
// address FROM THE RECEIPT, our readiness mark and watching the XMR - all of it is held by the core
|
|
434
273
|
// (sdk/src/swaps.mjs, swaps.start). The screen passes only data: the quote, where to receive, the password, the
|
|
@@ -461,17 +300,8 @@ export async function sdkStartSwap(request) {
|
|
|
461
300
|
req.order = sdkOrderTerms({ chain: ctx.chain, amountWei: req.amountWei, finality: req.finality,
|
|
462
301
|
salt: req.salt, asset: req.receiveAsset });
|
|
463
302
|
}
|
|
464
|
-
//
|
|
465
|
-
//
|
|
466
|
-
// saw is signed. If it did not, we request it here through the core's path (config.route("orderQuote")).
|
|
467
|
-
//
|
|
468
|
-
// WHY THIS SEPARATE FIELD. The lock takes the quote NOT from req.quote: req.quote is the book's indicative
|
|
469
|
-
// quote for the guards (freshness, deadlines), while the factory needs a SIGNED SET (fee, registry, provider).
|
|
470
|
-
// The core reads it as `request.orderQuote` (sdk/src/swaps.mjs). While the bridge did not put it there, the
|
|
471
|
-
// start reached the deposit and failed there: "a signed quote is required: the factory takes a quote, not bare order terms".
|
|
472
|
-
if (!req.orderQuote && req.providerId) {
|
|
473
|
-
req.orderQuote = await ctx.sdk.quotes.firm({ providerId: req.providerId, order: req.order });
|
|
474
|
-
}
|
|
303
|
+
// THE SIGNED QUOTE COMES FROM THE RELAY PATH AND IS PASSED IN. There is no direct node call to fetch one here:
|
|
304
|
+
// a start without `orderQuote` reaches the lock without a signed set and the core refuses it.
|
|
475
305
|
if (req.orderQuote) {
|
|
476
306
|
// THE CLAIMER IS NAMED BY THE PROVIDER, and enters the order context: without it the proof would not agree
|
|
477
307
|
// (the core refuses - context mismatch). Here we only carry its value into the terms.
|
|
@@ -502,14 +332,9 @@ export async function sdkWatchSwap(request) {
|
|
|
502
332
|
|
|
503
333
|
// --- THE DEAL LIST FROM THE CORE (the #/swaps screen) ---------------------------------------------
|
|
504
334
|
// READING, MERGING AND DROPPING GO THROUGH THE CORE, NOT THE ENGINE ON THE PAGE. sdkListSwaps above returns
|
|
505
|
-
// deal states (swaps.list)
|
|
506
|
-
//
|
|
335
|
+
// deal states (swaps.list) and record dropping (swaps.forget: it removes the record only here; the server and
|
|
336
|
+
// the contract keep everything).
|
|
507
337
|
// The core did not come up - null, and the console names the cause (see sdkBundle), not silence.
|
|
508
|
-
export async function sdkSyncSwaps(chainSlug) {
|
|
509
|
-
const ctx = await instanceFor(chainSlug);
|
|
510
|
-
return ctx ? ctx.sdk.swaps.sync() : null;
|
|
511
|
-
}
|
|
512
|
-
|
|
513
338
|
export async function sdkForgetSwap(id, chainSlug) {
|
|
514
339
|
const ctx = await instanceFor(chainSlug);
|
|
515
340
|
return ctx ? ctx.sdk.swaps.forget(id) : null;
|
package/engine/ui/walletModal.js
CHANGED
|
@@ -2,14 +2,12 @@
|
|
|
2
2
|
// Edit the source under www/js and regenerate the mirror; a drift guard reddens on any difference.
|
|
3
3
|
// Everything below this header is identical to the source.
|
|
4
4
|
|
|
5
|
-
// A wallet-connect modal: browser-wallet choice
|
|
5
|
+
// A wallet-connect modal for the injected connector: browser-wallet choice only.
|
|
6
6
|
// The browser-wallet list comes from outside (setChoices); detection is evm/injected.js by EIP-6963. Here is
|
|
7
7
|
// only rendering: the CSP bans inline styles, so everything goes through dom.h(), and wallet icons are data: URLs.
|
|
8
|
-
//
|
|
9
|
-
// CSP, and we did not weaken it for a modal. So we draw the modal ourselves and the QR with a qrcode generator as a data: URL.
|
|
10
|
-
// No secrets here: the QR holds the public WalletConnect session URI (wc:...), safe to show like any dapp.
|
|
8
|
+
// The host owns any WalletConnect or QR UI.
|
|
11
9
|
|
|
12
|
-
import { h
|
|
10
|
+
import { h } from "./dom.js";
|
|
13
11
|
|
|
14
12
|
export function openWalletModal({ title = "Connect a wallet", subtitle = "", hint = "" } = {}) {
|
|
15
13
|
const refs = {};
|
|
@@ -23,11 +21,8 @@ export function openWalletModal({ title = "Connect a wallet", subtitle = "", hin
|
|
|
23
21
|
(refs.subtitle = h("div", { class: "ar-modal-sub", text: subtitle })),
|
|
24
22
|
// The browser-wallet list: empty until detection delivers it (then invisible).
|
|
25
23
|
(refs.choices = h("div", { class: "ar-modal-choices" })),
|
|
26
|
-
(refs.qrBox = h("div", { class: "ar-modal-qr", hidden: true }, [(refs.qr = h("img", { alt: "WalletConnect QR code" }))])),
|
|
27
|
-
(refs.uri = h("code", { class: "ar-modal-uri" })),
|
|
28
24
|
(refs.status = h("div", { class: "ar-modal-status" })),
|
|
29
25
|
h("div", { class: "ar-modal-actions" }, [
|
|
30
|
-
(refs.copyBtn = h("button", { class: "ar-btn-ghost", type: "button", text: "Copy link" })),
|
|
31
26
|
(refs.cancelBtn = h("button", { class: "ar-btn-ghost", type: "button", text: "Cancel" })),
|
|
32
27
|
]),
|
|
33
28
|
(refs.hint = h("div", { class: "ar-modal-hint", text: hint })),
|
|
@@ -39,10 +34,6 @@ export function openWalletModal({ title = "Connect a wallet", subtitle = "", hin
|
|
|
39
34
|
const closed = { value: false };
|
|
40
35
|
let onCancel = null;
|
|
41
36
|
|
|
42
|
-
// TWO DIFFERENT EXITS FROM THE MODAL, and the difference is fundamental: close() closes it programmatically
|
|
43
|
-
// (e.g. the session settled), while cancel() is the user refusing - and THAT is when we must kill the session
|
|
44
|
-
// we asked for. They must not be confused: before, a successful connect closed the modal, which fired the
|
|
45
|
-
// cancel handler and deleted the just-created session.
|
|
46
37
|
function close() {
|
|
47
38
|
if (closed.value) return;
|
|
48
39
|
closed.value = true;
|
|
@@ -57,16 +48,13 @@ export function openWalletModal({ title = "Connect a wallet", subtitle = "", hin
|
|
|
57
48
|
|
|
58
49
|
refs.closeBtn.addEventListener("click", cancel);
|
|
59
50
|
refs.cancelBtn.addEventListener("click", cancel);
|
|
60
|
-
refs.copyBtn.addEventListener("click", () => {
|
|
61
|
-
if (refs.uri.textContent) copy(refs.uri.textContent, "WalletConnect link copied");
|
|
62
|
-
});
|
|
63
51
|
overlay.addEventListener("click", (e) => {
|
|
64
52
|
if (e.target === overlay) cancel();
|
|
65
53
|
});
|
|
66
54
|
|
|
67
|
-
// setChoices([{ key, name, icon, hint, onClick }]) - the browser-wallet list
|
|
68
|
-
//
|
|
69
|
-
//
|
|
55
|
+
// setChoices([{ key, name, icon, hint, onClick }]) - the browser-wallet list. Icons are data: URLs only
|
|
56
|
+
// (the wallet itself provides them): external addresses are not allowed by the demo CSP, and rightly so -
|
|
57
|
+
// a network image must not influence which wallet is chosen.
|
|
70
58
|
function setChoices(list) {
|
|
71
59
|
refs.choices.innerHTML = "";
|
|
72
60
|
refs.choices.hidden = !list || !list.length;
|
|
@@ -80,8 +68,6 @@ export function openWalletModal({ title = "Connect a wallet", subtitle = "", hin
|
|
|
80
68
|
item.hint ? h("span", { class: "ar-modal-choice-hint", text: item.hint }) : null,
|
|
81
69
|
]),
|
|
82
70
|
]);
|
|
83
|
-
// The rest of the modal is closed by whoever handled the choice: a browser wallet shows its own window,
|
|
84
|
-
// while WalletConnect still needs the QR shown.
|
|
85
71
|
btn.addEventListener("click", () => {
|
|
86
72
|
if (closed.value) return;
|
|
87
73
|
item.onClick();
|
|
@@ -99,14 +85,8 @@ export function openWalletModal({ title = "Connect a wallet", subtitle = "", hin
|
|
|
99
85
|
setOnCancel(fn) {
|
|
100
86
|
onCancel = fn;
|
|
101
87
|
},
|
|
102
|
-
update({
|
|
88
|
+
update({ status, subtitle, hint: hintText, error } = {}) {
|
|
103
89
|
if (closed.value) return;
|
|
104
|
-
if (qrDataUrl) {
|
|
105
|
-
refs.qr.src = qrDataUrl;
|
|
106
|
-
// The frame is shown only when a QR actually exists: before WalletConnect is chosen this is empty.
|
|
107
|
-
refs.qrBox.hidden = false;
|
|
108
|
-
}
|
|
109
|
-
if (uri !== undefined) refs.uri.textContent = uri || "";
|
|
110
90
|
if (subtitle !== undefined) refs.subtitle.textContent = subtitle || "";
|
|
111
91
|
if (hintText !== undefined) refs.hint.textContent = hintText || "";
|
|
112
92
|
// error is more important than status: otherwise a generic "try again" overwrites the error text, and
|