@swype-org/deposit 0.3.6 → 0.3.14
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/dist/{chunk-KDRGSQ2W.js → chunk-XYI3ZPQD.js} +456 -24
- package/dist/chunk-XYI3ZPQD.js.map +1 -0
- package/dist/index.cjs +458 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +159 -3
- package/dist/index.d.ts +159 -3
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +453 -21
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +2 -2
- package/dist/react.d.ts +2 -2
- package/dist/react.js +2 -2
- package/dist/{types-DJikyy3z.d.cts → types-DYsZwNXq.d.cts} +10 -5
- package/dist/{types-DJikyy3z.d.ts → types-DYsZwNXq.d.ts} +10 -5
- package/package.json +2 -2
- package/dist/chunk-KDRGSQ2W.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -41,24 +41,16 @@ function parseTransferComplete(data) {
|
|
|
41
41
|
if (typeof t.id !== "string" || typeof t.status !== "string") {
|
|
42
42
|
return null;
|
|
43
43
|
}
|
|
44
|
-
const transferType = parseTransferKind(t.type);
|
|
45
44
|
return {
|
|
46
45
|
type: "blink:transfer-complete",
|
|
47
46
|
transfer: {
|
|
48
47
|
id: t.id,
|
|
49
48
|
status: t.status,
|
|
50
|
-
...transferType != null ? { type: transferType } : {},
|
|
51
49
|
amount: parseAmount(t.amount),
|
|
52
50
|
destinations: parseDestinations(t.destinations)
|
|
53
51
|
}
|
|
54
52
|
};
|
|
55
53
|
}
|
|
56
|
-
function parseTransferKind(value) {
|
|
57
|
-
if (value === "guest" || value === "standard") {
|
|
58
|
-
return value;
|
|
59
|
-
}
|
|
60
|
-
return void 0;
|
|
61
|
-
}
|
|
62
54
|
function parseAmount(value) {
|
|
63
55
|
if (!value || typeof value !== "object") {
|
|
64
56
|
return void 0;
|
|
@@ -99,9 +91,401 @@ function parseCloseRequest(data) {
|
|
|
99
91
|
return { type: "blink:close-request" };
|
|
100
92
|
}
|
|
101
93
|
|
|
94
|
+
// src/walletBridge/discover.ts
|
|
95
|
+
function createWalletDiscoverer() {
|
|
96
|
+
if (typeof window === "undefined") {
|
|
97
|
+
return makeNoopHandle();
|
|
98
|
+
}
|
|
99
|
+
const registry = /* @__PURE__ */ new Map();
|
|
100
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
101
|
+
let destroyed = false;
|
|
102
|
+
const onAnnounce = (event) => {
|
|
103
|
+
if (destroyed) return;
|
|
104
|
+
const detail = event.detail;
|
|
105
|
+
if (!isValidProviderDetail(detail)) {
|
|
106
|
+
console.info("[blink-bridge:parent] dropping malformed EIP-6963 announcement", {
|
|
107
|
+
rawInfo: event.detail && event.detail.info
|
|
108
|
+
});
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const existing = registry.get(detail.info.uuid);
|
|
112
|
+
if (existing && existing.provider === detail.provider) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
console.info("[blink-bridge:parent] EIP-6963 announceProvider", {
|
|
116
|
+
rdns: detail.info.rdns,
|
|
117
|
+
name: detail.info.name,
|
|
118
|
+
uuid: detail.info.uuid
|
|
119
|
+
});
|
|
120
|
+
registry.set(detail.info.uuid, {
|
|
121
|
+
info: { ...detail.info },
|
|
122
|
+
provider: detail.provider
|
|
123
|
+
});
|
|
124
|
+
notify();
|
|
125
|
+
};
|
|
126
|
+
window.addEventListener("eip6963:announceProvider", onAnnounce);
|
|
127
|
+
requestProviders();
|
|
128
|
+
const RESWEEP_INTERVALS_MS = [500, 1500, 3e3, 6e3];
|
|
129
|
+
const reSweepTimers = [];
|
|
130
|
+
for (const ms of RESWEEP_INTERVALS_MS) {
|
|
131
|
+
reSweepTimers.push(
|
|
132
|
+
setTimeout(() => {
|
|
133
|
+
if (!destroyed) requestProviders();
|
|
134
|
+
}, ms)
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
function requestProviders() {
|
|
138
|
+
try {
|
|
139
|
+
window.dispatchEvent(new Event("eip6963:requestProvider"));
|
|
140
|
+
} catch {
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function notify() {
|
|
144
|
+
const snapshot = list();
|
|
145
|
+
for (const listener of listeners) {
|
|
146
|
+
try {
|
|
147
|
+
listener(snapshot);
|
|
148
|
+
} catch {
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
function list() {
|
|
153
|
+
return [...registry.values()];
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
list,
|
|
157
|
+
get(uuid) {
|
|
158
|
+
return registry.get(uuid)?.provider;
|
|
159
|
+
},
|
|
160
|
+
subscribe(listener) {
|
|
161
|
+
listeners.add(listener);
|
|
162
|
+
return () => {
|
|
163
|
+
listeners.delete(listener);
|
|
164
|
+
};
|
|
165
|
+
},
|
|
166
|
+
requestProviders,
|
|
167
|
+
destroy() {
|
|
168
|
+
if (destroyed) return;
|
|
169
|
+
destroyed = true;
|
|
170
|
+
window.removeEventListener("eip6963:announceProvider", onAnnounce);
|
|
171
|
+
for (const t of reSweepTimers) clearTimeout(t);
|
|
172
|
+
registry.clear();
|
|
173
|
+
listeners.clear();
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function makeNoopHandle() {
|
|
178
|
+
return {
|
|
179
|
+
list: () => [],
|
|
180
|
+
get: () => void 0,
|
|
181
|
+
subscribe: () => () => {
|
|
182
|
+
},
|
|
183
|
+
requestProviders: () => {
|
|
184
|
+
},
|
|
185
|
+
destroy: () => {
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
function isValidProviderDetail(value) {
|
|
190
|
+
if (!value || typeof value !== "object") return false;
|
|
191
|
+
const detail = value;
|
|
192
|
+
const info = detail.info;
|
|
193
|
+
const provider = detail.provider;
|
|
194
|
+
if (!info || !provider) return false;
|
|
195
|
+
if (typeof info.uuid !== "string" || info.uuid.length === 0) return false;
|
|
196
|
+
if (typeof info.name !== "string") return false;
|
|
197
|
+
if (typeof info.rdns !== "string") return false;
|
|
198
|
+
if (typeof provider.request !== "function") return false;
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// src/walletBridge/protocol.ts
|
|
203
|
+
var BRIDGE_PROTOCOL_VERSION = 1;
|
|
204
|
+
var ALLOWED_RPC_METHODS = /* @__PURE__ */ new Set([
|
|
205
|
+
// Read
|
|
206
|
+
"eth_accounts",
|
|
207
|
+
"eth_blockNumber",
|
|
208
|
+
"eth_call",
|
|
209
|
+
"eth_chainId",
|
|
210
|
+
"eth_estimateGas",
|
|
211
|
+
"eth_gasPrice",
|
|
212
|
+
"eth_getBalance",
|
|
213
|
+
"eth_getCode",
|
|
214
|
+
"eth_getStorageAt",
|
|
215
|
+
"eth_getTransactionByHash",
|
|
216
|
+
"eth_getTransactionCount",
|
|
217
|
+
"eth_getTransactionReceipt",
|
|
218
|
+
"net_version",
|
|
219
|
+
"wallet_getCapabilities",
|
|
220
|
+
"wallet_getCallsStatus",
|
|
221
|
+
// Write / sign
|
|
222
|
+
"eth_requestAccounts",
|
|
223
|
+
"eth_sendTransaction",
|
|
224
|
+
"eth_sendRawTransaction",
|
|
225
|
+
"eth_sign",
|
|
226
|
+
"personal_sign",
|
|
227
|
+
"eth_signTypedData",
|
|
228
|
+
"eth_signTypedData_v3",
|
|
229
|
+
"eth_signTypedData_v4",
|
|
230
|
+
"wallet_addEthereumChain",
|
|
231
|
+
"wallet_switchEthereumChain",
|
|
232
|
+
"wallet_sendCalls",
|
|
233
|
+
"wallet_watchAsset"
|
|
234
|
+
]);
|
|
235
|
+
var FORWARDED_PROVIDER_EVENTS = [
|
|
236
|
+
"accountsChanged",
|
|
237
|
+
"chainChanged",
|
|
238
|
+
"connect",
|
|
239
|
+
"disconnect",
|
|
240
|
+
"message"
|
|
241
|
+
];
|
|
242
|
+
function parseBridgeMessage(data) {
|
|
243
|
+
if (!data || typeof data !== "object") return null;
|
|
244
|
+
const msg = data;
|
|
245
|
+
if (msg.protocolVersion !== BRIDGE_PROTOCOL_VERSION) return null;
|
|
246
|
+
switch (msg.type) {
|
|
247
|
+
case "blink:bridge-hello":
|
|
248
|
+
return msg;
|
|
249
|
+
case "blink:wallets-advertised":
|
|
250
|
+
return Array.isArray(msg.wallets) ? msg : null;
|
|
251
|
+
case "blink:rpc-request":
|
|
252
|
+
if (typeof msg.uuid !== "string" || typeof msg.id !== "string" || typeof msg.method !== "string") {
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
return msg;
|
|
256
|
+
case "blink:rpc-response":
|
|
257
|
+
if (typeof msg.id !== "string") return null;
|
|
258
|
+
return msg;
|
|
259
|
+
case "blink:rpc-event":
|
|
260
|
+
if (typeof msg.uuid !== "string" || typeof msg.event !== "string" || !Array.isArray(msg.args)) {
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
return msg;
|
|
264
|
+
case "blink:resolve-by-flag":
|
|
265
|
+
if (typeof msg.id !== "string" || !Array.isArray(msg.flags)) return null;
|
|
266
|
+
if (!msg.flags.every((f) => typeof f === "string" && f.length > 0)) return null;
|
|
267
|
+
return msg;
|
|
268
|
+
case "blink:resolve-by-flag-response":
|
|
269
|
+
if (typeof msg.id !== "string") return null;
|
|
270
|
+
if (msg.match !== null && (typeof msg.match !== "object" || !msg.match)) return null;
|
|
271
|
+
return msg;
|
|
272
|
+
default:
|
|
273
|
+
return null;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// src/walletBridge/rpcHost.ts
|
|
278
|
+
function attachRpcHost(options) {
|
|
279
|
+
const { iframeWindow, iframeOrigin, discoverer } = options;
|
|
280
|
+
const log = options.log ?? noopLog;
|
|
281
|
+
if (typeof window === "undefined") {
|
|
282
|
+
return { detach: () => {
|
|
283
|
+
} };
|
|
284
|
+
}
|
|
285
|
+
let detached = false;
|
|
286
|
+
const subscriptions = /* @__PURE__ */ new Map();
|
|
287
|
+
const unsubscribeFromDiscoverer = discoverer.subscribe((snapshot) => {
|
|
288
|
+
if (detached) return;
|
|
289
|
+
advertiseWallets(snapshot);
|
|
290
|
+
});
|
|
291
|
+
function postToIframe(message) {
|
|
292
|
+
if (detached) return;
|
|
293
|
+
try {
|
|
294
|
+
iframeWindow.postMessage(message, iframeOrigin);
|
|
295
|
+
} catch (err) {
|
|
296
|
+
log("postMessage to iframe failed", {
|
|
297
|
+
error: err instanceof Error ? err.message : String(err)
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
function advertiseWallets(snapshot) {
|
|
302
|
+
const wallets = snapshot.map((entry) => ({
|
|
303
|
+
uuid: entry.info.uuid,
|
|
304
|
+
rdns: entry.info.rdns,
|
|
305
|
+
name: entry.info.name,
|
|
306
|
+
icon: entry.info.icon
|
|
307
|
+
}));
|
|
308
|
+
console.info("[blink-bridge:parent] advertising wallets", wallets.map((w) => ({
|
|
309
|
+
rdns: w.rdns,
|
|
310
|
+
name: w.name
|
|
311
|
+
})));
|
|
312
|
+
const message = {
|
|
313
|
+
type: "blink:wallets-advertised",
|
|
314
|
+
protocolVersion: BRIDGE_PROTOCOL_VERSION,
|
|
315
|
+
wallets
|
|
316
|
+
};
|
|
317
|
+
postToIframe(message);
|
|
318
|
+
}
|
|
319
|
+
function ensureSubscription(uuid, provider) {
|
|
320
|
+
if (subscriptions.has(uuid)) return;
|
|
321
|
+
if (typeof provider.on !== "function") {
|
|
322
|
+
subscriptions.set(uuid, { provider, listeners: /* @__PURE__ */ new Map() });
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
const record = { provider, listeners: /* @__PURE__ */ new Map() };
|
|
326
|
+
for (const event of FORWARDED_PROVIDER_EVENTS) {
|
|
327
|
+
const listener = (...args) => {
|
|
328
|
+
const eventMessage = {
|
|
329
|
+
type: "blink:rpc-event",
|
|
330
|
+
protocolVersion: BRIDGE_PROTOCOL_VERSION,
|
|
331
|
+
uuid,
|
|
332
|
+
event,
|
|
333
|
+
args
|
|
334
|
+
};
|
|
335
|
+
postToIframe(eventMessage);
|
|
336
|
+
};
|
|
337
|
+
try {
|
|
338
|
+
provider.on(event, listener);
|
|
339
|
+
record.listeners.set(event, listener);
|
|
340
|
+
} catch (err) {
|
|
341
|
+
log(`provider.on('${event}') threw \u2014 skipping that event`, {
|
|
342
|
+
uuid,
|
|
343
|
+
error: err instanceof Error ? err.message : String(err)
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
subscriptions.set(uuid, record);
|
|
348
|
+
}
|
|
349
|
+
function unsubscribeAll() {
|
|
350
|
+
for (const [, record] of subscriptions) {
|
|
351
|
+
const provider = record.provider;
|
|
352
|
+
if (typeof provider.removeListener !== "function") continue;
|
|
353
|
+
for (const [event, listener] of record.listeners) {
|
|
354
|
+
try {
|
|
355
|
+
provider.removeListener(event, listener);
|
|
356
|
+
} catch {
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
subscriptions.clear();
|
|
361
|
+
}
|
|
362
|
+
function sendError(id, code, message, data) {
|
|
363
|
+
const response = {
|
|
364
|
+
type: "blink:rpc-response",
|
|
365
|
+
protocolVersion: BRIDGE_PROTOCOL_VERSION,
|
|
366
|
+
id,
|
|
367
|
+
error: data === void 0 ? { code, message } : { code, message, data }
|
|
368
|
+
};
|
|
369
|
+
postToIframe(response);
|
|
370
|
+
}
|
|
371
|
+
function sendResult(id, result) {
|
|
372
|
+
const response = {
|
|
373
|
+
type: "blink:rpc-response",
|
|
374
|
+
protocolVersion: BRIDGE_PROTOCOL_VERSION,
|
|
375
|
+
id,
|
|
376
|
+
result
|
|
377
|
+
};
|
|
378
|
+
postToIframe(response);
|
|
379
|
+
}
|
|
380
|
+
const onMessage = (event) => {
|
|
381
|
+
if (detached) return;
|
|
382
|
+
if (event.source !== iframeWindow) return;
|
|
383
|
+
if (event.origin !== iframeOrigin) return;
|
|
384
|
+
const message = parseBridgeMessage(event.data);
|
|
385
|
+
if (!message) return;
|
|
386
|
+
switch (message.type) {
|
|
387
|
+
case "blink:bridge-hello": {
|
|
388
|
+
advertiseWallets(discoverer.list());
|
|
389
|
+
discoverer.requestProviders();
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
case "blink:rpc-request": {
|
|
393
|
+
const { id, uuid, method, params } = message;
|
|
394
|
+
console.info("[blink-bridge:parent] rpc-request", { uuid, method });
|
|
395
|
+
if (!ALLOWED_RPC_METHODS.has(method)) {
|
|
396
|
+
log("rejecting non-allowlisted method", { uuid, method });
|
|
397
|
+
sendError(id, -32601, `Method not allowed: ${method}`);
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
const provider = discoverer.get(uuid);
|
|
401
|
+
if (!provider) {
|
|
402
|
+
log("no provider for uuid", { uuid, method });
|
|
403
|
+
sendError(id, -32602, `Unknown wallet: ${uuid}`);
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
ensureSubscription(uuid, provider);
|
|
407
|
+
provider.request({ method, params }).then((result) => {
|
|
408
|
+
console.info("[blink-bridge:parent] rpc-result", { uuid, method, ok: true });
|
|
409
|
+
sendResult(id, result);
|
|
410
|
+
}).catch((err) => {
|
|
411
|
+
const { code, message: errMessage, data } = normalizeProviderError(err);
|
|
412
|
+
console.info("[blink-bridge:parent] rpc-error", { uuid, method, code, message: errMessage });
|
|
413
|
+
sendError(id, code, errMessage, data);
|
|
414
|
+
});
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
case "blink:resolve-by-flag": {
|
|
418
|
+
const match = resolveByFlag(discoverer.list(), message.flags, log);
|
|
419
|
+
console.info("[blink-bridge:parent] resolveByFlag", {
|
|
420
|
+
flags: message.flags,
|
|
421
|
+
match: match ? { rdns: match.rdns, flag: match.flag } : null
|
|
422
|
+
});
|
|
423
|
+
const response = {
|
|
424
|
+
type: "blink:resolve-by-flag-response",
|
|
425
|
+
protocolVersion: BRIDGE_PROTOCOL_VERSION,
|
|
426
|
+
id: message.id,
|
|
427
|
+
match
|
|
428
|
+
};
|
|
429
|
+
postToIframe(response);
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
case "blink:wallets-advertised":
|
|
433
|
+
case "blink:rpc-response":
|
|
434
|
+
case "blink:rpc-event":
|
|
435
|
+
case "blink:resolve-by-flag-response":
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
window.addEventListener("message", onMessage);
|
|
440
|
+
return {
|
|
441
|
+
detach() {
|
|
442
|
+
if (detached) return;
|
|
443
|
+
detached = true;
|
|
444
|
+
window.removeEventListener("message", onMessage);
|
|
445
|
+
unsubscribeFromDiscoverer();
|
|
446
|
+
unsubscribeAll();
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
function noopLog() {
|
|
451
|
+
}
|
|
452
|
+
function resolveByFlag(snapshot, flags, log) {
|
|
453
|
+
for (const flag of flags) {
|
|
454
|
+
for (const entry of snapshot) {
|
|
455
|
+
let value;
|
|
456
|
+
try {
|
|
457
|
+
value = entry.provider[flag];
|
|
458
|
+
} catch (err) {
|
|
459
|
+
log("provider threw on flag read \u2014 skipping", {
|
|
460
|
+
rdns: entry.info.rdns,
|
|
461
|
+
flag,
|
|
462
|
+
error: err instanceof Error ? err.message : String(err)
|
|
463
|
+
});
|
|
464
|
+
continue;
|
|
465
|
+
}
|
|
466
|
+
if (value) {
|
|
467
|
+
return { rdns: entry.info.rdns, uuid: entry.info.uuid, flag };
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
return null;
|
|
472
|
+
}
|
|
473
|
+
function normalizeProviderError(err) {
|
|
474
|
+
if (err && typeof err === "object") {
|
|
475
|
+
const e = err;
|
|
476
|
+
const code = typeof e.code === "number" ? e.code : -32603;
|
|
477
|
+
const message = typeof e.message === "string" ? e.message : err instanceof Error ? err.message : "Provider error";
|
|
478
|
+
const data = "data" in e ? e.data : void 0;
|
|
479
|
+
return data === void 0 ? { code, message } : { code, message, data };
|
|
480
|
+
}
|
|
481
|
+
return { code: -32603, message: typeof err === "string" ? err : "Provider error" };
|
|
482
|
+
}
|
|
483
|
+
|
|
102
484
|
// src/iframe.ts
|
|
103
485
|
var STYLE_ID = "blink-deposit-styles";
|
|
104
486
|
var CLOSE_DURATION_MS = 280;
|
|
487
|
+
var MOBILE_SHEET_MAX_VIEWPORT_PX = 640;
|
|
488
|
+
var MOBILE_SHEET_MAX_SCREEN_PX = 900;
|
|
105
489
|
var STYLES = `
|
|
106
490
|
@keyframes blink-fade-in{from{opacity:0}to{opacity:1}}
|
|
107
491
|
@keyframes blink-fade-out{from{opacity:1}to{opacity:0}}
|
|
@@ -110,12 +494,13 @@ var STYLES = `
|
|
|
110
494
|
@keyframes blink-slide-down-full{from{transform:translateY(0)}to{transform:translateY(100%)}}
|
|
111
495
|
[data-blink-overlay]{position:fixed;inset:0;background:rgba(0,0,0,.6);display:flex;align-items:center;justify-content:center;z-index:2147483647;animation:blink-fade-in .2s ease-out;backdrop-filter:blur(4px);-webkit-backdrop-filter:blur(4px)}
|
|
112
496
|
[data-blink-overlay][data-blink-closing]{animation:blink-fade-out ${CLOSE_DURATION_MS}ms ease-in forwards;pointer-events:none}
|
|
113
|
-
[data-blink-
|
|
497
|
+
[data-blink-overlay][data-blink-mobile-sheet]{align-items:flex-end;touch-action:none;overscroll-behavior:contain}
|
|
498
|
+
[data-blink-container]{width:min(420px,92vw);height:min(600px,85vh);border-radius:24px;overflow:hidden;box-shadow:0 24px 80px rgba(0,0,0,.4);animation:blink-slide-up .25s ease-out;display:flex;flex-direction:column;background:transparent}
|
|
114
499
|
[data-blink-overlay][data-blink-closing] [data-blink-container]{opacity:0;transition:opacity ${CLOSE_DURATION_MS}ms ease-in}
|
|
115
|
-
[data-blink-
|
|
116
|
-
[data-blink-
|
|
117
|
-
[data-blink-container]
|
|
118
|
-
@media(max-width
|
|
500
|
+
[data-blink-container] iframe{width:100%;flex:1;border:none;display:block;background:transparent;color-scheme:normal;border-radius:inherit}
|
|
501
|
+
[data-blink-overlay][data-blink-mobile-sheet] [data-blink-container]{width:100%;max-width:100%;height:79vh;border-radius:24px 24px 0 0;box-shadow:0 -8px 40px rgba(0,0,0,.25);animation:blink-slide-up-full .35s cubic-bezier(.32,.72,0,1);padding-bottom:env(safe-area-inset-bottom,0px)}
|
|
502
|
+
[data-blink-overlay][data-blink-mobile-sheet][data-blink-closing] [data-blink-container]{opacity:1;animation:blink-slide-down-full ${CLOSE_DURATION_MS}ms ease-in forwards}
|
|
503
|
+
@media(max-width:${MOBILE_SHEET_MAX_VIEWPORT_PX}px){[data-blink-overlay]{align-items:flex-end;touch-action:none;overscroll-behavior:contain}[data-blink-container]{width:100%;max-width:100%;height:79vh;border-radius:24px 24px 0 0;box-shadow:0 -8px 40px rgba(0,0,0,.25);animation:blink-slide-up-full .35s cubic-bezier(.32,.72,0,1);padding-bottom:env(safe-area-inset-bottom,0px)}[data-blink-overlay][data-blink-closing] [data-blink-container]{opacity:1;animation:blink-slide-down-full ${CLOSE_DURATION_MS}ms ease-in forwards}}
|
|
119
504
|
`;
|
|
120
505
|
function createIframe(url, containerElement) {
|
|
121
506
|
ensureStyles();
|
|
@@ -123,19 +508,34 @@ function createIframe(url, containerElement) {
|
|
|
123
508
|
let closeCallback = null;
|
|
124
509
|
const overlay = document.createElement("div");
|
|
125
510
|
overlay.setAttribute("data-blink-overlay", "");
|
|
511
|
+
if (shouldUseMobileSheetLayout()) {
|
|
512
|
+
overlay.setAttribute("data-blink-mobile-sheet", "");
|
|
513
|
+
}
|
|
126
514
|
const container = document.createElement("div");
|
|
127
515
|
container.setAttribute("data-blink-container", "");
|
|
128
516
|
const iframe = document.createElement("iframe");
|
|
129
517
|
iframe.src = url;
|
|
130
518
|
const iframeOrigin = new URL(url).origin;
|
|
131
|
-
iframe.allow = `publickey-credentials-get ${iframeOrigin}; publickey-credentials-create ${iframeOrigin}`;
|
|
519
|
+
iframe.allow = `publickey-credentials-get ${iframeOrigin}; publickey-credentials-create ${iframeOrigin}; clipboard-write ${iframeOrigin}`;
|
|
132
520
|
const handle = document.createElement("div");
|
|
133
|
-
handle.setAttribute("data-blink-handle", "");
|
|
134
521
|
container.appendChild(handle);
|
|
135
522
|
container.appendChild(iframe);
|
|
136
523
|
overlay.appendChild(container);
|
|
137
524
|
const mountTarget = containerElement ?? document.body;
|
|
138
525
|
mountTarget.appendChild(overlay);
|
|
526
|
+
const discoverer = createWalletDiscoverer();
|
|
527
|
+
let rpcHostHandle = null;
|
|
528
|
+
const attachBridge = () => {
|
|
529
|
+
if (rpcHostHandle) return;
|
|
530
|
+
if (!iframe.contentWindow) return;
|
|
531
|
+
rpcHostHandle = attachRpcHost({
|
|
532
|
+
iframeWindow: iframe.contentWindow,
|
|
533
|
+
iframeOrigin,
|
|
534
|
+
discoverer
|
|
535
|
+
});
|
|
536
|
+
};
|
|
537
|
+
attachBridge();
|
|
538
|
+
iframe.addEventListener("load", attachBridge);
|
|
139
539
|
const savedOverflow = document.body.style.overflow;
|
|
140
540
|
document.body.style.overflow = "hidden";
|
|
141
541
|
const onBackdropClick = (event) => {
|
|
@@ -162,6 +562,7 @@ function createIframe(url, containerElement) {
|
|
|
162
562
|
if (closed) return;
|
|
163
563
|
closed = true;
|
|
164
564
|
removeListeners();
|
|
565
|
+
detachBridge();
|
|
165
566
|
overlay.setAttribute("data-blink-closing", "");
|
|
166
567
|
let removed = false;
|
|
167
568
|
const removeOverlay = () => {
|
|
@@ -174,6 +575,14 @@ function createIframe(url, containerElement) {
|
|
|
174
575
|
container.addEventListener("animationend", removeOverlay, { once: true });
|
|
175
576
|
setTimeout(removeOverlay, CLOSE_DURATION_MS + 50);
|
|
176
577
|
}
|
|
578
|
+
function detachBridge() {
|
|
579
|
+
iframe.removeEventListener("load", attachBridge);
|
|
580
|
+
if (rpcHostHandle) {
|
|
581
|
+
rpcHostHandle.detach();
|
|
582
|
+
rpcHostHandle = null;
|
|
583
|
+
}
|
|
584
|
+
discoverer.destroy();
|
|
585
|
+
}
|
|
177
586
|
return {
|
|
178
587
|
get contentWindow() {
|
|
179
588
|
return iframe.contentWindow;
|
|
@@ -192,6 +601,7 @@ function createIframe(url, containerElement) {
|
|
|
192
601
|
if (!closed) {
|
|
193
602
|
closed = true;
|
|
194
603
|
removeListeners();
|
|
604
|
+
detachBridge();
|
|
195
605
|
overlay.remove();
|
|
196
606
|
unlockScroll();
|
|
197
607
|
}
|
|
@@ -199,12 +609,34 @@ function createIframe(url, containerElement) {
|
|
|
199
609
|
};
|
|
200
610
|
}
|
|
201
611
|
function ensureStyles() {
|
|
202
|
-
|
|
612
|
+
const existingStyle = document.getElementById(STYLE_ID);
|
|
613
|
+
if (existingStyle) {
|
|
614
|
+
if (existingStyle.textContent !== STYLES) {
|
|
615
|
+
existingStyle.textContent = STYLES;
|
|
616
|
+
}
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
203
619
|
const style = document.createElement("style");
|
|
204
620
|
style.id = STYLE_ID;
|
|
205
621
|
style.textContent = STYLES;
|
|
206
622
|
document.head.appendChild(style);
|
|
207
623
|
}
|
|
624
|
+
function shouldUseMobileSheetLayout() {
|
|
625
|
+
if (typeof window === "undefined") return false;
|
|
626
|
+
if (window.matchMedia?.(`(max-width: ${MOBILE_SHEET_MAX_VIEWPORT_PX}px)`).matches) {
|
|
627
|
+
return true;
|
|
628
|
+
}
|
|
629
|
+
const viewportWidth = window.visualViewport?.width ?? window.innerWidth;
|
|
630
|
+
if (viewportWidth > 0 && viewportWidth <= MOBILE_SHEET_MAX_VIEWPORT_PX) {
|
|
631
|
+
return true;
|
|
632
|
+
}
|
|
633
|
+
const hasCoarsePointer = window.matchMedia?.("(pointer: coarse)").matches ?? false;
|
|
634
|
+
if (!hasCoarsePointer) {
|
|
635
|
+
return false;
|
|
636
|
+
}
|
|
637
|
+
const shortestScreenSide = Math.min(window.screen.width, window.screen.height);
|
|
638
|
+
return shortestScreenSide > 0 && shortestScreenSide <= MOBILE_SHEET_MAX_SCREEN_PX;
|
|
639
|
+
}
|
|
208
640
|
|
|
209
641
|
// src/signer.ts
|
|
210
642
|
var DEFAULT_SIGNER_TIMEOUT_MS = 15e3;
|
|
@@ -292,8 +724,10 @@ function isValidTokenAddress(value) {
|
|
|
292
724
|
return TOKEN_ADDRESS_RE.test(value) || SOLANA_ADDRESS_RE.test(value);
|
|
293
725
|
}
|
|
294
726
|
function validateDepositRequest(request) {
|
|
295
|
-
if (
|
|
296
|
-
|
|
727
|
+
if (request.amount !== null) {
|
|
728
|
+
if (typeof request.amount !== "number" || !Number.isFinite(request.amount) || request.amount <= 0) {
|
|
729
|
+
throw new DepositError("INVALID_REQUEST", "amount must be a positive number or null.");
|
|
730
|
+
}
|
|
297
731
|
}
|
|
298
732
|
if (!Number.isInteger(request.chainId) || request.chainId <= 0) {
|
|
299
733
|
throw new DepositError("INVALID_REQUEST", "chainId must be a positive integer.");
|
|
@@ -411,9 +845,7 @@ var Deposit = class {
|
|
|
411
845
|
this.setStatus("completed");
|
|
412
846
|
this.emit("complete", result);
|
|
413
847
|
resolve(result);
|
|
414
|
-
|
|
415
|
-
this.cleanup();
|
|
416
|
-
}
|
|
848
|
+
this.cleanup();
|
|
417
849
|
});
|
|
418
850
|
};
|
|
419
851
|
const onError = (error) => {
|
|
@@ -610,12 +1042,17 @@ var Checkout = Deposit;
|
|
|
610
1042
|
// src/index.ts
|
|
611
1043
|
var VERSION = "0.3.0";
|
|
612
1044
|
|
|
1045
|
+
exports.ALLOWED_RPC_METHODS = ALLOWED_RPC_METHODS;
|
|
1046
|
+
exports.BRIDGE_PROTOCOL_VERSION = BRIDGE_PROTOCOL_VERSION;
|
|
613
1047
|
exports.Checkout = Checkout;
|
|
614
1048
|
exports.CheckoutError = CheckoutError;
|
|
615
1049
|
exports.DEFAULT_WEBVIEW_BASE_URL = DEFAULT_WEBVIEW_BASE_URL;
|
|
616
1050
|
exports.Deposit = Deposit;
|
|
617
1051
|
exports.DepositError = DepositError;
|
|
618
1052
|
exports.VERSION = VERSION;
|
|
1053
|
+
exports.attachRpcHost = attachRpcHost;
|
|
1054
|
+
exports.createWalletDiscoverer = createWalletDiscoverer;
|
|
619
1055
|
exports.getDisplayMessage = getDisplayMessage;
|
|
1056
|
+
exports.parseBridgeMessage = parseBridgeMessage;
|
|
620
1057
|
//# sourceMappingURL=index.cjs.map
|
|
621
1058
|
//# sourceMappingURL=index.cjs.map
|