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