@glacislabs/stablegenie-zerodelta 2.0.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/LICENSE +21 -0
- package/README.md +157 -0
- package/dist/chunk-DSQ7MRF7.js +3107 -0
- package/dist/chunk-VL5MWEY2.js +1426 -0
- package/dist/core/index.cjs +1522 -0
- package/dist/core/index.d.cts +353 -0
- package/dist/core/index.d.ts +353 -0
- package/dist/core/index.js +1 -0
- package/dist/index.cjs +4491 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +2 -0
- package/dist/mount-yTJi4VdA.d.ts +204 -0
- package/dist/mount-yqXrDBLc.d.cts +204 -0
- package/dist/mount.cjs +4481 -0
- package/dist/mount.d.cts +3 -0
- package/dist/mount.d.ts +3 -0
- package/dist/mount.js +2 -0
- package/dist/standalone.global.js +451 -0
- package/dist/verify-CaO0OD4Z.d.cts +351 -0
- package/dist/verify-CaO0OD4Z.d.ts +351 -0
- package/package.json +119 -0
package/dist/mount.cjs
ADDED
|
@@ -0,0 +1,4481 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var client = require('react-dom/client');
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
|
|
7
|
+
// src/mount.ts
|
|
8
|
+
var ConfigContext = react.createContext({});
|
|
9
|
+
function useMergedConfig(local) {
|
|
10
|
+
const ctx = react.useContext(ConfigContext);
|
|
11
|
+
return { ...ctx, ...local, theme: { ...ctx.theme, ...local.theme } };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// src/core/constants.ts
|
|
15
|
+
var DEFAULT_WIDGET_API_BASE = "/api/widget/v1";
|
|
16
|
+
var SUPPORTED_CHAIN_IDS = /* @__PURE__ */ new Set([1, 10, 42161, 8453, 57073, 130, 9745, 146]);
|
|
17
|
+
var SUPPORTED_ASSETS = /* @__PURE__ */ new Set(["USDC", "USDT", "USDE", "XAUT"]);
|
|
18
|
+
var API_CACHE_TTL_MS = 6e4;
|
|
19
|
+
var MAX_QUOTE_CANDIDATES = 8;
|
|
20
|
+
var QUOTE_BUFFER_BPS = 50;
|
|
21
|
+
var LZ_FEE_BUFFER_BPS = 1500n;
|
|
22
|
+
var SUBMIT_ORDER_SELECTOR = "0xbbd71141";
|
|
23
|
+
var ERC20_APPROVE_SELECTOR = "0x095ea7b3";
|
|
24
|
+
var ERC20_TRANSFER_SELECTOR = "0xa9059cbb";
|
|
25
|
+
var ERC20_ALLOWANCE_SELECTOR = "0xdd62ed3e";
|
|
26
|
+
var ERC20_BALANCEOF_SELECTOR = "0x70a08231";
|
|
27
|
+
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
28
|
+
var PREVIEW_OWNER = "0x1111111111111111111111111111111111111111";
|
|
29
|
+
var CANONICAL_DECIMALS = { USDC: 6, USDT: 6, USDE: 18, XAUT: 6 };
|
|
30
|
+
var CANONICAL_ESCROW = Object.freeze({
|
|
31
|
+
1: "0x46A3219c357C2E50129d4839058FCFD421789aE7",
|
|
32
|
+
// Ethereum — impl 0x49d173C4AbC90B3665D691f1FF2064eb9732A743
|
|
33
|
+
10: "0x46A3219c357C2E50129d4839058FCFD421789aE7",
|
|
34
|
+
// Optimism — impl 0xB47eCBa71039694D28E76C482aC2bE34d5faC22A
|
|
35
|
+
130: "0x46A3219c357C2E50129d4839058FCFD421789aE7",
|
|
36
|
+
// Unichain — impl 0xA9B1bBF52EF242aa4b9a8018bfD48fe64BbDfD03
|
|
37
|
+
146: "0x46A3219c357C2E50129d4839058FCFD421789aE7",
|
|
38
|
+
// Sonic — impl 0x4c66dECff081Cf282af4C7f9CA436CB7b46A700d
|
|
39
|
+
8453: "0x46A3219c357C2E50129d4839058FCFD421789aE7",
|
|
40
|
+
// Base — impl 0x70E37bF2c258015DAB7FE26942185D0362ebEd46
|
|
41
|
+
9745: "0x46A3219c357C2E50129d4839058FCFD421789aE7",
|
|
42
|
+
// Plasma — impl 0x70168A99722f3041ceff211C4E505e8732ee965D
|
|
43
|
+
57073: "0x46A3219c357C2E50129d4839058FCFD421789aE7",
|
|
44
|
+
// Ink — impl 0x8A9e68864f476DA577e948cb61Cedffe7e17b562
|
|
45
|
+
42161: "0x46A3219c357C2E50129d4839058FCFD421789aE7"
|
|
46
|
+
// Arbitrum — impl 0x453B00aeB8c7dDBaff10f2812A0bA7dc88DdbC35
|
|
47
|
+
});
|
|
48
|
+
var MAX_LZ_MSG_VALUE_WEI = 10n ** 18n;
|
|
49
|
+
var MAX_LZ_MSG_VALUE_WEI_BY_CHAIN = {};
|
|
50
|
+
function maxNativeFeeWei(chainId) {
|
|
51
|
+
return MAX_LZ_MSG_VALUE_WEI_BY_CHAIN[Number(chainId)] ?? MAX_LZ_MSG_VALUE_WEI;
|
|
52
|
+
}
|
|
53
|
+
var CANONICAL_INBOUND_BRIDGE = {
|
|
54
|
+
USDC: "cctp",
|
|
55
|
+
USDT: "layerzero",
|
|
56
|
+
USDE: "layerzero",
|
|
57
|
+
XAUT: "layerzero"
|
|
58
|
+
};
|
|
59
|
+
var SAME_CLASS_STABLE = /* @__PURE__ */ new Set(["USDC", "USDT", "USDE"]);
|
|
60
|
+
var MAX_SAME_CLASS_PAY_BPS = 30000n;
|
|
61
|
+
var BUNDLED_NATIVE_SYMBOL = {
|
|
62
|
+
1: "ETH",
|
|
63
|
+
10: "ETH",
|
|
64
|
+
130: "ETH",
|
|
65
|
+
146: "S",
|
|
66
|
+
8453: "ETH",
|
|
67
|
+
57073: "ETH",
|
|
68
|
+
42161: "ETH"
|
|
69
|
+
};
|
|
70
|
+
var BUNDLED_RPC = {
|
|
71
|
+
1: "https://ethereum-rpc.publicnode.com",
|
|
72
|
+
10: "https://optimism-rpc.publicnode.com",
|
|
73
|
+
130: "https://mainnet.unichain.org",
|
|
74
|
+
146: "https://rpc.soniclabs.com",
|
|
75
|
+
8453: "https://mainnet.base.org",
|
|
76
|
+
9745: "https://rpc.plasma.to",
|
|
77
|
+
57073: "https://rpc-gel.inkonchain.com",
|
|
78
|
+
42161: "https://arb1.arbitrum.io/rpc"
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/core/address.ts
|
|
82
|
+
function symbolKey(value) {
|
|
83
|
+
return String(value || "").trim().toUpperCase();
|
|
84
|
+
}
|
|
85
|
+
function isAddress(value) {
|
|
86
|
+
return /^0x[a-fA-F0-9]{40}$/.test(String(value || ""));
|
|
87
|
+
}
|
|
88
|
+
function normalizeAddress(value) {
|
|
89
|
+
if (!isAddress(value)) return null;
|
|
90
|
+
return String(value).toLowerCase();
|
|
91
|
+
}
|
|
92
|
+
function assertAddress(value, label) {
|
|
93
|
+
const normalized = normalizeAddress(value);
|
|
94
|
+
if (!normalized || normalized === ZERO_ADDRESS) throw new Error(`${label} is not a valid EVM address.`);
|
|
95
|
+
return normalized;
|
|
96
|
+
}
|
|
97
|
+
function resolveSwapReceiver(recipient, payer) {
|
|
98
|
+
const payerAddr = assertAddress(payer, "Swap wallet");
|
|
99
|
+
if (recipient === void 0 || recipient === null || recipient === "") return payerAddr;
|
|
100
|
+
const normalized = normalizeAddress(recipient);
|
|
101
|
+
if (!normalized || normalized === ZERO_ADDRESS) throw new Error("Deposit recipient is not a valid EVM address.");
|
|
102
|
+
return normalized;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// src/core/units.ts
|
|
106
|
+
function assetDecimals(token) {
|
|
107
|
+
const sym = symbolKey(token?.symbol);
|
|
108
|
+
const registry = Number(token?.decimals);
|
|
109
|
+
const canonical = CANONICAL_DECIMALS[sym];
|
|
110
|
+
if (canonical !== void 0) {
|
|
111
|
+
if (!Number.isInteger(registry)) {
|
|
112
|
+
throw new Error(`ZeroDelta token registry is missing decimals for ${sym}; refusing to price.`);
|
|
113
|
+
}
|
|
114
|
+
if (registry !== canonical) {
|
|
115
|
+
throw new Error(`ZeroDelta token registry reported ${registry} decimals for ${sym}; expected ${canonical}. Refusing to price.`);
|
|
116
|
+
}
|
|
117
|
+
return canonical;
|
|
118
|
+
}
|
|
119
|
+
if (!Number.isInteger(registry) || registry < 0 || registry > 36) {
|
|
120
|
+
throw new Error(`ZeroDelta token registry has invalid decimals for ${sym || "token"}; refusing to price.`);
|
|
121
|
+
}
|
|
122
|
+
return registry;
|
|
123
|
+
}
|
|
124
|
+
function normalizeDecimalText(value) {
|
|
125
|
+
const text = String(value || "").trim().replace(/\s+/g, "");
|
|
126
|
+
if (!text) return "";
|
|
127
|
+
if (/^\d{1,3}(,\d{3})+(?:\.\d+)?$/.test(text)) return text.replace(/,/g, "");
|
|
128
|
+
if (/^\d+,\d{1,18}$/.test(text) && !text.includes(".")) return text.replace(",", ".");
|
|
129
|
+
if (text.includes(",")) return "";
|
|
130
|
+
return text;
|
|
131
|
+
}
|
|
132
|
+
function parseUnitsDecimal(amount, decimals) {
|
|
133
|
+
const text = normalizeDecimalText(amount);
|
|
134
|
+
if (!/^\d+(\.\d+)?$/.test(text)) throw new Error("Could not detect a valid payment amount.");
|
|
135
|
+
const [whole, frac = ""] = text.split(".");
|
|
136
|
+
if (frac.length > decimals) throw new Error("Payment amount has more decimal places than the asset supports.");
|
|
137
|
+
const padded = (frac + "0".repeat(decimals)).slice(0, decimals);
|
|
138
|
+
const value = BigInt(whole || "0") * 10n ** BigInt(decimals) + BigInt(padded || "0");
|
|
139
|
+
if (value <= 0n) throw new Error("Payment amount must be greater than zero.");
|
|
140
|
+
return value;
|
|
141
|
+
}
|
|
142
|
+
function scaleDecimals(amount, fromDecimals, toDecimals) {
|
|
143
|
+
if (toDecimals === fromDecimals) return amount;
|
|
144
|
+
if (toDecimals > fromDecimals) return amount * 10n ** BigInt(toDecimals - fromDecimals);
|
|
145
|
+
return amount / 10n ** BigInt(fromDecimals - toDecimals);
|
|
146
|
+
}
|
|
147
|
+
function formatUnits(raw, decimals, maxDecimals = 6) {
|
|
148
|
+
const value = BigInt(raw || "0");
|
|
149
|
+
const base = 10n ** BigInt(decimals);
|
|
150
|
+
const whole = value / base;
|
|
151
|
+
const fracFull = (value % base).toString().padStart(decimals, "0");
|
|
152
|
+
const frac = fracFull.slice(0, Math.min(decimals, maxDecimals)).replace(/0+$/, "");
|
|
153
|
+
return frac ? `${whole}.${frac}` : whole.toString();
|
|
154
|
+
}
|
|
155
|
+
function finalOf(quote) {
|
|
156
|
+
return BigInt(quote?.finalAmount || quote?.toAmount || "0");
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// src/core/abi.ts
|
|
160
|
+
function strip0x(value) {
|
|
161
|
+
return String(value || "").replace(/^0x/i, "");
|
|
162
|
+
}
|
|
163
|
+
function uintWord(value) {
|
|
164
|
+
const n = BigInt(value || 0);
|
|
165
|
+
if (n < 0n) throw new Error("Cannot encode a negative uint256.");
|
|
166
|
+
const hex = n.toString(16);
|
|
167
|
+
if (hex.length > 64) throw new Error("uint256 value is too large.");
|
|
168
|
+
return hex.padStart(64, "0");
|
|
169
|
+
}
|
|
170
|
+
function addressWord(address) {
|
|
171
|
+
return strip0x(assertAddress(address, "Address")).padStart(64, "0");
|
|
172
|
+
}
|
|
173
|
+
function bytesPayload(value) {
|
|
174
|
+
const hex = strip0x(value);
|
|
175
|
+
if (hex.length % 2) throw new Error("Order data has an odd-length hex payload; refusing to encode.");
|
|
176
|
+
if (!/^[a-fA-F0-9]*$/.test(hex)) throw new Error("Order data is not valid hex.");
|
|
177
|
+
const byteLength = hex.length / 2;
|
|
178
|
+
const paddedLength = Math.ceil(hex.length / 64) * 64;
|
|
179
|
+
return `${uintWord(byteLength)}${hex.padEnd(paddedLength, "0")}`;
|
|
180
|
+
}
|
|
181
|
+
function encodeApprove(spender, amount) {
|
|
182
|
+
return `0x${ERC20_APPROVE_SELECTOR.slice(2)}${addressWord(spender)}${uintWord(amount)}`;
|
|
183
|
+
}
|
|
184
|
+
function encodeTransfer(to, amount) {
|
|
185
|
+
return `0x${ERC20_TRANSFER_SELECTOR.slice(2)}${addressWord(to)}${uintWord(amount)}`;
|
|
186
|
+
}
|
|
187
|
+
function encodeAllowance(owner, spender) {
|
|
188
|
+
return `${ERC20_ALLOWANCE_SELECTOR}${addressWord(owner)}${addressWord(spender)}`;
|
|
189
|
+
}
|
|
190
|
+
function encodeBalanceOf(account) {
|
|
191
|
+
return `${ERC20_BALANCEOF_SELECTOR}${addressWord(account)}`;
|
|
192
|
+
}
|
|
193
|
+
function encodeSubmitOrder(order) {
|
|
194
|
+
const tupleHead = [
|
|
195
|
+
addressWord(order.owner),
|
|
196
|
+
addressWord(order.bidToken),
|
|
197
|
+
uintWord(order.bidTokenAmount),
|
|
198
|
+
addressWord(order.askToken),
|
|
199
|
+
uintWord(order.askTokenAmount),
|
|
200
|
+
addressWord(order.destinationReceiver),
|
|
201
|
+
uintWord(order.destinationChainId),
|
|
202
|
+
uintWord(order.deadline),
|
|
203
|
+
uintWord(9n * 32n)
|
|
204
|
+
].join("");
|
|
205
|
+
return `0x${SUBMIT_ORDER_SELECTOR.slice(2)}${uintWord(32)}${tupleHead}${bytesPayload(order.data)}`;
|
|
206
|
+
}
|
|
207
|
+
function toHexQuantity(value) {
|
|
208
|
+
const n = BigInt(value || 0);
|
|
209
|
+
return `0x${n.toString(16)}`;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// src/core/escrow.ts
|
|
213
|
+
function checkEscrow(chainId, quoteEscrow, chainsEscrow) {
|
|
214
|
+
const fromQuote = normalizeAddress(quoteEscrow);
|
|
215
|
+
const fromChains = normalizeAddress(chainsEscrow);
|
|
216
|
+
if (!fromChains || fromChains === ZERO_ADDRESS) {
|
|
217
|
+
throw new Error(`No registry escrow is available for ${chainId}; refusing to sign.`);
|
|
218
|
+
}
|
|
219
|
+
if (!fromQuote || fromQuote === ZERO_ADDRESS) {
|
|
220
|
+
throw new Error("ZeroDelta quote did not include an escrow address; refusing to sign.");
|
|
221
|
+
}
|
|
222
|
+
if (fromQuote !== fromChains) {
|
|
223
|
+
throw new Error("Escrow address from ZeroDelta quote does not match the chain registry.");
|
|
224
|
+
}
|
|
225
|
+
const pinned = normalizeAddress(CANONICAL_ESCROW[Number(chainId)]);
|
|
226
|
+
if (pinned && pinned !== fromChains) {
|
|
227
|
+
throw new Error(`Escrow address for ${chainId} does not match the pinned canonical escrow; refusing to sign.`);
|
|
228
|
+
}
|
|
229
|
+
return fromChains;
|
|
230
|
+
}
|
|
231
|
+
function isLayerZeroRoute(quote, option = {}) {
|
|
232
|
+
const bridge = `${quote?.bridge || ""} ${option?.bridge || ""}`.toLowerCase();
|
|
233
|
+
return bridge.includes("layerzero") || bridge.includes("layer zero");
|
|
234
|
+
}
|
|
235
|
+
function sourceAssetKey(quote, option = {}) {
|
|
236
|
+
return symbolKey(option?.symbolKey || option?.symbol || quote?.fromToken);
|
|
237
|
+
}
|
|
238
|
+
function requiresNativeBridgeFee(quote, option = {}) {
|
|
239
|
+
const sourceChainId = Number(option?.chainId ?? quote?.fromChainId);
|
|
240
|
+
const execChainId = Number(quote?.executionChainId);
|
|
241
|
+
if (Number.isFinite(sourceChainId) && Number.isFinite(execChainId) && execChainId > 0 && sourceChainId === execChainId) {
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
const canonical = CANONICAL_INBOUND_BRIDGE[sourceAssetKey(quote, option)];
|
|
245
|
+
if (canonical) return canonical === "layerzero";
|
|
246
|
+
return isLayerZeroRoute(quote, option);
|
|
247
|
+
}
|
|
248
|
+
function applyLayerZeroBuffer(quote, option = {}) {
|
|
249
|
+
const gas = BigInt(quote?.gasCostSource || "0");
|
|
250
|
+
if (gas <= 0n) return 0n;
|
|
251
|
+
if (!requiresNativeBridgeFee(quote, option)) return 0n;
|
|
252
|
+
return gas * (10000n + LZ_FEE_BUFFER_BPS) / 10000n;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// src/core/options.ts
|
|
256
|
+
function chainNameOf(chainId, chains) {
|
|
257
|
+
const chain = chains.find((item) => Number(item.chainId) === Number(chainId));
|
|
258
|
+
return chain?.displayName || chain?.name || `Chain ${chainId}`;
|
|
259
|
+
}
|
|
260
|
+
function chainById(chains, chainId) {
|
|
261
|
+
return chains.find((chain) => Number(chain.chainId) === Number(chainId)) || null;
|
|
262
|
+
}
|
|
263
|
+
function isDeliverable(symbol, chainId) {
|
|
264
|
+
if (Number(chainId) === 8453 && symbolKey(symbol) === "USDT") return false;
|
|
265
|
+
return true;
|
|
266
|
+
}
|
|
267
|
+
function chainSelectable(chain, chainId) {
|
|
268
|
+
if (!SUPPORTED_CHAIN_IDS.has(Number(chainId))) return false;
|
|
269
|
+
if (!chain) return true;
|
|
270
|
+
return chain.isEnabled !== false;
|
|
271
|
+
}
|
|
272
|
+
function tokenEnabled(token) {
|
|
273
|
+
return token?.isEnabled !== false && isAddress(token?.address) && Number.isFinite(Number(token?.chainId));
|
|
274
|
+
}
|
|
275
|
+
function findToken(tokens, chainId, symbol) {
|
|
276
|
+
const key = symbolKey(symbol);
|
|
277
|
+
return tokens.find((token) => tokenEnabled(token) && Number(token.chainId) === Number(chainId) && symbolKey(token.symbol) === key) || null;
|
|
278
|
+
}
|
|
279
|
+
function buildPayOptions({ invoiceAsset, invoiceChainId, tokens, routes, chains, walletChainId }) {
|
|
280
|
+
const invoiceKey = symbolKey(invoiceAsset);
|
|
281
|
+
const tokenBySymbolAndChain = /* @__PURE__ */ new Map();
|
|
282
|
+
for (const token of tokens) {
|
|
283
|
+
if (!tokenEnabled(token)) continue;
|
|
284
|
+
const key = symbolKey(token.symbol);
|
|
285
|
+
if (!tokenBySymbolAndChain.has(key)) tokenBySymbolAndChain.set(key, /* @__PURE__ */ new Map());
|
|
286
|
+
tokenBySymbolAndChain.get(key).set(Number(token.chainId), token);
|
|
287
|
+
}
|
|
288
|
+
const routeBridge = /* @__PURE__ */ new Map();
|
|
289
|
+
for (const route of routes || []) {
|
|
290
|
+
if (route.isEnabled === false || Number(route.toChainId) !== Number(invoiceChainId)) continue;
|
|
291
|
+
routeBridge.set(`${symbolKey(route.tokenName || route.tokenId)}:${Number(route.fromChainId)}`, route.bridge);
|
|
292
|
+
routeBridge.set(`${symbolKey(route.tokenId)}:${Number(route.fromChainId)}`, route.bridge);
|
|
293
|
+
}
|
|
294
|
+
const receiveDeliverable = isDeliverable(invoiceKey, invoiceChainId);
|
|
295
|
+
const options = [];
|
|
296
|
+
for (const [payKey, byChain] of tokenBySymbolAndChain.entries()) {
|
|
297
|
+
if (!byChain.has(Number(invoiceChainId))) continue;
|
|
298
|
+
for (const [chainId, token] of byChain.entries()) {
|
|
299
|
+
const chain = chainById(chains, chainId);
|
|
300
|
+
if (!chainSelectable(chain, chainId)) continue;
|
|
301
|
+
const direct = chainId === Number(invoiceChainId) && payKey === invoiceKey;
|
|
302
|
+
if (!direct && payKey === invoiceKey) continue;
|
|
303
|
+
if (!direct && (!receiveDeliverable || !isDeliverable(payKey, chainId))) continue;
|
|
304
|
+
options.push({
|
|
305
|
+
symbol: token.symbol,
|
|
306
|
+
symbolKey: payKey,
|
|
307
|
+
name: token.name || token.symbol,
|
|
308
|
+
chainId,
|
|
309
|
+
chainName: chainNameOf(chainId, chains),
|
|
310
|
+
address: token.address,
|
|
311
|
+
decimals: assetDecimals(token),
|
|
312
|
+
logoUrl: token.logoUrl,
|
|
313
|
+
bridge: routeBridge.get(`${payKey}:${chainId}`) || token.bridge,
|
|
314
|
+
sameChain: chainId === Number(invoiceChainId),
|
|
315
|
+
direct
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
options.sort((a, b) => {
|
|
320
|
+
const walletChain = Number(walletChainId || 0);
|
|
321
|
+
if (walletChain) {
|
|
322
|
+
if (a.chainId === walletChain && b.chainId !== walletChain) return -1;
|
|
323
|
+
if (b.chainId === walletChain && a.chainId !== walletChain) return 1;
|
|
324
|
+
}
|
|
325
|
+
if (a.direct !== b.direct) return a.direct ? -1 : 1;
|
|
326
|
+
if (a.symbolKey !== b.symbolKey) {
|
|
327
|
+
if (a.symbolKey === invoiceKey) return -1;
|
|
328
|
+
if (b.symbolKey === invoiceKey) return 1;
|
|
329
|
+
return a.symbolKey.localeCompare(b.symbolKey);
|
|
330
|
+
}
|
|
331
|
+
if (a.sameChain !== b.sameChain) return a.sameChain ? -1 : 1;
|
|
332
|
+
return a.chainId - b.chainId;
|
|
333
|
+
});
|
|
334
|
+
return options;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// src/core/native-fee.ts
|
|
338
|
+
function routeNativeValue(route) {
|
|
339
|
+
try {
|
|
340
|
+
const raw = route?.quote?.msgValue;
|
|
341
|
+
if (raw === void 0 || raw === null || raw === "") return 0n;
|
|
342
|
+
const value = BigInt(raw);
|
|
343
|
+
return value > 0n ? value : 0n;
|
|
344
|
+
} catch {
|
|
345
|
+
return 0n;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
function nativeSymbol(chainId, chains = []) {
|
|
349
|
+
const registry = chainById(chains, Number(chainId))?.nativeCurrency;
|
|
350
|
+
const fromRegistry = typeof registry === "string" ? registry.trim() : "";
|
|
351
|
+
return fromRegistry || BUNDLED_NATIVE_SYMBOL[Number(chainId)] || "ETH";
|
|
352
|
+
}
|
|
353
|
+
function formatNative(wei) {
|
|
354
|
+
const text = formatUnits(wei.toString(), 18, 8);
|
|
355
|
+
return text === "0" && wei > 0n ? "<0.00000001" : text;
|
|
356
|
+
}
|
|
357
|
+
function checkNativeFee(route, balance) {
|
|
358
|
+
const required = routeNativeValue(route);
|
|
359
|
+
if (required <= 0n || balance === null || balance === void 0) {
|
|
360
|
+
return { required, balance: balance ?? null, short: false, shortfall: 0n };
|
|
361
|
+
}
|
|
362
|
+
const shortfall = required > balance ? required - balance : 0n;
|
|
363
|
+
return { required, balance, short: shortfall > 0n, shortfall };
|
|
364
|
+
}
|
|
365
|
+
function nativeFeeShortLabel(check, symbol) {
|
|
366
|
+
if (!check.short) return null;
|
|
367
|
+
return `Need ${formatNative(check.required)} ${symbol} for the bridge fee`;
|
|
368
|
+
}
|
|
369
|
+
function nativeFeeShortMessage(check, symbol, chainName2) {
|
|
370
|
+
const need = formatNative(check.required);
|
|
371
|
+
const have = formatNative(check.balance ?? 0n);
|
|
372
|
+
const where = chainName2 ? ` on ${chainName2}` : "";
|
|
373
|
+
return `This route bridges via LayerZero, which charges a ${need} ${symbol} network fee paid as part of the transaction. Your wallet holds ${have} ${symbol}${where}. Add ${symbol}${where} and try again \u2014 gas is owed on top of this fee.`;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// src/core/solve.ts
|
|
377
|
+
async function solveExactOut({ option, destination, destinationToken, payer, fetchQuote }) {
|
|
378
|
+
const destDecimals = assetDecimals(destinationToken);
|
|
379
|
+
const targetRaw = parseUnitsDecimal(destination.amount, destDecimals);
|
|
380
|
+
if (option.direct) {
|
|
381
|
+
return {
|
|
382
|
+
directTransfer: true,
|
|
383
|
+
quote: {
|
|
384
|
+
fromChainId: option.chainId,
|
|
385
|
+
toChainId: Number(destination.chainId),
|
|
386
|
+
fromToken: option.symbol,
|
|
387
|
+
toToken: destinationToken.symbol,
|
|
388
|
+
fromAmount: targetRaw.toString(),
|
|
389
|
+
toAmount: targetRaw.toString(),
|
|
390
|
+
finalAmount: targetRaw.toString(),
|
|
391
|
+
bridge: "direct",
|
|
392
|
+
feeBps: 0,
|
|
393
|
+
estimatedDuration: 0,
|
|
394
|
+
gasCostSource: "0",
|
|
395
|
+
gasCostDest: "0",
|
|
396
|
+
orderRequest: null
|
|
397
|
+
},
|
|
398
|
+
youPayRaw: targetRaw.toString(),
|
|
399
|
+
recipientReceivesRaw: targetRaw.toString(),
|
|
400
|
+
targetRaw: targetRaw.toString(),
|
|
401
|
+
overageBps: 0,
|
|
402
|
+
meetsTarget: true,
|
|
403
|
+
iterations: 0
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
const local1to1 = scaleDecimals(targetRaw, destDecimals, option.decimals);
|
|
407
|
+
const samePriceClass = option.symbolKey === symbolKey(destinationToken.symbol) || SAME_CLASS_STABLE.has(option.symbolKey) && SAME_CLASS_STABLE.has(symbolKey(destinationToken.symbol));
|
|
408
|
+
const maxPayRaw = samePriceClass && local1to1 > 0n ? local1to1 * MAX_SAME_CLASS_PAY_BPS / 10000n : 0n;
|
|
409
|
+
const enforcePayCeiling = (raw) => {
|
|
410
|
+
if (maxPayRaw > 0n && BigInt(raw) > maxPayRaw) {
|
|
411
|
+
throw new Error("ZeroDelta priced this payment above the safety ceiling for the amount.");
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
const bufferNum = BigInt(1e4 + QUOTE_BUFFER_BPS);
|
|
415
|
+
let guess = scaleDecimals(targetRaw, destDecimals, option.decimals) * bufferNum / 10000n;
|
|
416
|
+
if (guess <= 0n) guess = 1n;
|
|
417
|
+
let best = null;
|
|
418
|
+
let bestFinal = -1n;
|
|
419
|
+
let bestGuess = guess;
|
|
420
|
+
for (let i = 0; i < 3; i += 1) {
|
|
421
|
+
const guessSent = guess;
|
|
422
|
+
const quote = await fetchQuote({
|
|
423
|
+
fromChainId: option.chainId,
|
|
424
|
+
toChainId: Number(destination.chainId),
|
|
425
|
+
fromToken: option.symbol,
|
|
426
|
+
toToken: destinationToken.symbol,
|
|
427
|
+
fromAmount: guessSent.toString(),
|
|
428
|
+
owner: payer,
|
|
429
|
+
destinationReceiver: destination.address
|
|
430
|
+
});
|
|
431
|
+
if (BigInt(quote?.fromAmount || "0") !== guessSent) {
|
|
432
|
+
throw new Error("ZeroDelta echoed a different input amount than requested.");
|
|
433
|
+
}
|
|
434
|
+
const guaranteed = BigInt(quote?.toAmount || "0");
|
|
435
|
+
const final = finalOf(quote);
|
|
436
|
+
if (final > bestFinal) {
|
|
437
|
+
bestFinal = final;
|
|
438
|
+
best = quote;
|
|
439
|
+
bestGuess = guessSent;
|
|
440
|
+
}
|
|
441
|
+
if (final >= targetRaw) {
|
|
442
|
+
const overageBps = targetRaw > 0n ? Number((final - targetRaw) * 10000n / targetRaw) : 0;
|
|
443
|
+
if (overageBps <= QUOTE_BUFFER_BPS + 25 || i === 2) {
|
|
444
|
+
enforcePayCeiling(guessSent.toString());
|
|
445
|
+
return {
|
|
446
|
+
directTransfer: false,
|
|
447
|
+
quote,
|
|
448
|
+
youPayRaw: guessSent.toString(),
|
|
449
|
+
recipientReceivesRaw: guaranteed.toString(),
|
|
450
|
+
targetRaw: targetRaw.toString(),
|
|
451
|
+
overageBps,
|
|
452
|
+
meetsTarget: true,
|
|
453
|
+
iterations: i + 1
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
guess = guess * targetRaw * bufferNum / (final * 10000n);
|
|
457
|
+
} else if (final <= 0n) {
|
|
458
|
+
guess = guess * 12000n / 10000n;
|
|
459
|
+
} else {
|
|
460
|
+
guess = guess * targetRaw * bufferNum / (final * 10000n);
|
|
461
|
+
}
|
|
462
|
+
if (guess <= 0n) guess = 1n;
|
|
463
|
+
if (maxPayRaw > 0n && guess > maxPayRaw) guess = maxPayRaw;
|
|
464
|
+
}
|
|
465
|
+
if (!best) throw new Error("Could not price this payment route.");
|
|
466
|
+
enforcePayCeiling(bestGuess.toString());
|
|
467
|
+
return {
|
|
468
|
+
directTransfer: false,
|
|
469
|
+
quote: best,
|
|
470
|
+
youPayRaw: bestGuess.toString(),
|
|
471
|
+
recipientReceivesRaw: BigInt(best.toAmount || "0").toString(),
|
|
472
|
+
targetRaw: targetRaw.toString(),
|
|
473
|
+
overageBps: targetRaw > 0n ? Number((bestFinal - targetRaw) * 10000n / targetRaw) : 0,
|
|
474
|
+
meetsTarget: bestFinal >= targetRaw,
|
|
475
|
+
iterations: 3
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
async function solveExactIn({ option, destination, destinationToken, payer, fetchQuote, amountInRaw }) {
|
|
479
|
+
const fromRaw = BigInt(amountInRaw || "0");
|
|
480
|
+
if (fromRaw <= 0n) throw new Error("Swap amount must be greater than zero.");
|
|
481
|
+
const quote = await fetchQuote({
|
|
482
|
+
fromChainId: option.chainId,
|
|
483
|
+
toChainId: Number(destination.chainId),
|
|
484
|
+
fromToken: option.symbol,
|
|
485
|
+
toToken: destinationToken.symbol,
|
|
486
|
+
fromAmount: fromRaw.toString(),
|
|
487
|
+
owner: payer,
|
|
488
|
+
destinationReceiver: destination.address
|
|
489
|
+
});
|
|
490
|
+
if (BigInt(quote?.fromAmount || "0") !== fromRaw) {
|
|
491
|
+
throw new Error("ZeroDelta echoed a different input amount than requested.");
|
|
492
|
+
}
|
|
493
|
+
const guaranteed = BigInt(quote?.toAmount || "0");
|
|
494
|
+
if (guaranteed <= 0n) throw new Error("ZeroDelta could not price this swap.");
|
|
495
|
+
return {
|
|
496
|
+
directTransfer: false,
|
|
497
|
+
quote,
|
|
498
|
+
youPayRaw: fromRaw.toString(),
|
|
499
|
+
recipientReceivesRaw: guaranteed.toString(),
|
|
500
|
+
targetRaw: guaranteed.toString(),
|
|
501
|
+
overageBps: 0,
|
|
502
|
+
meetsTarget: true,
|
|
503
|
+
iterations: 1
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
// src/core/order.ts
|
|
508
|
+
function normalizeOrderRequest(order, payer, destination) {
|
|
509
|
+
const apiDeadline = Number(order.deadline);
|
|
510
|
+
const deadline = Number.isFinite(apiDeadline) && apiDeadline > 0 ? String(order.deadline) : String(Math.floor(Date.now() / 1e3) + 1800);
|
|
511
|
+
return {
|
|
512
|
+
owner: assertAddress(order.owner || payer, "Order owner"),
|
|
513
|
+
bidToken: assertAddress(order.bidToken, "Bid token"),
|
|
514
|
+
bidTokenAmount: String(order.bidTokenAmount || "0"),
|
|
515
|
+
askToken: assertAddress(order.askToken, "Ask token"),
|
|
516
|
+
askTokenAmount: String(order.askTokenAmount || "0"),
|
|
517
|
+
destinationReceiver: assertAddress(order.destinationReceiver || destination.address, "Destination receiver"),
|
|
518
|
+
destinationChainId: String(order.destinationChainId || destination.chainId),
|
|
519
|
+
deadline,
|
|
520
|
+
data: order.data || "0x"
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
function assertQuoteMatchesSelection({ quote, order, option, destinationToken, destination, payer, result }) {
|
|
524
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
525
|
+
const deadline = Number(order.deadline || 0);
|
|
526
|
+
if (normalizeAddress(order.owner) !== normalizeAddress(payer)) {
|
|
527
|
+
throw new Error("ZeroDelta quote returned an owner that does not match the connected wallet.");
|
|
528
|
+
}
|
|
529
|
+
if (normalizeAddress(order.destinationReceiver) !== normalizeAddress(destination.address)) {
|
|
530
|
+
throw new Error("ZeroDelta quote returned a receiver that does not match the detected destination.");
|
|
531
|
+
}
|
|
532
|
+
if (normalizeAddress(order.bidToken) !== normalizeAddress(option.address)) {
|
|
533
|
+
throw new Error("ZeroDelta quote returned a bid token that does not match the selected route.");
|
|
534
|
+
}
|
|
535
|
+
if (normalizeAddress(order.askToken) !== normalizeAddress(destinationToken.address)) {
|
|
536
|
+
throw new Error("ZeroDelta quote returned an ask token that does not match the destination asset.");
|
|
537
|
+
}
|
|
538
|
+
if (Number(order.destinationChainId) !== Number(destination.chainId) || Number(quote.toChainId) !== Number(destination.chainId)) {
|
|
539
|
+
throw new Error("ZeroDelta quote returned a destination chain that does not match the payment request.");
|
|
540
|
+
}
|
|
541
|
+
if (Number(quote.fromChainId) !== Number(option.chainId)) {
|
|
542
|
+
throw new Error("ZeroDelta quote returned a source chain that does not match the selected route.");
|
|
543
|
+
}
|
|
544
|
+
if (symbolKey(quote.fromToken) !== option.symbolKey || symbolKey(quote.toToken) !== symbolKey(destinationToken.symbol)) {
|
|
545
|
+
throw new Error("ZeroDelta quote returned token symbols that do not match the selected route.");
|
|
546
|
+
}
|
|
547
|
+
if (BigInt(order.bidTokenAmount || "0") !== BigInt(result.youPayRaw || "0")) {
|
|
548
|
+
throw new Error("ZeroDelta quote returned a bid amount that does not match the displayed payment amount.");
|
|
549
|
+
}
|
|
550
|
+
if (BigInt(order.askTokenAmount || "0") !== BigInt(quote.toAmount || "0")) {
|
|
551
|
+
throw new Error("ZeroDelta quote returned an ask amount that does not match the quoted output.");
|
|
552
|
+
}
|
|
553
|
+
if (BigInt(order.askTokenAmount || "0") <= 0n || BigInt(quote.toAmount || "0") <= 0n) {
|
|
554
|
+
throw new Error("ZeroDelta quote returned a non-positive output amount.");
|
|
555
|
+
}
|
|
556
|
+
if (BigInt(order.askTokenAmount || "0") < BigInt(result.targetRaw || "0")) {
|
|
557
|
+
throw new Error("ZeroDelta quote would not cover the requested destination amount.");
|
|
558
|
+
}
|
|
559
|
+
if (BigInt(order.askTokenAmount || "0") < BigInt(result.recipientReceivesRaw || "0")) {
|
|
560
|
+
throw new Error("ZeroDelta order guarantees less than the displayed receive amount.");
|
|
561
|
+
}
|
|
562
|
+
if (!Number.isFinite(deadline) || deadline <= now || deadline > now + 60 * 60) {
|
|
563
|
+
throw new Error("ZeroDelta quote deadline is invalid or too far in the future.");
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
// src/core/route.ts
|
|
568
|
+
function routeDeltaLabel(result, quote) {
|
|
569
|
+
if (result.directTransfer) return "~0";
|
|
570
|
+
if (!result.meetsTarget) return "Below requested amount";
|
|
571
|
+
if (result.overageBps > 0) return `+${(result.overageBps / 100).toFixed(2)}% buffer`;
|
|
572
|
+
if (quote.feeBps) return `${quote.feeBps} bps fee`;
|
|
573
|
+
return "~0";
|
|
574
|
+
}
|
|
575
|
+
function routeLabelFor(option, destinationToken, result) {
|
|
576
|
+
if (result.directTransfer) return "Direct transfer: asset and chain already match.";
|
|
577
|
+
const bridge = result.quote.bridge ? ` via ${result.quote.bridge}` : "";
|
|
578
|
+
return `Swap ${option.symbol} to ${destinationToken.symbol} and settle on ZeroDelta${bridge}.`;
|
|
579
|
+
}
|
|
580
|
+
async function buildRoute({ option, destination, destinationToken, chains, payer, fetchQuote, solve = solveExactOut, amountInRaw }) {
|
|
581
|
+
const result = await solve({ option, destination, destinationToken, payer, fetchQuote, amountInRaw });
|
|
582
|
+
const quote = result.quote;
|
|
583
|
+
const destDecimals = assetDecimals(destinationToken);
|
|
584
|
+
const receiveAmount = formatUnits(result.recipientReceivesRaw, destDecimals);
|
|
585
|
+
const sourceAmount = formatUnits(result.youPayRaw, option.decimals);
|
|
586
|
+
if (result.directTransfer) {
|
|
587
|
+
return {
|
|
588
|
+
id: `direct-${option.symbolKey}-${option.chainId}`,
|
|
589
|
+
recommended: false,
|
|
590
|
+
state: "DIRECT",
|
|
591
|
+
source: {
|
|
592
|
+
asset: option.symbol,
|
|
593
|
+
chainId: option.chainId,
|
|
594
|
+
chainName: option.chainName,
|
|
595
|
+
tokenAddress: option.address,
|
|
596
|
+
decimals: option.decimals,
|
|
597
|
+
amount: sourceAmount,
|
|
598
|
+
payAmount: sourceAmount
|
|
599
|
+
},
|
|
600
|
+
receive: {
|
|
601
|
+
asset: destinationToken.symbol,
|
|
602
|
+
chainId: Number(destination.chainId),
|
|
603
|
+
chainName: chainNameOf(Number(destination.chainId), chains),
|
|
604
|
+
tokenAddress: destinationToken.address,
|
|
605
|
+
decimals: destDecimals,
|
|
606
|
+
amount: receiveAmount
|
|
607
|
+
},
|
|
608
|
+
routeLabel: routeLabelFor(option, destinationToken, result),
|
|
609
|
+
deltaLabel: routeDeltaLabel(result, quote),
|
|
610
|
+
transactions: [
|
|
611
|
+
{
|
|
612
|
+
id: "transfer",
|
|
613
|
+
kind: "transfer",
|
|
614
|
+
label: `Transfer ${destinationToken.symbol}`,
|
|
615
|
+
chainId: option.chainId,
|
|
616
|
+
to: option.address,
|
|
617
|
+
data: encodeTransfer(destination.address, result.youPayRaw),
|
|
618
|
+
value: "0x0",
|
|
619
|
+
token: option.address,
|
|
620
|
+
amountRaw: result.youPayRaw
|
|
621
|
+
}
|
|
622
|
+
],
|
|
623
|
+
quote: {
|
|
624
|
+
bridge: quote.bridge,
|
|
625
|
+
feeBps: quote.feeBps,
|
|
626
|
+
estimatedDuration: quote.estimatedDuration,
|
|
627
|
+
iterations: result.iterations
|
|
628
|
+
}
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
if (!quote.orderRequest) throw new Error("ZeroDelta quote did not include an order request.");
|
|
632
|
+
const sourceChain = chainById(chains, option.chainId);
|
|
633
|
+
const escrow = checkEscrow(option.chainId, quote.escrowAddress, sourceChain?.escrowContract);
|
|
634
|
+
const order = normalizeOrderRequest(quote.orderRequest, payer, destination);
|
|
635
|
+
assertQuoteMatchesSelection({ quote, order, option, destinationToken, destination, payer, result });
|
|
636
|
+
const needsNativeFee = requiresNativeBridgeFee(quote, option);
|
|
637
|
+
if (needsNativeFee) {
|
|
638
|
+
let rawFee;
|
|
639
|
+
try {
|
|
640
|
+
rawFee = BigInt(quote.gasCostSource || "0");
|
|
641
|
+
} catch {
|
|
642
|
+
throw new Error("ZeroDelta quote returned an unreadable LayerZero bridge fee; refusing to sign.");
|
|
643
|
+
}
|
|
644
|
+
if (rawFee > maxNativeFeeWei(option.chainId)) {
|
|
645
|
+
throw new Error("LayerZero native fee exceeds the safety cap; refusing to sign.");
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
const valueRaw = applyLayerZeroBuffer(quote, option);
|
|
649
|
+
if (!needsNativeFee) {
|
|
650
|
+
if (valueRaw !== 0n) throw new Error("Non-LayerZero route requested a non-zero native value; refusing to sign.");
|
|
651
|
+
} else if (valueRaw === 0n && Number(quote.executionChainId) > 0) {
|
|
652
|
+
throw new Error("ZeroDelta quote is missing the LayerZero bridge fee for this route; refusing to sign.");
|
|
653
|
+
}
|
|
654
|
+
return {
|
|
655
|
+
id: `zd-${option.symbolKey}-${option.chainId}-${symbolKey(destinationToken.symbol)}-${destination.chainId}`,
|
|
656
|
+
recommended: false,
|
|
657
|
+
state: result.meetsTarget ? "ROUTE" : "SHORT",
|
|
658
|
+
source: {
|
|
659
|
+
asset: option.symbol,
|
|
660
|
+
chainId: option.chainId,
|
|
661
|
+
chainName: option.chainName,
|
|
662
|
+
tokenAddress: option.address,
|
|
663
|
+
decimals: option.decimals,
|
|
664
|
+
amount: sourceAmount,
|
|
665
|
+
payAmount: sourceAmount
|
|
666
|
+
},
|
|
667
|
+
receive: {
|
|
668
|
+
asset: destinationToken.symbol,
|
|
669
|
+
chainId: Number(destination.chainId),
|
|
670
|
+
chainName: chainNameOf(Number(destination.chainId), chains),
|
|
671
|
+
tokenAddress: destinationToken.address,
|
|
672
|
+
decimals: destDecimals,
|
|
673
|
+
amount: receiveAmount
|
|
674
|
+
},
|
|
675
|
+
routeLabel: routeLabelFor(option, destinationToken, result),
|
|
676
|
+
deltaLabel: routeDeltaLabel(result, quote),
|
|
677
|
+
transactions: [
|
|
678
|
+
{
|
|
679
|
+
id: "approve",
|
|
680
|
+
kind: "approve",
|
|
681
|
+
label: `Approve ${option.symbol}`,
|
|
682
|
+
chainId: option.chainId,
|
|
683
|
+
to: option.address,
|
|
684
|
+
data: encodeApprove(escrow, order.bidTokenAmount),
|
|
685
|
+
value: "0x0",
|
|
686
|
+
token: option.address,
|
|
687
|
+
spender: escrow,
|
|
688
|
+
amountRaw: order.bidTokenAmount
|
|
689
|
+
},
|
|
690
|
+
{
|
|
691
|
+
id: "submit-order",
|
|
692
|
+
kind: "submitOrder",
|
|
693
|
+
label: "Submit ZeroDelta order",
|
|
694
|
+
chainId: option.chainId,
|
|
695
|
+
to: escrow,
|
|
696
|
+
data: encodeSubmitOrder(order),
|
|
697
|
+
value: toHexQuantity(valueRaw),
|
|
698
|
+
escrow,
|
|
699
|
+
amountRaw: order.bidTokenAmount
|
|
700
|
+
}
|
|
701
|
+
],
|
|
702
|
+
quote: {
|
|
703
|
+
bridge: quote.bridge,
|
|
704
|
+
feeBps: quote.feeBps,
|
|
705
|
+
estimatedDuration: quote.estimatedDuration,
|
|
706
|
+
gasCostSource: quote.gasCostSource,
|
|
707
|
+
msgValue: valueRaw.toString(),
|
|
708
|
+
deadline: order.deadline,
|
|
709
|
+
iterations: result.iterations
|
|
710
|
+
}
|
|
711
|
+
};
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
// src/core/api.ts
|
|
715
|
+
function apiError(message, props = {}) {
|
|
716
|
+
const err = new Error(message);
|
|
717
|
+
Object.assign(err, props);
|
|
718
|
+
return err;
|
|
719
|
+
}
|
|
720
|
+
function toQuery(params) {
|
|
721
|
+
const entries = Object.entries(params).filter(([, v]) => v !== void 0 && v !== "" && v !== null);
|
|
722
|
+
if (!entries.length) return "";
|
|
723
|
+
return `?${new URLSearchParams(entries.map(([k, v]) => [k, String(v)])).toString()}`;
|
|
724
|
+
}
|
|
725
|
+
var MAX_MESSAGE_LEN = 160;
|
|
726
|
+
function sanitizeMessage(value, fallback) {
|
|
727
|
+
const text = typeof value === "string" ? value.trim() : "";
|
|
728
|
+
if (!text) return fallback;
|
|
729
|
+
const leaksInfra = /(https?:\/\/|\b\w+:\/\/|\b[\w.-]+\.(?:internal|local|amazonaws\.com|vercel\.app)\b|\b\d{1,3}(?:\.\d{1,3}){3}\b|\b[a-z0-9][a-z0-9.-]*\.[a-z]{2,}:\d{2,5}\b|\blocalhost:\d{2,5}\b|[A-Za-z]:\\|\/(?:usr|var|home|opt|etc)\/|\bat\s+\w+\s*\(|\.(?:go|ts|js|py|tsx|jsx):\d+)/i.test(
|
|
730
|
+
text
|
|
731
|
+
);
|
|
732
|
+
if (leaksInfra) return fallback;
|
|
733
|
+
return text.length > MAX_MESSAGE_LEN ? `${text.slice(0, MAX_MESSAGE_LEN - 1)}\u2026` : text;
|
|
734
|
+
}
|
|
735
|
+
function apiMessage(json, fallback) {
|
|
736
|
+
const err = json?.error || json;
|
|
737
|
+
if (err?.fieldErrors?.[0]?.message) return sanitizeMessage(err.fieldErrors[0].message, fallback);
|
|
738
|
+
if (Array.isArray(err?.reasons) && err.reasons.length) {
|
|
739
|
+
const head = sanitizeMessage(err.message, fallback);
|
|
740
|
+
const detail = sanitizeMessage(err.reasons.filter((r) => typeof r === "string").join(", "), "");
|
|
741
|
+
return detail ? `${head}: ${detail}` : head;
|
|
742
|
+
}
|
|
743
|
+
return sanitizeMessage(err?.message, fallback);
|
|
744
|
+
}
|
|
745
|
+
var BLOCK_CATEGORY_LABELS = {
|
|
746
|
+
STOLEN_FUNDS: "flagged as associated with stolen funds",
|
|
747
|
+
SANCTIONS: "on a sanctions list",
|
|
748
|
+
SANCTIONED: "on a sanctions list",
|
|
749
|
+
OFAC: "on a sanctions list",
|
|
750
|
+
TERRORIST_FINANCING: "flagged for terrorist financing",
|
|
751
|
+
FRAUD: "flagged for fraud",
|
|
752
|
+
SCAM: "flagged as a scam address"
|
|
753
|
+
};
|
|
754
|
+
var BLOCK_LABEL_DEFAULT = "flagged by compliance screening";
|
|
755
|
+
function classifyQuoteError(error) {
|
|
756
|
+
if (!error) return null;
|
|
757
|
+
const reasons = Array.isArray(error.reasons) ? error.reasons : [];
|
|
758
|
+
const haystack = `${error.message || ""} ${reasons.join(" ")}`;
|
|
759
|
+
const catMatch = /blocked_category:\s*([A-Za-z_]+)/i.exec(haystack);
|
|
760
|
+
const isBlock = !!catMatch || error.code === "blocked" || error.code === "compliance_block" || /\b(stolen|sanction(?:s|ed|ing)?|block(?:ed|list)|screen(?:ed|ing)?|compliance|ofac|denylist|blacklist)\b/i.test(haystack);
|
|
761
|
+
if (!isBlock) return null;
|
|
762
|
+
const category = (catMatch?.[1] || "").toUpperCase() || "COMPLIANCE";
|
|
763
|
+
const label = BLOCK_CATEGORY_LABELS[category] || BLOCK_LABEL_DEFAULT;
|
|
764
|
+
return {
|
|
765
|
+
blocked: true,
|
|
766
|
+
category,
|
|
767
|
+
reason: reasons.join(", ") || error.message || "",
|
|
768
|
+
message: `This payment was blocked by compliance screening \u2014 the recipient is ${label}. Choose a different recipient or connect a different wallet.`
|
|
769
|
+
};
|
|
770
|
+
}
|
|
771
|
+
function nowFresh(entry) {
|
|
772
|
+
return !!entry && Date.now() - entry.at < API_CACHE_TTL_MS;
|
|
773
|
+
}
|
|
774
|
+
function isTransientQuoteError(error) {
|
|
775
|
+
return error?.code === "gateway_timeout" || error?.status === 502 || error?.status === 503 || error?.status === 504 || /failed to get swap quote|timeout|temporar/i.test(error?.message || "");
|
|
776
|
+
}
|
|
777
|
+
function wait(ms) {
|
|
778
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
779
|
+
}
|
|
780
|
+
function createApiClient(cfg) {
|
|
781
|
+
const cache = {
|
|
782
|
+
chains: null,
|
|
783
|
+
tokens: null,
|
|
784
|
+
routes: null
|
|
785
|
+
};
|
|
786
|
+
const apiBase = cfg.apiBase.replace(/\/$/, "");
|
|
787
|
+
async function apiRequest(path, init = {}) {
|
|
788
|
+
const apiKey = await cfg.getApiKey();
|
|
789
|
+
const headers = { "Content-Type": "application/json", ...init.headers || {} };
|
|
790
|
+
if (apiKey) headers["x-api-key"] = apiKey;
|
|
791
|
+
const controller = new AbortController();
|
|
792
|
+
const timeoutId = setTimeout(() => controller.abort(), init.timeoutMs || 15e3);
|
|
793
|
+
let response;
|
|
794
|
+
try {
|
|
795
|
+
response = await cfg.fetchImpl(`${apiBase}${path}`, { ...init, headers, signal: init.signal || controller.signal });
|
|
796
|
+
} catch (error) {
|
|
797
|
+
throw apiError(error?.name === "AbortError" ? "ZeroDelta request timed out." : error?.message || "ZeroDelta request failed.", {
|
|
798
|
+
code: error?.name === "AbortError" ? "gateway_timeout" : "network_error"
|
|
799
|
+
});
|
|
800
|
+
} finally {
|
|
801
|
+
clearTimeout(timeoutId);
|
|
802
|
+
}
|
|
803
|
+
const text = await response.text();
|
|
804
|
+
let json = null;
|
|
805
|
+
if (text) {
|
|
806
|
+
try {
|
|
807
|
+
json = JSON.parse(text);
|
|
808
|
+
} catch {
|
|
809
|
+
throw apiError(response.ok ? "ZeroDelta returned an invalid response." : `ZeroDelta upstream error (${response.status}).`, {
|
|
810
|
+
status: response.status,
|
|
811
|
+
code: response.status >= 502 ? "gateway_timeout" : "bad_response"
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
if (!response.ok) {
|
|
816
|
+
throw apiError(apiMessage(json, `ZeroDelta request failed (${response.status}).`), {
|
|
817
|
+
status: response.status,
|
|
818
|
+
code: json?.error?.code || json?.code || (response.status >= 502 ? "gateway_timeout" : "api_error"),
|
|
819
|
+
fieldErrors: json?.error?.fieldErrors || json?.fieldErrors,
|
|
820
|
+
reasons: json?.error?.reasons || json?.reasons
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
return json?.data ?? json;
|
|
824
|
+
}
|
|
825
|
+
async function fetchChains() {
|
|
826
|
+
if (nowFresh(cache.chains)) return cache.chains.value;
|
|
827
|
+
const chains = await apiRequest(`/chains${toQuery({ enabledOnly: true, limit: 500 })}`);
|
|
828
|
+
const normalized = (Array.isArray(chains) ? chains : []).map((chain) => ({ ...chain, chainId: Number(chain.chainId) })).map((chain) => {
|
|
829
|
+
const escrow = normalizeAddress(chain.escrowContract);
|
|
830
|
+
return escrow ? { ...chain, escrowContract: escrow } : { ...chain, escrowContract: void 0 };
|
|
831
|
+
});
|
|
832
|
+
cache.chains = { at: Date.now(), value: normalized };
|
|
833
|
+
return normalized;
|
|
834
|
+
}
|
|
835
|
+
async function fetchTokens() {
|
|
836
|
+
if (nowFresh(cache.tokens)) return cache.tokens.value;
|
|
837
|
+
const tokens = await apiRequest(`/tokens${toQuery({ limit: 500 })}`);
|
|
838
|
+
const normalized = (Array.isArray(tokens) ? tokens : []).map((token) => ({ ...token, chainId: Number(token.chainId) }));
|
|
839
|
+
cache.tokens = { at: Date.now(), value: normalized };
|
|
840
|
+
return normalized;
|
|
841
|
+
}
|
|
842
|
+
async function fetchRoutes() {
|
|
843
|
+
if (nowFresh(cache.routes)) return cache.routes.value;
|
|
844
|
+
try {
|
|
845
|
+
const routes = await apiRequest(`/routes${toQuery({ limit: 500 })}`);
|
|
846
|
+
const normalized = Array.isArray(routes) ? routes : [];
|
|
847
|
+
cache.routes = { at: Date.now(), value: normalized };
|
|
848
|
+
return normalized;
|
|
849
|
+
} catch {
|
|
850
|
+
cache.routes = { at: Date.now(), value: [] };
|
|
851
|
+
return [];
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
async function fetchQuote(body, retries = 1) {
|
|
855
|
+
let lastError;
|
|
856
|
+
for (let attempt = 0; attempt <= retries; attempt += 1) {
|
|
857
|
+
try {
|
|
858
|
+
const quote = await apiRequest("/quote", { method: "POST", body: JSON.stringify(body), timeoutMs: 18e3 });
|
|
859
|
+
return quote && quote.executionChainId != null ? { ...quote, executionChainId: Number(quote.executionChainId) } : quote;
|
|
860
|
+
} catch (error) {
|
|
861
|
+
lastError = error;
|
|
862
|
+
if (attempt >= retries || !isTransientQuoteError(error)) throw error;
|
|
863
|
+
await wait(1400);
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
throw lastError;
|
|
867
|
+
}
|
|
868
|
+
return { apiRequest, fetchChains, fetchTokens, fetchRoutes, fetchQuote, apiBase };
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
// src/core/plan.ts
|
|
872
|
+
function validateDestination(destination) {
|
|
873
|
+
assertAddress(destination.address, "Destination address");
|
|
874
|
+
const chainId = Number(destination.chainId);
|
|
875
|
+
const asset = symbolKey(destination.asset);
|
|
876
|
+
if (!SUPPORTED_CHAIN_IDS.has(chainId)) throw new Error("Unsupported destination chain.");
|
|
877
|
+
if (!SUPPORTED_ASSETS.has(asset)) throw new Error("Unsupported destination asset.");
|
|
878
|
+
const normalizedAmount = normalizeDecimalText(destination.amount);
|
|
879
|
+
if (!/^\d+(\.\d+)?$/.test(normalizedAmount)) throw new Error("Could not detect a valid payment amount.");
|
|
880
|
+
if (Number(normalizedAmount) <= 0 || Number(normalizedAmount) > 1e9) throw new Error("Payment amount is outside the supported range.");
|
|
881
|
+
destination.amount = normalizedAmount;
|
|
882
|
+
}
|
|
883
|
+
function planErrorSummary(errors) {
|
|
884
|
+
const unique = [...new Set(errors.map((error) => error?.message || String(error)).filter(Boolean))].slice(0, 3);
|
|
885
|
+
return unique.length ? unique.join(" | ") : "No ZeroDelta route is currently available for this payment.";
|
|
886
|
+
}
|
|
887
|
+
async function fetchPaymentPlan(api, request, payer, wallet = {}) {
|
|
888
|
+
validateDestination(request);
|
|
889
|
+
assertAddress(payer, "Payer wallet");
|
|
890
|
+
const [chains, tokens, routes] = await Promise.all([api.fetchChains(), api.fetchTokens(), api.fetchRoutes()]);
|
|
891
|
+
const destination = {
|
|
892
|
+
...request,
|
|
893
|
+
chainId: Number(request.chainId),
|
|
894
|
+
asset: symbolKey(request.asset)
|
|
895
|
+
};
|
|
896
|
+
const destinationToken = findToken(tokens, destination.chainId, destination.asset);
|
|
897
|
+
if (!destinationToken) throw new Error(`${destination.asset} is not enabled on ${chainNameOf(destination.chainId, chains)}.`);
|
|
898
|
+
const options = buildPayOptions({
|
|
899
|
+
invoiceAsset: destination.asset,
|
|
900
|
+
invoiceChainId: destination.chainId,
|
|
901
|
+
tokens,
|
|
902
|
+
routes,
|
|
903
|
+
chains,
|
|
904
|
+
walletChainId: wallet?.chainId
|
|
905
|
+
});
|
|
906
|
+
if (!options.length) throw new Error(`No enabled ZeroDelta funding assets can settle ${destination.asset} on ${chainNameOf(destination.chainId, chains)}.`);
|
|
907
|
+
const candidates = options.filter((option) => option.direct);
|
|
908
|
+
const seenChains = /* @__PURE__ */ new Set();
|
|
909
|
+
const perChainBest = [];
|
|
910
|
+
const leftovers = [];
|
|
911
|
+
for (const option of options) {
|
|
912
|
+
if (option.direct) continue;
|
|
913
|
+
if (seenChains.has(option.chainId)) {
|
|
914
|
+
leftovers.push(option);
|
|
915
|
+
} else {
|
|
916
|
+
seenChains.add(option.chainId);
|
|
917
|
+
perChainBest.push(option);
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
for (const option of [...perChainBest, ...leftovers].slice(0, MAX_QUOTE_CANDIDATES)) {
|
|
921
|
+
candidates.push(option);
|
|
922
|
+
}
|
|
923
|
+
const routeErrors = [];
|
|
924
|
+
const routePromises = candidates.map(
|
|
925
|
+
(option) => buildRoute({ option, destination, destinationToken, chains, payer, fetchQuote: api.fetchQuote }).catch((error) => {
|
|
926
|
+
routeErrors.push(error);
|
|
927
|
+
return null;
|
|
928
|
+
})
|
|
929
|
+
);
|
|
930
|
+
const routesBuilt = (await Promise.all(routePromises)).filter(Boolean);
|
|
931
|
+
routesBuilt.sort((a, b) => {
|
|
932
|
+
const walletChain = Number(wallet?.chainId || 0);
|
|
933
|
+
if (a.state !== "SHORT" && b.state === "SHORT") return -1;
|
|
934
|
+
if (b.state !== "SHORT" && a.state === "SHORT") return 1;
|
|
935
|
+
if (walletChain) {
|
|
936
|
+
if (a.source.chainId === walletChain && b.source.chainId !== walletChain) return -1;
|
|
937
|
+
if (b.source.chainId === walletChain && a.source.chainId !== walletChain) return 1;
|
|
938
|
+
}
|
|
939
|
+
if (a.state !== b.state) return a.state === "DIRECT" ? -1 : b.state === "DIRECT" ? 1 : 0;
|
|
940
|
+
return Number(a.quote?.feeBps || 0) - Number(b.quote?.feeBps || 0);
|
|
941
|
+
});
|
|
942
|
+
const recommended = routesBuilt.find((route) => route.state !== "SHORT");
|
|
943
|
+
if (recommended) recommended.recommended = true;
|
|
944
|
+
if (!routesBuilt.length || !recommended) {
|
|
945
|
+
const blocked = routeErrors.map(classifyQuoteError).find(Boolean);
|
|
946
|
+
if (blocked) throw apiError(blocked.message, { blocked: true, blockedCategory: blocked.category, blockedReason: blocked.reason });
|
|
947
|
+
throw new Error(planErrorSummary(routeErrors));
|
|
948
|
+
}
|
|
949
|
+
return {
|
|
950
|
+
mode: "zerodelta",
|
|
951
|
+
requestId: `zd_${Date.now().toString(36)}_${Math.random().toString(16).slice(2, 10)}`,
|
|
952
|
+
expiresAt: new Date(Date.now() + 2 * 60 * 1e3).toISOString(),
|
|
953
|
+
apiBase: api.apiBase,
|
|
954
|
+
routes: routesBuilt,
|
|
955
|
+
destination: {
|
|
956
|
+
asset: destinationToken.symbol,
|
|
957
|
+
chainId: destination.chainId,
|
|
958
|
+
chainName: chainNameOf(destination.chainId, chains),
|
|
959
|
+
tokenAddress: destinationToken.address,
|
|
960
|
+
decimals: assetDecimals(destinationToken),
|
|
961
|
+
amount: destination.amount,
|
|
962
|
+
address: destination.address
|
|
963
|
+
}
|
|
964
|
+
};
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
// src/core/swap.ts
|
|
968
|
+
function validateSwap(swap = {}) {
|
|
969
|
+
const fromChainId = Number(swap.fromChainId);
|
|
970
|
+
const toChainId = Number(swap.toChainId);
|
|
971
|
+
const fromToken = symbolKey(swap.fromToken);
|
|
972
|
+
const toToken = symbolKey(swap.toToken);
|
|
973
|
+
if (!SUPPORTED_CHAIN_IDS.has(fromChainId) || !SUPPORTED_CHAIN_IDS.has(toChainId)) throw new Error("Unsupported swap chain.");
|
|
974
|
+
if (!SUPPORTED_ASSETS.has(fromToken) || !SUPPORTED_ASSETS.has(toToken)) throw new Error("Unsupported swap asset.");
|
|
975
|
+
const amountIn = normalizeDecimalText(swap.amountIn);
|
|
976
|
+
if (!/^\d+(\.\d+)?$/.test(amountIn) || Number(amountIn) <= 0 || Number(amountIn) > 1e9) throw new Error("Enter a valid swap amount.");
|
|
977
|
+
return { fromChainId, toChainId, fromToken, toToken, amountIn };
|
|
978
|
+
}
|
|
979
|
+
async function quoteSwapPreview(api, swap, owner) {
|
|
980
|
+
const v = validateSwap(swap);
|
|
981
|
+
const tokens = await api.fetchTokens();
|
|
982
|
+
const sourceToken = findToken(tokens, v.fromChainId, v.fromToken);
|
|
983
|
+
const destToken = findToken(tokens, v.toChainId, v.toToken);
|
|
984
|
+
if (!sourceToken) throw new Error(`${v.fromToken} is not enabled on that source chain.`);
|
|
985
|
+
if (!destToken) throw new Error(`${v.toToken} is not enabled on that destination chain.`);
|
|
986
|
+
const amountInRaw = parseUnitsDecimal(v.amountIn, assetDecimals(sourceToken));
|
|
987
|
+
const account = normalizeAddress(owner) || PREVIEW_OWNER;
|
|
988
|
+
const previewReceiver = normalizeAddress(swap.recipient) || account;
|
|
989
|
+
const quote = await api.fetchQuote({
|
|
990
|
+
fromChainId: v.fromChainId,
|
|
991
|
+
toChainId: v.toChainId,
|
|
992
|
+
fromToken: sourceToken.symbol,
|
|
993
|
+
toToken: destToken.symbol,
|
|
994
|
+
fromAmount: amountInRaw.toString(),
|
|
995
|
+
owner: account,
|
|
996
|
+
destinationReceiver: previewReceiver
|
|
997
|
+
});
|
|
998
|
+
const final = finalOf(quote);
|
|
999
|
+
return {
|
|
1000
|
+
receive: formatUnits(final, assetDecimals(destToken)),
|
|
1001
|
+
receiveRaw: final.toString(),
|
|
1002
|
+
fromAmount: v.amountIn,
|
|
1003
|
+
fromToken: sourceToken.symbol,
|
|
1004
|
+
toToken: destToken.symbol,
|
|
1005
|
+
bridge: quote.bridge || "",
|
|
1006
|
+
feeBps: Number(quote.feeBps || 0),
|
|
1007
|
+
estimatedDuration: Number(quote.estimatedDuration || 0)
|
|
1008
|
+
};
|
|
1009
|
+
}
|
|
1010
|
+
async function buildSwapPlan(api, swap, payer, wallet = {}) {
|
|
1011
|
+
const v = validateSwap(swap);
|
|
1012
|
+
const account = assertAddress(payer, "Swap wallet");
|
|
1013
|
+
const [chains, tokens] = await Promise.all([api.fetchChains(), api.fetchTokens()]);
|
|
1014
|
+
const sourceToken = findToken(tokens, v.fromChainId, v.fromToken);
|
|
1015
|
+
const destToken = findToken(tokens, v.toChainId, v.toToken);
|
|
1016
|
+
if (!sourceToken) throw new Error(`${v.fromToken} is not enabled on ${chainNameOf(v.fromChainId, chains)}.`);
|
|
1017
|
+
if (!destToken) throw new Error(`${v.toToken} is not enabled on ${chainNameOf(v.toChainId, chains)}.`);
|
|
1018
|
+
const amountInRaw = parseUnitsDecimal(v.amountIn, assetDecimals(sourceToken));
|
|
1019
|
+
const receiver = resolveSwapReceiver(swap.recipient, account);
|
|
1020
|
+
const option = {
|
|
1021
|
+
symbol: sourceToken.symbol,
|
|
1022
|
+
symbolKey: symbolKey(sourceToken.symbol),
|
|
1023
|
+
name: sourceToken.name || sourceToken.symbol,
|
|
1024
|
+
chainId: v.fromChainId,
|
|
1025
|
+
chainName: chainNameOf(v.fromChainId, chains),
|
|
1026
|
+
address: sourceToken.address,
|
|
1027
|
+
decimals: assetDecimals(sourceToken),
|
|
1028
|
+
// Carry the source token's bridge through: it is the inbound (source -> execution chain) leg,
|
|
1029
|
+
// which is what decides whether the escrow order owes a native LayerZero fee. buildPayOptions
|
|
1030
|
+
// sets this for the Pay flow; omitting it here left the Swap flow with no bridge signal at all.
|
|
1031
|
+
bridge: sourceToken.bridge,
|
|
1032
|
+
direct: false
|
|
1033
|
+
};
|
|
1034
|
+
const destination = { address: receiver, chainId: v.toChainId, asset: destToken.symbol };
|
|
1035
|
+
const route = await buildRoute({ option, destination, destinationToken: destToken, chains, payer: account, fetchQuote: api.fetchQuote, solve: solveExactIn, amountInRaw });
|
|
1036
|
+
if (route.state === "SHORT") throw new Error("ZeroDelta could not price this swap right now.");
|
|
1037
|
+
route.recommended = true;
|
|
1038
|
+
return {
|
|
1039
|
+
mode: "swap",
|
|
1040
|
+
requestId: `zdswap_${Date.now().toString(36)}`,
|
|
1041
|
+
expiresAt: new Date(Date.now() + 2 * 60 * 1e3).toISOString(),
|
|
1042
|
+
apiBase: api.apiBase,
|
|
1043
|
+
routes: [route],
|
|
1044
|
+
destination: {
|
|
1045
|
+
asset: destToken.symbol,
|
|
1046
|
+
chainId: v.toChainId,
|
|
1047
|
+
chainName: chainNameOf(v.toChainId, chains),
|
|
1048
|
+
tokenAddress: destToken.address,
|
|
1049
|
+
decimals: assetDecimals(destToken),
|
|
1050
|
+
amount: route.receive.amount,
|
|
1051
|
+
address: receiver
|
|
1052
|
+
}
|
|
1053
|
+
};
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
// src/core/validate-tx.ts
|
|
1057
|
+
var lower = (v) => String(v || "").toLowerCase();
|
|
1058
|
+
function isHexAddress(value) {
|
|
1059
|
+
return /^0x[a-fA-F0-9]{40}$/.test(String(value || ""));
|
|
1060
|
+
}
|
|
1061
|
+
function isHexData(value) {
|
|
1062
|
+
return /^0x(?:[a-fA-F0-9]{2})*$/.test(String(value));
|
|
1063
|
+
}
|
|
1064
|
+
function isHexQuantity(value) {
|
|
1065
|
+
return /^0x[0-9a-fA-F]+$/.test(String(value));
|
|
1066
|
+
}
|
|
1067
|
+
function dataWord(data, index) {
|
|
1068
|
+
const word = String(data || "").slice(10 + index * 64, 10 + (index + 1) * 64);
|
|
1069
|
+
return /^[a-fA-F0-9]{64}$/.test(word) ? word : "";
|
|
1070
|
+
}
|
|
1071
|
+
function dataAddress(data, index) {
|
|
1072
|
+
const word = dataWord(data, index);
|
|
1073
|
+
return word ? `0x${word.slice(24)}` : "";
|
|
1074
|
+
}
|
|
1075
|
+
function dataUint(data, index) {
|
|
1076
|
+
const word = dataWord(data, index);
|
|
1077
|
+
return word ? BigInt(`0x${word}`) : null;
|
|
1078
|
+
}
|
|
1079
|
+
function rawEquals(value, expected) {
|
|
1080
|
+
try {
|
|
1081
|
+
return value === BigInt(expected || "0");
|
|
1082
|
+
} catch {
|
|
1083
|
+
return false;
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
function planMsgValueHex(route) {
|
|
1087
|
+
try {
|
|
1088
|
+
const raw = route?.quote?.msgValue;
|
|
1089
|
+
if (raw === void 0 || raw === null || raw === "") return "0x0";
|
|
1090
|
+
return "0x" + BigInt(raw).toString(16);
|
|
1091
|
+
} catch {
|
|
1092
|
+
return null;
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
function validatePlannedTransaction(tx, route, expectedRecipient) {
|
|
1096
|
+
if (!tx || tx.mock) return true;
|
|
1097
|
+
if (!isHexAddress(tx.to) || !isHexData(tx.data || "0x") || !isHexQuantity(tx.value || "0x0")) return false;
|
|
1098
|
+
const data = String(tx.data || "0x").toLowerCase();
|
|
1099
|
+
const selector = data.slice(0, 10);
|
|
1100
|
+
const value = lower(tx.value || "0x0");
|
|
1101
|
+
if (tx.kind === "transfer") {
|
|
1102
|
+
if (value !== "0x0") return false;
|
|
1103
|
+
return selector === "0xa9059cbb" && isHexAddress(tx.token) && lower(tx.to) === lower(tx.token) && lower(dataAddress(data, 0)) === lower(expectedRecipient) && rawEquals(dataUint(data, 1), tx.amountRaw);
|
|
1104
|
+
}
|
|
1105
|
+
if (tx.kind === "approve") {
|
|
1106
|
+
if (value !== "0x0") return false;
|
|
1107
|
+
return selector === "0x095ea7b3" && isHexAddress(tx.token) && isHexAddress(tx.spender) && lower(tx.to) === lower(tx.token) && lower(dataAddress(data, 0)) === lower(tx.spender) && rawEquals(dataUint(data, 1), tx.amountRaw);
|
|
1108
|
+
}
|
|
1109
|
+
if (tx.kind === "submitOrder") {
|
|
1110
|
+
const expected = planMsgValueHex(route);
|
|
1111
|
+
if (expected === null || value !== lower(expected)) return false;
|
|
1112
|
+
return selector === "0xbbd71141" && isHexAddress(tx.escrow) && lower(tx.to) === lower(tx.escrow);
|
|
1113
|
+
}
|
|
1114
|
+
return false;
|
|
1115
|
+
}
|
|
1116
|
+
async function allowanceCovers(tx, account, ethCall2) {
|
|
1117
|
+
if (tx?.kind !== "approve" || !tx.token || !tx.spender || !tx.amountRaw || !account) return false;
|
|
1118
|
+
try {
|
|
1119
|
+
const raw = await ethCall2(tx.token, encodeAllowance(account, tx.spender));
|
|
1120
|
+
return BigInt(raw || "0x0") >= BigInt(tx.amountRaw || "0");
|
|
1121
|
+
} catch {
|
|
1122
|
+
return false;
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
// src/core/verify.ts
|
|
1127
|
+
var TX_VERIFY_ATTEMPTS = 5;
|
|
1128
|
+
var TX_VERIFY_INTERVAL_MS = 2500;
|
|
1129
|
+
var TX_VERIFY_FETCH_MS = 5e3;
|
|
1130
|
+
var TX_VERIFY_DEADLINE_MS = 18e3;
|
|
1131
|
+
function registryRpc(chain) {
|
|
1132
|
+
if (!chain) return "";
|
|
1133
|
+
const candidates = [chain.rpcUrl, Array.isArray(chain.rpcUrls) ? chain.rpcUrls[0] : null, chain.publicRpcUrl, chain.rpc, chain.rpcEndpoint];
|
|
1134
|
+
const found = candidates.find((url) => typeof url === "string" && /^https:\/\//i.test(url));
|
|
1135
|
+
return found || "";
|
|
1136
|
+
}
|
|
1137
|
+
function txMatchesPlan(tx, plan) {
|
|
1138
|
+
if (!tx) return false;
|
|
1139
|
+
const wantFrom = normalizeAddress(plan.from);
|
|
1140
|
+
if (!wantFrom || normalizeAddress(tx.from) !== wantFrom) return false;
|
|
1141
|
+
const wantTo = normalizeAddress(plan.to);
|
|
1142
|
+
if (wantTo && normalizeAddress(tx.to) !== wantTo) return false;
|
|
1143
|
+
const wantData = String(plan.data || "0x").toLowerCase();
|
|
1144
|
+
const gotData = String(tx.input || tx.data || "0x").toLowerCase();
|
|
1145
|
+
if (wantData !== "0x" && gotData !== wantData) return false;
|
|
1146
|
+
if (plan.value !== void 0 && plan.value !== null) {
|
|
1147
|
+
try {
|
|
1148
|
+
if (BigInt(tx.value || "0x0") !== BigInt(plan.value || "0x0")) return false;
|
|
1149
|
+
} catch {
|
|
1150
|
+
return false;
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
if (typeof plan.minNonce !== "number") return false;
|
|
1154
|
+
let n;
|
|
1155
|
+
try {
|
|
1156
|
+
n = Number(BigInt(tx.nonce));
|
|
1157
|
+
} catch {
|
|
1158
|
+
return false;
|
|
1159
|
+
}
|
|
1160
|
+
if (n < plan.minNonce) return false;
|
|
1161
|
+
return true;
|
|
1162
|
+
}
|
|
1163
|
+
function createVerifier(api, fetchImpl, rpcOverrides = {}) {
|
|
1164
|
+
async function chainRpcUrl(chainId) {
|
|
1165
|
+
const override = rpcOverrides[Number(chainId)];
|
|
1166
|
+
if (override && /^https?:\/\//i.test(override)) return override;
|
|
1167
|
+
const bundled = BUNDLED_RPC[Number(chainId)];
|
|
1168
|
+
if (bundled) return bundled;
|
|
1169
|
+
const chains = await api.fetchChains().catch(() => []);
|
|
1170
|
+
return registryRpc(chainById(chains, Number(chainId)));
|
|
1171
|
+
}
|
|
1172
|
+
async function rpcCall(rpcUrl, method, params) {
|
|
1173
|
+
const response = await fetchImpl(rpcUrl, {
|
|
1174
|
+
method: "POST",
|
|
1175
|
+
headers: { "Content-Type": "application/json" },
|
|
1176
|
+
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method, params }),
|
|
1177
|
+
signal: AbortSignal.timeout(TX_VERIFY_FETCH_MS)
|
|
1178
|
+
});
|
|
1179
|
+
if (!response.ok) throw new Error(`RPC ${response.status}`);
|
|
1180
|
+
const json = await response.json();
|
|
1181
|
+
return json?.result ?? null;
|
|
1182
|
+
}
|
|
1183
|
+
async function payerNonceBaseline(chainId, account) {
|
|
1184
|
+
if (!isAddress(account)) return null;
|
|
1185
|
+
const rpcUrl = await chainRpcUrl(chainId);
|
|
1186
|
+
if (!rpcUrl) return null;
|
|
1187
|
+
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
1188
|
+
try {
|
|
1189
|
+
const hex = await rpcCall(rpcUrl, "eth_getTransactionCount", [normalizeAddress(account), "latest"]);
|
|
1190
|
+
if (typeof hex === "string") return Number(BigInt(hex));
|
|
1191
|
+
} catch {
|
|
1192
|
+
}
|
|
1193
|
+
if (attempt < 2) await new Promise((resolve) => setTimeout(resolve, 1500));
|
|
1194
|
+
}
|
|
1195
|
+
return null;
|
|
1196
|
+
}
|
|
1197
|
+
async function verifySubmittedTx({ chainId, hash, from, to, data, value, minNonce }) {
|
|
1198
|
+
if (!/^0x[0-9a-fA-F]{64}$/.test(String(hash || ""))) return { status: "mismatch" };
|
|
1199
|
+
if (!normalizeAddress(from) || typeof minNonce !== "number") return { status: "unconfirmed", reason: "no-binding" };
|
|
1200
|
+
const rpcUrl = await chainRpcUrl(chainId);
|
|
1201
|
+
if (!rpcUrl) return { status: "unconfirmed", reason: "no-rpc" };
|
|
1202
|
+
const plan = { from, to, data, value, minNonce };
|
|
1203
|
+
const deadline = Date.now() + TX_VERIFY_DEADLINE_MS;
|
|
1204
|
+
let matched = false;
|
|
1205
|
+
for (let attempt = 0; attempt < TX_VERIFY_ATTEMPTS && Date.now() < deadline; attempt += 1) {
|
|
1206
|
+
if (!matched) {
|
|
1207
|
+
let tx = null;
|
|
1208
|
+
try {
|
|
1209
|
+
tx = await rpcCall(rpcUrl, "eth_getTransactionByHash", [hash]);
|
|
1210
|
+
} catch {
|
|
1211
|
+
tx = null;
|
|
1212
|
+
}
|
|
1213
|
+
if (tx) {
|
|
1214
|
+
if (!txMatchesPlan(tx, plan)) return { status: "mismatch" };
|
|
1215
|
+
matched = true;
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
if (matched) {
|
|
1219
|
+
let receipt = null;
|
|
1220
|
+
try {
|
|
1221
|
+
receipt = await rpcCall(rpcUrl, "eth_getTransactionReceipt", [hash]);
|
|
1222
|
+
} catch {
|
|
1223
|
+
receipt = null;
|
|
1224
|
+
}
|
|
1225
|
+
if (receipt && receipt.status != null) {
|
|
1226
|
+
const code = String(receipt.status).toLowerCase();
|
|
1227
|
+
if (code === "0x0" || code === "0x00" || code === "0") return { status: "reverted" };
|
|
1228
|
+
return { status: "confirmed" };
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
if (attempt < TX_VERIFY_ATTEMPTS - 1 && Date.now() + TX_VERIFY_INTERVAL_MS < deadline) {
|
|
1232
|
+
await new Promise((resolve) => setTimeout(resolve, TX_VERIFY_INTERVAL_MS));
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
return { status: "unconfirmed", reason: matched ? "pending" : "not-found" };
|
|
1236
|
+
}
|
|
1237
|
+
async function balanceRpcUrl(chainId) {
|
|
1238
|
+
const override = rpcOverrides[Number(chainId)];
|
|
1239
|
+
if (override && /^https?:\/\//i.test(override)) return override;
|
|
1240
|
+
const bundled = BUNDLED_RPC[Number(chainId)];
|
|
1241
|
+
if (bundled) return bundled;
|
|
1242
|
+
const chains = await api.fetchChains().catch(() => []);
|
|
1243
|
+
return registryRpc(chainById(chains, Number(chainId)));
|
|
1244
|
+
}
|
|
1245
|
+
async function readBalances(account, targets) {
|
|
1246
|
+
const out = {};
|
|
1247
|
+
if (!isAddress(account) || !Array.isArray(targets) || !targets.length) return out;
|
|
1248
|
+
const owner = normalizeAddress(account);
|
|
1249
|
+
const CONCURRENCY = 6;
|
|
1250
|
+
let cursor = 0;
|
|
1251
|
+
async function worker() {
|
|
1252
|
+
while (cursor < targets.length) {
|
|
1253
|
+
const target = targets[cursor++];
|
|
1254
|
+
if (!target || !isAddress(target.tokenAddress)) continue;
|
|
1255
|
+
const key = `${Number(target.chainId)}:${String(target.tokenAddress).toLowerCase()}`;
|
|
1256
|
+
try {
|
|
1257
|
+
const rpcUrl = await balanceRpcUrl(Number(target.chainId));
|
|
1258
|
+
if (!rpcUrl) continue;
|
|
1259
|
+
const hex = await rpcCall(rpcUrl, "eth_call", [{ to: normalizeAddress(target.tokenAddress), data: encodeBalanceOf(owner) }, "latest"]);
|
|
1260
|
+
if (typeof hex !== "string" || !/^0x[0-9a-fA-F]*$/.test(hex)) continue;
|
|
1261
|
+
const raw = BigInt(hex || "0x0").toString();
|
|
1262
|
+
out[key] = { raw, formatted: formatUnits(raw, Number(target.decimals)) };
|
|
1263
|
+
} catch {
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
await Promise.all(Array.from({ length: Math.min(CONCURRENCY, targets.length) }, () => worker()));
|
|
1268
|
+
return out;
|
|
1269
|
+
}
|
|
1270
|
+
async function readNativeBalance(chainId, account) {
|
|
1271
|
+
if (!isAddress(account)) return null;
|
|
1272
|
+
try {
|
|
1273
|
+
const rpcUrl = await balanceRpcUrl(Number(chainId));
|
|
1274
|
+
if (!rpcUrl) return null;
|
|
1275
|
+
const hex = await rpcCall(rpcUrl, "eth_getBalance", [normalizeAddress(account), "latest"]);
|
|
1276
|
+
if (typeof hex !== "string" || !/^0x[0-9a-fA-F]*$/.test(hex)) return null;
|
|
1277
|
+
return BigInt(hex || "0x0");
|
|
1278
|
+
} catch {
|
|
1279
|
+
return null;
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
return { payerNonceBaseline, verifySubmittedTx, readBalances, readNativeBalance };
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
// src/core/config.ts
|
|
1286
|
+
function parseAllowedApiBase(value) {
|
|
1287
|
+
try {
|
|
1288
|
+
const url = new URL(String(value || ""));
|
|
1289
|
+
const localDev = url.protocol === "http:" && /^(localhost|127\.0\.0\.1)$/i.test(url.hostname);
|
|
1290
|
+
if (url.protocol !== "https:" && !localDev) return null;
|
|
1291
|
+
url.hash = "";
|
|
1292
|
+
url.search = "";
|
|
1293
|
+
return url.toString().replace(/\/$/, "");
|
|
1294
|
+
} catch {
|
|
1295
|
+
return null;
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
function isSameOriginPath(value) {
|
|
1299
|
+
return value.startsWith("/") && !value.startsWith("//") && !value.startsWith("/\\");
|
|
1300
|
+
}
|
|
1301
|
+
function resolveApiBase(value) {
|
|
1302
|
+
const raw = value ?? DEFAULT_WIDGET_API_BASE;
|
|
1303
|
+
if (isSameOriginPath(raw)) return raw.replace(/\/+$/, "") || "/";
|
|
1304
|
+
return parseAllowedApiBase(raw) || DEFAULT_WIDGET_API_BASE;
|
|
1305
|
+
}
|
|
1306
|
+
function canAttachApiKey(apiBase, trustedOrigin) {
|
|
1307
|
+
if (isSameOriginPath(apiBase)) return true;
|
|
1308
|
+
if (apiBase.startsWith("/")) return false;
|
|
1309
|
+
if (!trustedOrigin) return false;
|
|
1310
|
+
try {
|
|
1311
|
+
const trusted = parseAllowedApiBase(trustedOrigin);
|
|
1312
|
+
if (!trusted) return false;
|
|
1313
|
+
return new URL(apiBase).origin === new URL(trusted).origin;
|
|
1314
|
+
} catch {
|
|
1315
|
+
return false;
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
function resolveConfig(config = {}) {
|
|
1319
|
+
const apiBase = resolveApiBase(config.apiBase);
|
|
1320
|
+
const fetchImpl = config.fetchImpl ?? globalThis.fetch?.bind(globalThis);
|
|
1321
|
+
if (typeof fetchImpl !== "function") {
|
|
1322
|
+
throw new Error("No fetch implementation available; pass EngineConfig.fetchImpl.");
|
|
1323
|
+
}
|
|
1324
|
+
const getApiKey = async () => {
|
|
1325
|
+
if (!canAttachApiKey(apiBase, config.trustedApiOrigin)) return "";
|
|
1326
|
+
if (config.getApiKey) return String(await config.getApiKey() || "");
|
|
1327
|
+
return String(config.apiKey || "");
|
|
1328
|
+
};
|
|
1329
|
+
return {
|
|
1330
|
+
apiBase,
|
|
1331
|
+
getApiKey,
|
|
1332
|
+
fetchImpl,
|
|
1333
|
+
rpcOverrides: config.rpcOverrides ?? {},
|
|
1334
|
+
onTransaction: config.onTransaction
|
|
1335
|
+
};
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
// src/core/index.ts
|
|
1339
|
+
function sanitizeTxEntry(entry) {
|
|
1340
|
+
return {
|
|
1341
|
+
kind: entry.kind === "swap" ? "swap" : "payment",
|
|
1342
|
+
hash: /^0x[0-9a-fA-F]{6,80}$/.test(String(entry.hash || "")) ? String(entry.hash) : "",
|
|
1343
|
+
txKind: entry.txKind === "transfer" || entry.txKind === "approve" || entry.txKind === "submitOrder" ? entry.txKind : void 0,
|
|
1344
|
+
chainId: Number(entry.chainId) || null,
|
|
1345
|
+
chainName: String(entry.chainName || "").slice(0, 40),
|
|
1346
|
+
fromAsset: String(entry.fromAsset || "").slice(0, 10),
|
|
1347
|
+
toAsset: String(entry.toAsset || "").slice(0, 10),
|
|
1348
|
+
payAmount: String(entry.payAmount || "").slice(0, 40),
|
|
1349
|
+
receiveAmount: String(entry.receiveAmount || "").slice(0, 40),
|
|
1350
|
+
account: isAddress(entry.account) ? normalizeAddress(entry.account) : "",
|
|
1351
|
+
recipient: isAddress(entry.recipient) ? normalizeAddress(entry.recipient) : "",
|
|
1352
|
+
settlement: entry.settlement === "direct" ? "direct" : "escrow",
|
|
1353
|
+
status: entry.status && ["confirmed", "unconfirmed", "error"].includes(entry.status) ? entry.status : "submitted",
|
|
1354
|
+
at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1355
|
+
};
|
|
1356
|
+
}
|
|
1357
|
+
function createEngine(config = {}) {
|
|
1358
|
+
const resolved = resolveConfig(config);
|
|
1359
|
+
const api = createApiClient(resolved);
|
|
1360
|
+
const verifier = createVerifier(api, resolved.fetchImpl, resolved.rpcOverrides);
|
|
1361
|
+
return {
|
|
1362
|
+
api,
|
|
1363
|
+
verifier,
|
|
1364
|
+
apiBase: api.apiBase,
|
|
1365
|
+
fetchChains: api.fetchChains,
|
|
1366
|
+
fetchTokens: api.fetchTokens,
|
|
1367
|
+
fetchRoutes: api.fetchRoutes,
|
|
1368
|
+
fetchQuote: api.fetchQuote,
|
|
1369
|
+
fetchPaymentPlan: (request, payer, wallet) => fetchPaymentPlan(api, request, payer, wallet),
|
|
1370
|
+
quoteSwapPreview: (swap, owner) => quoteSwapPreview(api, swap, owner),
|
|
1371
|
+
buildSwapPlan: (swap, payer, wallet) => buildSwapPlan(api, swap, payer, wallet),
|
|
1372
|
+
payerNonceBaseline: verifier.payerNonceBaseline,
|
|
1373
|
+
verifySubmittedTx: verifier.verifySubmittedTx,
|
|
1374
|
+
readBalances: verifier.readBalances,
|
|
1375
|
+
readNativeBalance: verifier.readNativeBalance,
|
|
1376
|
+
recordTransaction: (entry) => {
|
|
1377
|
+
const clean = sanitizeTxEntry(entry);
|
|
1378
|
+
try {
|
|
1379
|
+
resolved.onTransaction?.(clean);
|
|
1380
|
+
} catch {
|
|
1381
|
+
}
|
|
1382
|
+
return clean;
|
|
1383
|
+
}
|
|
1384
|
+
};
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
// src/react/hooks/useEngine.ts
|
|
1388
|
+
function useEngine(config) {
|
|
1389
|
+
return react.useMemo(
|
|
1390
|
+
() => createEngine(config),
|
|
1391
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1392
|
+
[config.apiBase, config.apiKey, config.trustedApiOrigin]
|
|
1393
|
+
);
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1396
|
+
// src/provider/eip1193.ts
|
|
1397
|
+
function discoverProviders(timeoutMs = 300) {
|
|
1398
|
+
return new Promise((resolve) => {
|
|
1399
|
+
if (typeof window === "undefined") return resolve([]);
|
|
1400
|
+
const found = /* @__PURE__ */ new Map();
|
|
1401
|
+
const onAnnounce = (event) => {
|
|
1402
|
+
const detail = event.detail;
|
|
1403
|
+
if (detail?.info?.uuid && detail.provider) found.set(detail.info.uuid, detail);
|
|
1404
|
+
};
|
|
1405
|
+
window.addEventListener("eip6963:announceProvider", onAnnounce);
|
|
1406
|
+
window.dispatchEvent(new Event("eip6963:requestProvider"));
|
|
1407
|
+
setTimeout(() => {
|
|
1408
|
+
window.removeEventListener("eip6963:announceProvider", onAnnounce);
|
|
1409
|
+
resolve([...found.values()]);
|
|
1410
|
+
}, timeoutMs);
|
|
1411
|
+
});
|
|
1412
|
+
}
|
|
1413
|
+
function legacyProvider() {
|
|
1414
|
+
if (typeof window === "undefined") return null;
|
|
1415
|
+
const eth = window.ethereum;
|
|
1416
|
+
if (!eth) return null;
|
|
1417
|
+
if (Array.isArray(eth.providers) && eth.providers.length) return eth.providers[0];
|
|
1418
|
+
return eth;
|
|
1419
|
+
}
|
|
1420
|
+
async function resolveProvider(injected2) {
|
|
1421
|
+
if (injected2) return injected2;
|
|
1422
|
+
const details = await discoverProviders();
|
|
1423
|
+
if (details.length) return details[0].provider;
|
|
1424
|
+
const legacy = legacyProvider();
|
|
1425
|
+
if (legacy) return legacy;
|
|
1426
|
+
throw new Error("No EVM wallet found. Install MetaMask, Rabby, or another EIP-1193 wallet.");
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
// src/provider/wallet.ts
|
|
1430
|
+
function chainHex(chainId) {
|
|
1431
|
+
return `0x${Number(chainId).toString(16)}`;
|
|
1432
|
+
}
|
|
1433
|
+
function hexToChain(hex) {
|
|
1434
|
+
if (typeof hex !== "string") return typeof hex === "number" ? hex : null;
|
|
1435
|
+
return Number.parseInt(hex, 16);
|
|
1436
|
+
}
|
|
1437
|
+
async function getAccounts(provider) {
|
|
1438
|
+
const accounts = await provider.request({ method: "eth_accounts" });
|
|
1439
|
+
return Array.isArray(accounts) ? accounts : [];
|
|
1440
|
+
}
|
|
1441
|
+
async function requestAccounts(provider) {
|
|
1442
|
+
const accounts = await provider.request({ method: "eth_requestAccounts" });
|
|
1443
|
+
return Array.isArray(accounts) ? accounts : [];
|
|
1444
|
+
}
|
|
1445
|
+
async function getChainId(provider) {
|
|
1446
|
+
return hexToChain(await provider.request({ method: "eth_chainId" }));
|
|
1447
|
+
}
|
|
1448
|
+
var NATIVE_CURRENCY = {
|
|
1449
|
+
1: { chainName: "Ethereum", name: "Ether", symbol: "ETH" },
|
|
1450
|
+
10: { chainName: "Optimism", name: "Ether", symbol: "ETH" },
|
|
1451
|
+
130: { chainName: "Unichain", name: "Ether", symbol: "ETH" },
|
|
1452
|
+
146: { chainName: "Sonic", name: "Sonic", symbol: "S" },
|
|
1453
|
+
8453: { chainName: "Base", name: "Ether", symbol: "ETH" },
|
|
1454
|
+
9745: { chainName: "Plasma", name: "Plasma", symbol: "XPL" },
|
|
1455
|
+
57073: { chainName: "Ink", name: "Ether", symbol: "ETH" },
|
|
1456
|
+
42161: { chainName: "Arbitrum One", name: "Ether", symbol: "ETH" }
|
|
1457
|
+
};
|
|
1458
|
+
function addChainParams(chainId) {
|
|
1459
|
+
const meta = NATIVE_CURRENCY[chainId];
|
|
1460
|
+
const rpc = BUNDLED_RPC[chainId];
|
|
1461
|
+
if (!meta || !rpc) return null;
|
|
1462
|
+
return {
|
|
1463
|
+
chainId: chainHex(chainId),
|
|
1464
|
+
chainName: meta.chainName,
|
|
1465
|
+
nativeCurrency: { name: meta.name, symbol: meta.symbol, decimals: 18 },
|
|
1466
|
+
rpcUrls: [rpc]
|
|
1467
|
+
};
|
|
1468
|
+
}
|
|
1469
|
+
function rpcErrorCode(err) {
|
|
1470
|
+
let cur = err;
|
|
1471
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1472
|
+
while (cur && typeof cur === "object" && !seen.has(cur)) {
|
|
1473
|
+
seen.add(cur);
|
|
1474
|
+
const e = cur;
|
|
1475
|
+
if (typeof e.data?.originalError?.code === "number") return e.data.originalError.code;
|
|
1476
|
+
if (typeof e.code === "number") return e.code;
|
|
1477
|
+
cur = e.cause;
|
|
1478
|
+
}
|
|
1479
|
+
return void 0;
|
|
1480
|
+
}
|
|
1481
|
+
async function switchChain(provider, chainId) {
|
|
1482
|
+
try {
|
|
1483
|
+
await provider.request({ method: "wallet_switchEthereumChain", params: [{ chainId: chainHex(chainId) }] });
|
|
1484
|
+
} catch (err) {
|
|
1485
|
+
const params = addChainParams(chainId);
|
|
1486
|
+
if (rpcErrorCode(err) === 4902 && params) {
|
|
1487
|
+
await provider.request({ method: "wallet_addEthereumChain", params: [params] });
|
|
1488
|
+
await provider.request({ method: "wallet_switchEthereumChain", params: [{ chainId: chainHex(chainId) }] });
|
|
1489
|
+
return;
|
|
1490
|
+
}
|
|
1491
|
+
throw err;
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
function shortWalletMessage(err) {
|
|
1495
|
+
if (err && typeof err === "object") {
|
|
1496
|
+
const e = err;
|
|
1497
|
+
if (typeof e.shortMessage === "string" && e.shortMessage) return e.shortMessage;
|
|
1498
|
+
if (typeof e.message === "string" && e.message) return e.message;
|
|
1499
|
+
}
|
|
1500
|
+
return void 0;
|
|
1501
|
+
}
|
|
1502
|
+
function normalizeWalletError(err, fallback = "Transaction failed.") {
|
|
1503
|
+
if (!err) return fallback;
|
|
1504
|
+
const code = rpcErrorCode(err);
|
|
1505
|
+
const name = err && typeof err === "object" && "name" in err ? err.name : void 0;
|
|
1506
|
+
if (code === -32002) return "Open your wallet \u2014 a request is already pending.";
|
|
1507
|
+
if (code === 4001 || name === "UserRejectedRequestError") return "Request was rejected in your wallet.";
|
|
1508
|
+
if (code === 4902) return "This chain isn't set up in your wallet. Approve adding it and try again.";
|
|
1509
|
+
if (code === -32603) return shortWalletMessage(err) || "Your wallet returned an internal error. Try again.";
|
|
1510
|
+
return shortWalletMessage(err) || fallback;
|
|
1511
|
+
}
|
|
1512
|
+
async function sendTransaction(provider, tx) {
|
|
1513
|
+
const hash = await provider.request({
|
|
1514
|
+
method: "eth_sendTransaction",
|
|
1515
|
+
params: [{ from: tx.from, to: tx.to, data: tx.data, value: tx.value || "0x0" }]
|
|
1516
|
+
});
|
|
1517
|
+
return hash;
|
|
1518
|
+
}
|
|
1519
|
+
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
1520
|
+
async function waitForReceipt(provider, hash, opts = {}) {
|
|
1521
|
+
const timeoutMs = opts.timeoutMs ?? 9e4;
|
|
1522
|
+
const pollMs = opts.pollMs ?? 2500;
|
|
1523
|
+
const deadline = Date.now() + timeoutMs;
|
|
1524
|
+
for (; ; ) {
|
|
1525
|
+
let receipt = null;
|
|
1526
|
+
try {
|
|
1527
|
+
receipt = await provider.request({ method: "eth_getTransactionReceipt", params: [hash] });
|
|
1528
|
+
} catch {
|
|
1529
|
+
}
|
|
1530
|
+
if (receipt && receipt.status != null) {
|
|
1531
|
+
const status = String(receipt.status).toLowerCase();
|
|
1532
|
+
if (status === "0x0" || status === "0x00" || status === "0") {
|
|
1533
|
+
throw new Error("A transaction reverted on-chain before settlement. Nothing was submitted \u2014 please try again.");
|
|
1534
|
+
}
|
|
1535
|
+
return;
|
|
1536
|
+
}
|
|
1537
|
+
if (Date.now() >= deadline) {
|
|
1538
|
+
throw new Error("Timed out waiting for the transaction to confirm. Check your wallet and try again.");
|
|
1539
|
+
}
|
|
1540
|
+
await sleep(pollMs);
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
async function ethCall(provider, to, data) {
|
|
1544
|
+
return await provider.request({ method: "eth_call", params: [{ to, data }, "latest"] });
|
|
1545
|
+
}
|
|
1546
|
+
async function nativeBalance(provider, account) {
|
|
1547
|
+
try {
|
|
1548
|
+
const raw = await provider.request({ method: "eth_getBalance", params: [account, "latest"] });
|
|
1549
|
+
if (typeof raw !== "string" || !/^0x[0-9a-fA-F]*$/.test(raw)) return null;
|
|
1550
|
+
return BigInt(raw || "0x0");
|
|
1551
|
+
} catch {
|
|
1552
|
+
return null;
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
// src/react/hooks/useWallet.ts
|
|
1557
|
+
function useWallet(injected2) {
|
|
1558
|
+
const [provider, setProvider] = react.useState(injected2 ?? null);
|
|
1559
|
+
const [account, setAccount] = react.useState(null);
|
|
1560
|
+
const [chainId, setChainId] = react.useState(null);
|
|
1561
|
+
const [connecting, setConnecting] = react.useState(false);
|
|
1562
|
+
const [error, setError] = react.useState(null);
|
|
1563
|
+
const providerRef = react.useRef(injected2 ?? null);
|
|
1564
|
+
react.useEffect(() => {
|
|
1565
|
+
const p = provider;
|
|
1566
|
+
if (!p) return;
|
|
1567
|
+
let alive = true;
|
|
1568
|
+
const onAccounts = (accs) => alive && setAccount(Array.isArray(accs) && accs[0] ? accs[0] : null);
|
|
1569
|
+
const onChain = (hex) => alive && setChainId(hexToChain(hex));
|
|
1570
|
+
p.on?.("accountsChanged", onAccounts);
|
|
1571
|
+
p.on?.("chainChanged", onChain);
|
|
1572
|
+
(async () => {
|
|
1573
|
+
try {
|
|
1574
|
+
const accs = await getAccounts(p);
|
|
1575
|
+
if (alive && accs[0]) setAccount(accs[0]);
|
|
1576
|
+
const cid = await getChainId(p);
|
|
1577
|
+
if (alive) setChainId(cid);
|
|
1578
|
+
} catch {
|
|
1579
|
+
}
|
|
1580
|
+
})();
|
|
1581
|
+
return () => {
|
|
1582
|
+
alive = false;
|
|
1583
|
+
p.removeListener?.("accountsChanged", onAccounts);
|
|
1584
|
+
p.removeListener?.("chainChanged", onChain);
|
|
1585
|
+
};
|
|
1586
|
+
}, [provider]);
|
|
1587
|
+
react.useEffect(() => {
|
|
1588
|
+
if (injected2 && injected2 !== providerRef.current) {
|
|
1589
|
+
providerRef.current = injected2;
|
|
1590
|
+
setProvider(injected2);
|
|
1591
|
+
}
|
|
1592
|
+
}, [injected2]);
|
|
1593
|
+
const connect = react.useCallback(async () => {
|
|
1594
|
+
setConnecting(true);
|
|
1595
|
+
setError(null);
|
|
1596
|
+
try {
|
|
1597
|
+
const p = providerRef.current ?? await resolveProvider(injected2);
|
|
1598
|
+
providerRef.current = p;
|
|
1599
|
+
setProvider(p);
|
|
1600
|
+
const accs = await requestAccounts(p);
|
|
1601
|
+
setAccount(accs[0] ?? null);
|
|
1602
|
+
setChainId(await getChainId(p));
|
|
1603
|
+
} catch (e) {
|
|
1604
|
+
setError(normalizeWalletError(e, "Could not connect a wallet."));
|
|
1605
|
+
} finally {
|
|
1606
|
+
setConnecting(false);
|
|
1607
|
+
}
|
|
1608
|
+
}, [injected2]);
|
|
1609
|
+
return { provider, account, chainId, connecting, error, connect };
|
|
1610
|
+
}
|
|
1611
|
+
|
|
1612
|
+
// src/react/txHistoryStore.ts
|
|
1613
|
+
var TX_HISTORY_EVENT = "sg:txhistory";
|
|
1614
|
+
var TX_HISTORY_LIMIT = 50;
|
|
1615
|
+
function defaultStorage() {
|
|
1616
|
+
try {
|
|
1617
|
+
return typeof window !== "undefined" ? window.localStorage : null;
|
|
1618
|
+
} catch {
|
|
1619
|
+
return null;
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
function validAccount(account) {
|
|
1623
|
+
return typeof account === "string" && /^0x[0-9a-fA-F]{40}$/.test(account);
|
|
1624
|
+
}
|
|
1625
|
+
function txHistoryKey(account) {
|
|
1626
|
+
return `sg:txh:v1:${account.toLowerCase()}`;
|
|
1627
|
+
}
|
|
1628
|
+
function isEntry(v) {
|
|
1629
|
+
if (!v || typeof v !== "object") return false;
|
|
1630
|
+
const e = v;
|
|
1631
|
+
return typeof e.hash === "string" && e.hash.length > 0 && typeof e.at === "string" && typeof e.status === "string";
|
|
1632
|
+
}
|
|
1633
|
+
function readTxHistory(account, storage2 = defaultStorage()) {
|
|
1634
|
+
if (!storage2 || !validAccount(account)) return [];
|
|
1635
|
+
try {
|
|
1636
|
+
const raw = storage2.getItem(txHistoryKey(account));
|
|
1637
|
+
if (!raw) return [];
|
|
1638
|
+
const parsed = JSON.parse(raw);
|
|
1639
|
+
return Array.isArray(parsed) ? parsed.filter(isEntry) : [];
|
|
1640
|
+
} catch {
|
|
1641
|
+
return [];
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
function appendTxHistory(account, entry, storage2 = defaultStorage()) {
|
|
1645
|
+
const current = readTxHistory(account, storage2);
|
|
1646
|
+
if (!storage2 || !validAccount(account) || !entry || !entry.hash) return current;
|
|
1647
|
+
const next = [entry, ...current.filter((e) => e.hash !== entry.hash)].slice(0, TX_HISTORY_LIMIT);
|
|
1648
|
+
try {
|
|
1649
|
+
storage2.setItem(txHistoryKey(account), JSON.stringify(next));
|
|
1650
|
+
} catch {
|
|
1651
|
+
return current;
|
|
1652
|
+
}
|
|
1653
|
+
try {
|
|
1654
|
+
if (typeof window !== "undefined") window.dispatchEvent(new CustomEvent(TX_HISTORY_EVENT, { detail: { account: account.toLowerCase() } }));
|
|
1655
|
+
} catch {
|
|
1656
|
+
}
|
|
1657
|
+
return next;
|
|
1658
|
+
}
|
|
1659
|
+
|
|
1660
|
+
// src/react/hooks/useFlow.ts
|
|
1661
|
+
function useFlow(args) {
|
|
1662
|
+
const { engine, wallet, kind, enabled, paramsKey, loadPlan, recipientFor, onQuote, onSuccess, onError } = args;
|
|
1663
|
+
const [status, setStatus] = react.useState("idle");
|
|
1664
|
+
const [plan, setPlan] = react.useState(null);
|
|
1665
|
+
const [selectedId, setSelectedId] = react.useState(null);
|
|
1666
|
+
const [error, setError] = react.useState(null);
|
|
1667
|
+
const [insufficient, setInsufficient] = react.useState(false);
|
|
1668
|
+
const [nativeShortfall, setNativeShortfall] = react.useState(null);
|
|
1669
|
+
const [steps, setSteps] = react.useState([]);
|
|
1670
|
+
const [verdict, setVerdict] = react.useState(null);
|
|
1671
|
+
const [txHash, setTxHash] = react.useState(null);
|
|
1672
|
+
const [lastTxEntry, setLastTxEntry] = react.useState(null);
|
|
1673
|
+
const [nonce, setNonce] = react.useState(0);
|
|
1674
|
+
const reqId = react.useRef(0);
|
|
1675
|
+
const busyRef = react.useRef(false);
|
|
1676
|
+
const routes = plan?.routes ?? [];
|
|
1677
|
+
const selected = react.useMemo(() => routes.find((r) => r.id === selectedId) ?? routes.find((r) => r.recommended) ?? routes[0] ?? null, [routes, selectedId]);
|
|
1678
|
+
const reload = react.useCallback(() => setNonce((n) => n + 1), []);
|
|
1679
|
+
react.useEffect(() => {
|
|
1680
|
+
if (busyRef.current) return;
|
|
1681
|
+
if (!enabled || !wallet.account) {
|
|
1682
|
+
setStatus("idle");
|
|
1683
|
+
setPlan(null);
|
|
1684
|
+
return;
|
|
1685
|
+
}
|
|
1686
|
+
const id = ++reqId.current;
|
|
1687
|
+
setStatus("loading");
|
|
1688
|
+
setError(null);
|
|
1689
|
+
setVerdict(null);
|
|
1690
|
+
setTxHash(null);
|
|
1691
|
+
setLastTxEntry(null);
|
|
1692
|
+
(async () => {
|
|
1693
|
+
try {
|
|
1694
|
+
const p = await loadPlan(engine, wallet.account, wallet.chainId ?? void 0);
|
|
1695
|
+
if (id !== reqId.current) return;
|
|
1696
|
+
setPlan(p);
|
|
1697
|
+
setSelectedId(p.routes.find((r) => r.recommended)?.id ?? p.routes[0]?.id ?? null);
|
|
1698
|
+
setStatus("ready");
|
|
1699
|
+
onQuote?.(p);
|
|
1700
|
+
} catch (e) {
|
|
1701
|
+
if (id !== reqId.current) return;
|
|
1702
|
+
setPlan(null);
|
|
1703
|
+
setError(e?.message || "Could not price this right now.");
|
|
1704
|
+
setStatus("error");
|
|
1705
|
+
onError?.(e instanceof Error ? e : new Error(String(e)));
|
|
1706
|
+
}
|
|
1707
|
+
})();
|
|
1708
|
+
}, [enabled, wallet.account, wallet.chainId, paramsKey, nonce]);
|
|
1709
|
+
react.useEffect(() => {
|
|
1710
|
+
let alive = true;
|
|
1711
|
+
setInsufficient(false);
|
|
1712
|
+
const src = selected?.source;
|
|
1713
|
+
if (!wallet.account || !src?.tokenAddress || src.decimals == null) return;
|
|
1714
|
+
(async () => {
|
|
1715
|
+
try {
|
|
1716
|
+
const key = `${Number(src.chainId)}:${String(src.tokenAddress).toLowerCase()}`;
|
|
1717
|
+
const balances = await engine.readBalances(wallet.account, [
|
|
1718
|
+
{ chainId: Number(src.chainId), tokenAddress: src.tokenAddress, decimals: Number(src.decimals) }
|
|
1719
|
+
]);
|
|
1720
|
+
const entry = balances[key];
|
|
1721
|
+
if (!entry) return;
|
|
1722
|
+
const need = parseUnitsDecimal(src.payAmount || src.amount, src.decimals);
|
|
1723
|
+
if (alive) setInsufficient(BigInt(entry.raw) < need);
|
|
1724
|
+
} catch {
|
|
1725
|
+
}
|
|
1726
|
+
})();
|
|
1727
|
+
return () => {
|
|
1728
|
+
alive = false;
|
|
1729
|
+
};
|
|
1730
|
+
}, [engine, wallet.account, selected]);
|
|
1731
|
+
react.useEffect(() => {
|
|
1732
|
+
let alive = true;
|
|
1733
|
+
setNativeShortfall(null);
|
|
1734
|
+
const account = wallet.account;
|
|
1735
|
+
const src = selected?.source;
|
|
1736
|
+
if (!account || !src || routeNativeValue(selected) <= 0n) return;
|
|
1737
|
+
(async () => {
|
|
1738
|
+
try {
|
|
1739
|
+
const [balance, chains] = await Promise.all([
|
|
1740
|
+
engine.readNativeBalance(Number(src.chainId), account),
|
|
1741
|
+
engine.fetchChains().catch(() => [])
|
|
1742
|
+
]);
|
|
1743
|
+
if (!alive) return;
|
|
1744
|
+
const check = checkNativeFee(selected, balance);
|
|
1745
|
+
setNativeShortfall(nativeFeeShortLabel(check, nativeSymbol(Number(src.chainId), chains)));
|
|
1746
|
+
} catch {
|
|
1747
|
+
}
|
|
1748
|
+
})();
|
|
1749
|
+
return () => {
|
|
1750
|
+
alive = false;
|
|
1751
|
+
};
|
|
1752
|
+
}, [engine, wallet.account, selected]);
|
|
1753
|
+
const submit = react.useCallback(async () => {
|
|
1754
|
+
if (busyRef.current) return;
|
|
1755
|
+
const route = selected;
|
|
1756
|
+
const provider = wallet.provider;
|
|
1757
|
+
const account = wallet.account;
|
|
1758
|
+
if (!route || !provider || !account) return;
|
|
1759
|
+
busyRef.current = true;
|
|
1760
|
+
const recipient = recipientFor(account);
|
|
1761
|
+
const sourceChainId = route.source.chainId;
|
|
1762
|
+
const txSteps = route.transactions.map((tx) => ({ id: tx.id, label: tx.label, state: "pending" }));
|
|
1763
|
+
txSteps.push({ id: "verify", label: "Confirm on-chain", state: "pending" });
|
|
1764
|
+
setSteps(txSteps);
|
|
1765
|
+
setStatus("submitting");
|
|
1766
|
+
setError(null);
|
|
1767
|
+
setVerdict(null);
|
|
1768
|
+
const patch = (id, s, hash) => setSteps((prev) => prev.map((st) => st.id === id ? { ...st, state: s, ...hash ? { hash } : {} } : st));
|
|
1769
|
+
try {
|
|
1770
|
+
const current = await getChainId(provider);
|
|
1771
|
+
if (current !== Number(sourceChainId)) {
|
|
1772
|
+
await switchChain(provider, Number(sourceChainId));
|
|
1773
|
+
const after = await getChainId(provider);
|
|
1774
|
+
if (after !== Number(sourceChainId)) throw new Error("Wallet did not switch to the source chain.");
|
|
1775
|
+
}
|
|
1776
|
+
if (routeNativeValue(route) > 0n) {
|
|
1777
|
+
const check = checkNativeFee(route, await nativeBalance(provider, account));
|
|
1778
|
+
if (check.short) {
|
|
1779
|
+
const chains = await engine.fetchChains().catch(() => []);
|
|
1780
|
+
throw new Error(nativeFeeShortMessage(check, nativeSymbol(Number(sourceChainId), chains), route.source.chainName));
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
const minNonce = await engine.payerNonceBaseline(Number(sourceChainId), account);
|
|
1784
|
+
const txs = route.transactions;
|
|
1785
|
+
let settleHash = "";
|
|
1786
|
+
let settleTx = txs[txs.length - 1];
|
|
1787
|
+
for (let i = 0; i < txs.length; i++) {
|
|
1788
|
+
const tx = txs[i];
|
|
1789
|
+
const isFinal = i === txs.length - 1;
|
|
1790
|
+
if (tx.mock) {
|
|
1791
|
+
patch(tx.id, "done");
|
|
1792
|
+
continue;
|
|
1793
|
+
}
|
|
1794
|
+
if (tx.kind === "approve" && await allowanceCovers(tx, account, (to, data) => ethCall(provider, to, data))) {
|
|
1795
|
+
patch(tx.id, "done");
|
|
1796
|
+
continue;
|
|
1797
|
+
}
|
|
1798
|
+
if (!validatePlannedTransaction(tx, route, recipient)) {
|
|
1799
|
+
throw new Error(`Refusing to sign a ${tx.kind} that does not match the reviewed plan.`);
|
|
1800
|
+
}
|
|
1801
|
+
patch(tx.id, "active");
|
|
1802
|
+
const hash = await sendTransaction(provider, { from: account, to: tx.to, data: tx.data, value: tx.value });
|
|
1803
|
+
if (!isFinal) {
|
|
1804
|
+
await waitForReceipt(provider, hash);
|
|
1805
|
+
}
|
|
1806
|
+
patch(tx.id, "done", hash);
|
|
1807
|
+
if (tx.kind !== "approve") {
|
|
1808
|
+
settleHash = hash;
|
|
1809
|
+
settleTx = tx;
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
patch("verify", "active");
|
|
1813
|
+
const v = settleHash ? await engine.verifySubmittedTx({ chainId: Number(sourceChainId), hash: settleHash, from: account, to: settleTx.to, data: settleTx.data, value: settleTx.value, minNonce: minNonce ?? void 0 }) : { status: "unconfirmed" };
|
|
1814
|
+
setVerdict(v);
|
|
1815
|
+
setTxHash(settleHash || null);
|
|
1816
|
+
patch("verify", v.status === "confirmed" ? "done" : v.status === "mismatch" || v.status === "reverted" ? "error" : "active");
|
|
1817
|
+
const entry = engine.recordTransaction({
|
|
1818
|
+
kind,
|
|
1819
|
+
hash: settleHash,
|
|
1820
|
+
txKind: settleTx.kind,
|
|
1821
|
+
chainId: Number(sourceChainId),
|
|
1822
|
+
chainName: route.source.chainName,
|
|
1823
|
+
fromAsset: route.source.asset,
|
|
1824
|
+
toAsset: route.receive.asset,
|
|
1825
|
+
payAmount: route.source.payAmount,
|
|
1826
|
+
receiveAmount: route.receive.amount,
|
|
1827
|
+
account,
|
|
1828
|
+
recipient,
|
|
1829
|
+
settlement: route.state === "DIRECT" ? "direct" : "escrow",
|
|
1830
|
+
status: v.status === "confirmed" ? "confirmed" : v.status === "mismatch" || v.status === "reverted" ? "error" : "unconfirmed"
|
|
1831
|
+
});
|
|
1832
|
+
setLastTxEntry(entry.hash ? entry : null);
|
|
1833
|
+
appendTxHistory(account, entry);
|
|
1834
|
+
if (v.status === "mismatch") {
|
|
1835
|
+
setStatus("error");
|
|
1836
|
+
setError("The submitted transaction did not match the reviewed plan.");
|
|
1837
|
+
onError?.(new Error("tx mismatch"));
|
|
1838
|
+
} else if (v.status === "reverted") {
|
|
1839
|
+
setStatus("error");
|
|
1840
|
+
setError("The transaction reverted on-chain. Your funds were not sent \u2014 please try again.");
|
|
1841
|
+
onError?.(new Error("tx reverted"));
|
|
1842
|
+
} else if (v.status === "confirmed") {
|
|
1843
|
+
setStatus("success");
|
|
1844
|
+
onSuccess?.({ hash: settleHash, verdict: v, route });
|
|
1845
|
+
} else {
|
|
1846
|
+
setStatus("pending");
|
|
1847
|
+
setError(null);
|
|
1848
|
+
}
|
|
1849
|
+
} catch (e) {
|
|
1850
|
+
setStatus("error");
|
|
1851
|
+
setError(normalizeWalletError(e));
|
|
1852
|
+
setSteps((prev) => prev.map((st) => st.state === "active" ? { ...st, state: "error" } : st));
|
|
1853
|
+
onError?.(e instanceof Error ? e : new Error(String(e)));
|
|
1854
|
+
} finally {
|
|
1855
|
+
busyRef.current = false;
|
|
1856
|
+
}
|
|
1857
|
+
}, [selected, wallet.provider, wallet.account, engine, kind, recipientFor, onSuccess, onError]);
|
|
1858
|
+
return {
|
|
1859
|
+
status,
|
|
1860
|
+
plan,
|
|
1861
|
+
routes,
|
|
1862
|
+
selected,
|
|
1863
|
+
selectRoute: setSelectedId,
|
|
1864
|
+
error,
|
|
1865
|
+
insufficient,
|
|
1866
|
+
nativeShortfall,
|
|
1867
|
+
steps,
|
|
1868
|
+
verdict,
|
|
1869
|
+
txHash,
|
|
1870
|
+
lastTxEntry,
|
|
1871
|
+
submit,
|
|
1872
|
+
reload
|
|
1873
|
+
};
|
|
1874
|
+
}
|
|
1875
|
+
function balanceKey(chainId, tokenAddress) {
|
|
1876
|
+
return `${Number(chainId)}:${String(tokenAddress || "").toLowerCase()}`;
|
|
1877
|
+
}
|
|
1878
|
+
function useHoldings(engine, account, routes) {
|
|
1879
|
+
const [balances, setBalances] = react.useState({});
|
|
1880
|
+
const [loading, setLoading] = react.useState(false);
|
|
1881
|
+
const reqId = react.useRef(0);
|
|
1882
|
+
const targets = react.useMemo(() => {
|
|
1883
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1884
|
+
const list = [];
|
|
1885
|
+
for (const r of routes) {
|
|
1886
|
+
const s = r.source;
|
|
1887
|
+
if (!s?.tokenAddress || s.decimals == null) continue;
|
|
1888
|
+
const k = balanceKey(s.chainId, s.tokenAddress);
|
|
1889
|
+
if (seen.has(k)) continue;
|
|
1890
|
+
seen.add(k);
|
|
1891
|
+
list.push({ chainId: s.chainId, tokenAddress: s.tokenAddress, decimals: s.decimals });
|
|
1892
|
+
}
|
|
1893
|
+
return list;
|
|
1894
|
+
}, [routes]);
|
|
1895
|
+
const targetsKey = react.useMemo(() => targets.map((t) => balanceKey(t.chainId, t.tokenAddress)).join("|"), [targets]);
|
|
1896
|
+
react.useEffect(() => {
|
|
1897
|
+
if (!account || !targets.length) {
|
|
1898
|
+
setBalances({});
|
|
1899
|
+
setLoading(false);
|
|
1900
|
+
return;
|
|
1901
|
+
}
|
|
1902
|
+
const id = ++reqId.current;
|
|
1903
|
+
setLoading(true);
|
|
1904
|
+
(async () => {
|
|
1905
|
+
try {
|
|
1906
|
+
const res = await engine.readBalances(account, targets);
|
|
1907
|
+
if (id !== reqId.current) return;
|
|
1908
|
+
setBalances(res);
|
|
1909
|
+
} catch {
|
|
1910
|
+
if (id === reqId.current) setBalances({});
|
|
1911
|
+
} finally {
|
|
1912
|
+
if (id === reqId.current) setLoading(false);
|
|
1913
|
+
}
|
|
1914
|
+
})();
|
|
1915
|
+
}, [engine, account, targetsKey]);
|
|
1916
|
+
return { balances, loading };
|
|
1917
|
+
}
|
|
1918
|
+
|
|
1919
|
+
// src/react/styles.ts
|
|
1920
|
+
var WIDGET_CSS = `
|
|
1921
|
+
.sg-widget{box-sizing:border-box;width:100%;max-width:400px;margin:0 auto;padding:20px;background:var(--sg-bg);color:var(--sg-text);border:1px solid var(--sg-border);border-radius:var(--sg-radius);font-family:var(--sg-font);font-size:15px;line-height:1.5;box-shadow:0 1px 2px rgba(16,17,22,.04),0 8px 24px rgba(16,17,22,.06)}
|
|
1922
|
+
.sg-widget *{box-sizing:border-box}
|
|
1923
|
+
:root[data-theme="dark"] .sg-widget,.sg-widget[data-sg-mode="dark"]{box-shadow:0 8px 24px rgba(0,0,0,.4)}
|
|
1924
|
+
|
|
1925
|
+
.sg-head{display:flex;align-items:center;justify-content:space-between;margin-bottom:16px}
|
|
1926
|
+
.sg-title{font-size:15px;font-weight:600;letter-spacing:-0.01em}
|
|
1927
|
+
.sg-brand{display:inline-flex;align-items:center;gap:5px;font-size:11px;color:var(--sg-text-muted);text-transform:uppercase;letter-spacing:0.08em}
|
|
1928
|
+
.sg-brand-mark{flex:0 0 auto;display:block}
|
|
1929
|
+
|
|
1930
|
+
.sg-label{display:block;font-size:12px;color:var(--sg-text-muted);margin-bottom:6px}
|
|
1931
|
+
.sg-panel{background:var(--sg-surface);border:1px solid var(--sg-border);border-radius:var(--sg-radius-control);padding:16px}
|
|
1932
|
+
.sg-panel + .sg-panel{margin-top:12px}
|
|
1933
|
+
.sg-row{display:flex;gap:10px;align-items:center}
|
|
1934
|
+
.sg-row>*{min-width:0}
|
|
1935
|
+
.sg-grow{flex:1 1 auto}
|
|
1936
|
+
.sg-muted{color:var(--sg-text-muted)}
|
|
1937
|
+
.sg-mono{font-variant-numeric:tabular-nums}
|
|
1938
|
+
.sg-strong{font-weight:600}
|
|
1939
|
+
|
|
1940
|
+
/* invariant anchor */
|
|
1941
|
+
.sg-anchor{font-size:30px;font-weight:700;line-height:1.1;font-variant-numeric:tabular-nums;letter-spacing:-0.01em}
|
|
1942
|
+
.sg-anchor-sub{font-size:12px;color:var(--sg-text-muted);margin-top:4px}
|
|
1943
|
+
|
|
1944
|
+
/* inputs */
|
|
1945
|
+
.sg-input,.sg-select{width:100%;padding:10px 12px;background:var(--sg-bg);color:var(--sg-text);border:1px solid var(--sg-border);border-radius:var(--sg-radius-control);font:inherit;outline:none;transition:border-color 120ms ease}
|
|
1946
|
+
.sg-input:focus,.sg-select:focus{border-color:var(--sg-accent)}
|
|
1947
|
+
.sg-amount{font-size:28px;font-weight:700;border:none;background:transparent;padding:0}
|
|
1948
|
+
.sg-amount:focus{border:none}
|
|
1949
|
+
.sg-field{margin-bottom:12px}
|
|
1950
|
+
.sg-reverse{display:flex;align-items:center;justify-content:center;width:34px;height:34px;margin:-6px auto;position:relative;z-index:1;border-radius:var(--sg-radius-control);border:1px solid var(--sg-border);background:var(--sg-bg);color:var(--sg-text-muted);cursor:pointer;transition:color 120ms ease,border-color 120ms ease}
|
|
1951
|
+
.sg-reverse:hover{color:var(--sg-accent);border-color:var(--sg-accent)}
|
|
1952
|
+
|
|
1953
|
+
/* method tabs (segmented) */
|
|
1954
|
+
.sg-tabs{display:flex;gap:6px;margin:14px 0 10px;overflow-x:auto;scrollbar-width:none;padding-bottom:2px}
|
|
1955
|
+
.sg-tabs::-webkit-scrollbar{display:none}
|
|
1956
|
+
.sg-tab{flex:0 0 auto;display:inline-flex;align-items:center;gap:5px;padding:7px 12px;border:1px solid var(--sg-border);background:var(--sg-bg);color:var(--sg-text-muted);border-radius:var(--sg-radius-cta);font:inherit;font-size:13px;font-weight:500;cursor:pointer;white-space:nowrap;transition:background 120ms ease,color 120ms ease,border-color 120ms ease}
|
|
1957
|
+
.sg-tab:hover:not([disabled]):not([data-selected="true"]){color:var(--sg-text)}
|
|
1958
|
+
.sg-tab[data-selected="true"]{background:color-mix(in srgb,var(--sg-accent) 12%,transparent);border-color:color-mix(in srgb,var(--sg-accent) 45%,transparent);color:var(--sg-accent)}
|
|
1959
|
+
.sg-tab[disabled]{opacity:.5;cursor:not-allowed}
|
|
1960
|
+
.sg-soon{font-size:9px;font-weight:700;text-transform:uppercase;letter-spacing:.05em;padding:1px 5px;border-radius:999px;background:var(--sg-surface);color:var(--sg-text-muted)}
|
|
1961
|
+
|
|
1962
|
+
.sg-why{font-size:12px;color:var(--sg-text-muted);margin:0 2px 10px}
|
|
1963
|
+
|
|
1964
|
+
/* route radio list */
|
|
1965
|
+
.sg-route{display:flex;flex-direction:column;gap:8px}
|
|
1966
|
+
.sg-route-item{display:flex;align-items:center;gap:12px;padding:12px;border:1px solid var(--sg-border);border-radius:var(--sg-radius-control);background:var(--sg-bg);cursor:pointer;transition:border-color 120ms ease,box-shadow 120ms ease}
|
|
1967
|
+
.sg-route-item:hover{border-color:color-mix(in srgb,var(--sg-accent) 40%,var(--sg-border))}
|
|
1968
|
+
.sg-route-item[data-selected="true"]{border-color:var(--sg-accent);box-shadow:0 0 0 1px var(--sg-accent) inset}
|
|
1969
|
+
.sg-route-item:focus-visible{outline:2px solid var(--sg-accent);outline-offset:2px}
|
|
1970
|
+
.sg-chip{flex:0 0 auto;width:40px;height:40px;border-radius:var(--sg-radius-control);background:var(--sg-surface);border:1px solid var(--sg-border);display:flex;flex-direction:column;align-items:center;justify-content:center;line-height:1.05}
|
|
1971
|
+
.sg-chip b{font-size:12px;font-weight:700;font-variant-numeric:tabular-nums}
|
|
1972
|
+
.sg-chip span{font-size:8px;color:var(--sg-text-muted);text-transform:uppercase;letter-spacing:.02em}
|
|
1973
|
+
.sg-route-main{flex:1 1 auto;min-width:0}
|
|
1974
|
+
.sg-route-amt{font-size:15px;font-weight:600;font-variant-numeric:tabular-nums;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
1975
|
+
.sg-route-sub{font-size:12px;color:var(--sg-text-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
1976
|
+
.sg-route-end{flex:0 0 auto;display:flex;align-items:center;gap:6px}
|
|
1977
|
+
.sg-radio{width:18px;height:18px;border-radius:999px;border:2px solid var(--sg-border);position:relative;transition:border-color 120ms ease}
|
|
1978
|
+
.sg-route-item[data-selected="true"] .sg-radio{border-color:var(--sg-accent)}
|
|
1979
|
+
.sg-route-item[data-selected="true"] .sg-radio::after{content:"";position:absolute;inset:3px;border-radius:999px;background:var(--sg-accent)}
|
|
1980
|
+
|
|
1981
|
+
.sg-more{width:100%;padding:9px;border:1px dashed var(--sg-border);background:transparent;color:var(--sg-text-muted);border-radius:var(--sg-radius-control);font:inherit;font-size:13px;cursor:pointer}
|
|
1982
|
+
.sg-more:hover{color:var(--sg-text)}
|
|
1983
|
+
.sg-collapse{overflow:hidden;transition:max-height var(--sg-motion-fast,160ms) var(--sg-ease-out-soft,ease),opacity var(--sg-motion-fast,160ms) var(--sg-ease-out-soft,ease)}
|
|
1984
|
+
|
|
1985
|
+
/* holdings-first checkout: your-funds section label, live balance chip, unaffordable dim, empty note */
|
|
1986
|
+
.sg-section-label{font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.06em;color:var(--sg-text-muted);margin:14px 2px 8px}
|
|
1987
|
+
.sg-section-label:first-child{margin-top:0}
|
|
1988
|
+
.sg-bal{font-size:11px;font-weight:600;font-variant-numeric:tabular-nums;color:var(--sg-text-muted);white-space:nowrap}
|
|
1989
|
+
.sg-route-item[data-short="true"]{opacity:.55}
|
|
1990
|
+
.sg-route-item[data-held="true"]{border-color:color-mix(in srgb,var(--sg-accent) 30%,var(--sg-border))}
|
|
1991
|
+
.sg-note{font-size:12px;color:var(--sg-text-muted);margin:2px 2px 10px;line-height:1.45}
|
|
1992
|
+
|
|
1993
|
+
/* badges */
|
|
1994
|
+
.sg-badge{font-size:10px;font-weight:700;text-transform:uppercase;letter-spacing:0.06em;padding:2px 7px;border-radius:999px;background:var(--sg-surface);color:var(--sg-text-muted)}
|
|
1995
|
+
.sg-badge[data-tone="accent"]{background:color-mix(in srgb,var(--sg-accent) 16%,transparent);color:var(--sg-accent)}
|
|
1996
|
+
.sg-badge[data-tone="ok"]{background:color-mix(in srgb,var(--sg-accent) 16%,transparent);color:var(--sg-accent)}
|
|
1997
|
+
.sg-badge[data-tone="warn"]{background:color-mix(in srgb,var(--sg-danger) 14%,transparent);color:var(--sg-danger)}
|
|
1998
|
+
|
|
1999
|
+
/* CTA */
|
|
2000
|
+
.sg-btn{width:100%;min-height:48px;padding:12px 16px;border:none;border-radius:var(--sg-radius-cta);background:var(--sg-accent);color:var(--sg-accent-text);font:inherit;font-size:15px;font-weight:600;cursor:pointer;display:inline-flex;align-items:center;justify-content:center;gap:8px;transition:filter 120ms ease,opacity 120ms ease,transform 60ms ease}
|
|
2001
|
+
.sg-btn:hover:not(:disabled){filter:brightness(1.06)}
|
|
2002
|
+
.sg-btn:active:not(:disabled){transform:translateY(1px)}
|
|
2003
|
+
.sg-btn:disabled{opacity:.5;cursor:not-allowed}
|
|
2004
|
+
.sg-btn-ghost{background:transparent;color:var(--sg-text);border:1px solid var(--sg-border)}
|
|
2005
|
+
.sg-btn-ghost:hover:not(:disabled){filter:none;border-color:var(--sg-accent);color:var(--sg-accent)}
|
|
2006
|
+
.sg-cta-wrap{margin-top:14px}
|
|
2007
|
+
.sg-cta-wrap .sg-btn+.sg-btn{margin-top:8px}
|
|
2008
|
+
|
|
2009
|
+
/* status / steps */
|
|
2010
|
+
.sg-status{margin-top:12px;padding:12px 14px;border-radius:var(--sg-radius-control);background:var(--sg-surface);font-size:13px}
|
|
2011
|
+
.sg-status[data-tone="error"]{background:color-mix(in srgb,var(--sg-danger) 12%,transparent);color:var(--sg-danger)}
|
|
2012
|
+
.sg-status[data-tone="ok"]{background:color-mix(in srgb,var(--sg-accent) 12%,transparent);color:var(--sg-accent)}
|
|
2013
|
+
.sg-steps{list-style:none;margin:10px 0 0;padding:0}
|
|
2014
|
+
.sg-steps li{display:flex;align-items:center;gap:8px;padding:4px 0;font-size:13px}
|
|
2015
|
+
.sg-dot{width:8px;height:8px;border-radius:999px;background:var(--sg-border);flex:0 0 auto}
|
|
2016
|
+
.sg-dot[data-state="active"]{background:var(--sg-accent)}
|
|
2017
|
+
.sg-dot[data-state="done"]{background:var(--sg-success)}
|
|
2018
|
+
.sg-dot[data-state="error"]{background:var(--sg-danger)}
|
|
2019
|
+
|
|
2020
|
+
/* success (accent, not green) */
|
|
2021
|
+
.sg-success{margin-top:14px;padding:18px;border-radius:var(--sg-radius-control);background:color-mix(in srgb,var(--sg-accent) 8%,transparent);text-align:center}
|
|
2022
|
+
.sg-success-check{width:40px;height:40px;border-radius:999px;background:var(--sg-accent);color:var(--sg-accent-text);display:inline-flex;align-items:center;justify-content:center;margin-bottom:8px}
|
|
2023
|
+
/* Broadcast but not receipt-confirmed: mute the disc so a pending settlement never wears the
|
|
2024
|
+
accent-coloured "paid" affordance. Mirrors .sg-settle-disc[data-pending] in the island. */
|
|
2025
|
+
.sg-success-check[data-pending="true"]{background:var(--sg-surface);color:var(--sg-text-muted);border:1px solid var(--sg-border)}
|
|
2026
|
+
.sg-success-amt{font-size:20px;font-weight:700;font-variant-numeric:tabular-nums}
|
|
2027
|
+
.sg-success-sub{font-size:12px;color:var(--sg-text-muted);margin-top:2px}
|
|
2028
|
+
|
|
2029
|
+
/* skeleton loading */
|
|
2030
|
+
.sg-skel{height:64px;border-radius:var(--sg-radius-control);background:linear-gradient(90deg,var(--sg-surface) 25%,color-mix(in srgb,var(--sg-border) 50%,var(--sg-surface)) 37%,var(--sg-surface) 63%);background-size:400% 100%;animation:sg-shimmer 1.2s ease-in-out infinite;margin-bottom:8px}
|
|
2031
|
+
|
|
2032
|
+
/* spinner */
|
|
2033
|
+
.sg-spinner{display:inline-block;width:14px;height:14px;border:2px solid currentColor;border-right-color:transparent;border-radius:999px;animation:sg-spin 0.7s linear infinite;vertical-align:-2px}
|
|
2034
|
+
@keyframes sg-spin{to{transform:rotate(360deg)}}
|
|
2035
|
+
@keyframes sg-shimmer{0%{background-position:100% 0}100%{background-position:-100% 0}}
|
|
2036
|
+
|
|
2037
|
+
.sg-foot{margin-top:14px;display:flex;align-items:center;justify-content:center;gap:6px;font-size:11px;color:var(--sg-text-muted);text-align:center}
|
|
2038
|
+
|
|
2039
|
+
/* fixed-height variant \u2014 head/foot pinned, body scrolls */
|
|
2040
|
+
.sg-widget[data-sg-fixed="true"]{display:flex;flex-direction:column}
|
|
2041
|
+
.sg-widget[data-sg-fixed="true"] .sg-body{flex:1 1 auto;min-height:0;overflow-y:auto;margin:0 -8px;padding:0 8px;scrollbar-width:thin}
|
|
2042
|
+
|
|
2043
|
+
/* head wallet pill (Connect wallet / connected address) */
|
|
2044
|
+
.sg-wallet{display:inline-flex;align-items:center;gap:6px;padding:6px 12px;border-radius:var(--sg-radius-cta);border:1px solid var(--sg-border);background:transparent;color:var(--sg-text);font:inherit;font-size:12px;font-weight:600;cursor:pointer;transition:border-color 120ms ease,color 120ms ease}
|
|
2045
|
+
.sg-wallet:hover{border-color:var(--sg-accent);color:var(--sg-accent)}
|
|
2046
|
+
.sg-wallet[data-connected="true"]{cursor:default;color:var(--sg-text-muted)}
|
|
2047
|
+
.sg-wallet[data-connected="true"]:hover{border-color:var(--sg-border);color:var(--sg-text-muted)}
|
|
2048
|
+
.sg-wallet-dot{width:7px;height:7px;border-radius:999px;background:var(--sg-success)}
|
|
2049
|
+
|
|
2050
|
+
/* From/To tiles with a centered arrow (exchange layout) */
|
|
2051
|
+
.sg-ft{position:relative;display:grid;grid-template-columns:1fr 1fr;gap:10px}
|
|
2052
|
+
.sg-tile{display:flex;flex-direction:column;gap:10px;padding:14px;border:1px solid var(--sg-border);border-radius:var(--sg-radius-control);background:var(--sg-surface);cursor:pointer;font:inherit;color:var(--sg-text);text-align:left;min-width:0;transition:border-color 120ms ease}
|
|
2053
|
+
.sg-tile:hover:not(:disabled){border-color:color-mix(in srgb,var(--sg-accent) 45%,var(--sg-border))}
|
|
2054
|
+
.sg-tile:disabled{cursor:default}
|
|
2055
|
+
.sg-tile-label{font-size:12px;color:var(--sg-text-muted)}
|
|
2056
|
+
.sg-tile-main{display:flex;align-items:center;gap:10px;min-width:0}
|
|
2057
|
+
.sg-tile-sym{font-size:16px;font-weight:700;line-height:1.15;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
2058
|
+
.sg-tile-chain{font-size:11px;color:var(--sg-text-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
2059
|
+
.sg-tile-empty{color:var(--sg-text-muted);font-size:15px;font-weight:600}
|
|
2060
|
+
.sg-ft-arrow{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);width:30px;height:30px;border-radius:999px;background:var(--sg-bg);border:1px solid var(--sg-border);display:flex;align-items:center;justify-content:center;color:var(--sg-text-muted);z-index:1;pointer-events:none}
|
|
2061
|
+
|
|
2062
|
+
/* token identity: logo circle + tiny chain badge, with a letters fallback */
|
|
2063
|
+
.sg-tok{position:relative;flex:0 0 auto;width:36px;height:36px}
|
|
2064
|
+
.sg-tok img{width:36px;height:36px;border-radius:999px;display:block;object-fit:cover}
|
|
2065
|
+
.sg-tok-fb{width:36px;height:36px;border-radius:999px;background:color-mix(in srgb,var(--sg-accent) 16%,transparent);color:var(--sg-accent);font-size:11px;font-weight:700;display:flex;align-items:center;justify-content:center;letter-spacing:.01em}
|
|
2066
|
+
.sg-tok-badge{position:absolute;right:-4px;bottom:-4px;min-width:16px;height:16px;padding:0 2px;border-radius:999px;border:2px solid var(--sg-bg);background:var(--sg-surface);color:var(--sg-text-muted);font-size:7px;font-weight:700;display:flex;align-items:center;justify-content:center;text-transform:uppercase}
|
|
2067
|
+
.sg-tok[data-size="sm"],.sg-tok[data-size="sm"] img,.sg-tok[data-size="sm"] .sg-tok-fb{width:28px;height:28px}
|
|
2068
|
+
.sg-tok[data-size="sm"] .sg-tok-fb{font-size:9px}
|
|
2069
|
+
|
|
2070
|
+
/* fiat side (on/off-ramp) */
|
|
2071
|
+
.sg-fiat{flex:0 0 auto;width:36px;height:36px;border-radius:999px;background:color-mix(in srgb,var(--sg-accent) 14%,transparent);color:var(--sg-accent);font-weight:700;font-size:15px;display:flex;align-items:center;justify-content:center}
|
|
2072
|
+
|
|
2073
|
+
/* send panel: inline token + big amount + percent chips */
|
|
2074
|
+
.sg-send-row{display:flex;align-items:center;gap:12px}
|
|
2075
|
+
.sg-send-row .sg-amount{flex:1 1 auto;min-width:0}
|
|
2076
|
+
.sg-send-bal{font-size:11px;color:var(--sg-text-muted);margin-top:6px}
|
|
2077
|
+
.sg-pct-row{display:flex;gap:8px;margin-top:12px}
|
|
2078
|
+
.sg-pct{flex:1 1 0;padding:7px 0;border-radius:var(--sg-radius-cta);border:1px solid var(--sg-border);background:var(--sg-bg);color:var(--sg-text-muted);font:inherit;font-size:12px;font-weight:600;cursor:pointer;transition:color 120ms ease,border-color 120ms ease}
|
|
2079
|
+
.sg-pct:hover:not(:disabled){color:var(--sg-accent);border-color:var(--sg-accent)}
|
|
2080
|
+
.sg-pct:disabled{opacity:.45;cursor:not-allowed}
|
|
2081
|
+
|
|
2082
|
+
/* full-panel token selector (Exchange from / Exchange to) */
|
|
2083
|
+
.sg-sel-head{display:flex;align-items:center;margin-bottom:14px}
|
|
2084
|
+
.sg-back{width:32px;height:32px;flex:0 0 auto;border:none;border-radius:999px;background:transparent;color:var(--sg-text);cursor:pointer;font:inherit;display:flex;align-items:center;justify-content:center;transition:background 120ms ease}
|
|
2085
|
+
.sg-back:hover{background:var(--sg-surface)}
|
|
2086
|
+
.sg-sel-title{flex:1 1 auto;text-align:center;font-size:15px;font-weight:600;margin-right:32px}
|
|
2087
|
+
.sg-chain-grid{display:grid;grid-template-columns:repeat(5,1fr);gap:8px;margin-bottom:12px}
|
|
2088
|
+
.sg-chain-chip{height:44px;border-radius:var(--sg-radius-control);border:1px solid var(--sg-border);background:var(--sg-surface);color:var(--sg-text);display:flex;align-items:center;justify-content:center;cursor:pointer;font:inherit;font-size:10px;font-weight:700;letter-spacing:.02em;transition:border-color 120ms ease,background 120ms ease;overflow:hidden}
|
|
2089
|
+
.sg-chain-chip img{width:22px;height:22px;border-radius:999px;display:block}
|
|
2090
|
+
.sg-chain-chip:hover{border-color:color-mix(in srgb,var(--sg-accent) 45%,var(--sg-border))}
|
|
2091
|
+
.sg-chain-chip[data-selected="true"]{border-color:var(--sg-accent);background:color-mix(in srgb,var(--sg-accent) 10%,var(--sg-surface))}
|
|
2092
|
+
.sg-search{position:relative;margin-bottom:10px}
|
|
2093
|
+
.sg-search svg{position:absolute;left:12px;top:50%;transform:translateY(-50%);color:var(--sg-text-muted);pointer-events:none}
|
|
2094
|
+
.sg-search input{width:100%;padding:11px 12px 11px 38px;background:var(--sg-surface);color:var(--sg-text);border:1px solid var(--sg-border);border-radius:var(--sg-radius-control);font:inherit;font-size:14px;outline:none;transition:border-color 120ms ease}
|
|
2095
|
+
.sg-search input:focus{border-color:var(--sg-accent)}
|
|
2096
|
+
.sg-toklist{display:flex;flex-direction:column;gap:2px;max-height:320px;overflow-y:auto;margin:0 -6px;padding:0 6px;scrollbar-width:thin}
|
|
2097
|
+
.sg-tokrow{display:flex;align-items:center;gap:12px;padding:10px 8px;border:none;border-radius:var(--sg-radius-control);background:transparent;color:var(--sg-text);cursor:pointer;font:inherit;text-align:left;transition:background 120ms ease}
|
|
2098
|
+
.sg-tokrow:hover{background:var(--sg-surface)}
|
|
2099
|
+
.sg-tokrow-main{flex:1 1 auto;min-width:0}
|
|
2100
|
+
.sg-tokrow-sym{display:block;font-size:15px;font-weight:700;line-height:1.2}
|
|
2101
|
+
.sg-tokrow-name{display:block;font-size:12px;color:var(--sg-text-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
2102
|
+
.sg-tokrow-end{flex:0 0 auto;text-align:right}
|
|
2103
|
+
.sg-tokrow-bal{display:block;font-size:13px;font-weight:600;font-variant-numeric:tabular-nums}
|
|
2104
|
+
.sg-tokrow-chain{display:block;font-size:11px;color:var(--sg-text-muted)}
|
|
2105
|
+
/* funding rows the wallet can't cover (zero / insufficient): greyed, non-interactive, reason hint.
|
|
2106
|
+
Mirrors RouteList's data-short dim + warn tone; no hover lift. Theme-aware via --sg-* vars. */
|
|
2107
|
+
.sg-tokrow--off,.sg-tokrow[disabled]{opacity:.5;cursor:not-allowed}
|
|
2108
|
+
.sg-tokrow--off:hover,.sg-tokrow[disabled]:hover{background:transparent}
|
|
2109
|
+
.sg-tokrow--off .sg-tokrow-sym,.sg-tokrow--off .sg-tokrow-name,.sg-tokrow--off .sg-tokrow-bal{color:var(--sg-text-muted)}
|
|
2110
|
+
.sg-tokrow-hint{display:block;font-size:11px;font-weight:600;color:var(--sg-danger)}
|
|
2111
|
+
.sg-sel-empty{padding:26px 10px;text-align:center;font-size:13px;color:var(--sg-text-muted)}
|
|
2112
|
+
|
|
2113
|
+
/* wide (duo) layout: main card + receive/routes side card. The collapse is keyed to the WIDGET'S
|
|
2114
|
+
OWN available width (container query) \u2014 an embedded widget cannot infer the host layout from the
|
|
2115
|
+
viewport. The viewport media query stays as a fallback for engines without container queries. */
|
|
2116
|
+
/* width:100% is load-bearing: an inline-size container has NO intrinsic width, so as a flex/grid
|
|
2117
|
+
item it would collapse to 0 and hide the whole widget. It fills the host slot; .sg-duo centers. */
|
|
2118
|
+
.sg-duo-wrap{container-type:inline-size;width:100%;font-family:var(--sg-font)}
|
|
2119
|
+
.sg-duo{display:grid;grid-template-columns:minmax(0,400px) minmax(0,380px);gap:18px;align-items:start;justify-content:center;font-family:var(--sg-font)}
|
|
2120
|
+
@container (max-width:840px){.sg-duo{grid-template-columns:minmax(0,400px)}}
|
|
2121
|
+
@media (max-width:920px){.sg-duo{grid-template-columns:minmax(0,400px)}}
|
|
2122
|
+
.sg-side-title{font-size:15px;font-weight:600;letter-spacing:-0.01em;margin-bottom:14px}
|
|
2123
|
+
.sg-noroutes{padding:34px 14px;text-align:center}
|
|
2124
|
+
.sg-noroutes-icon{display:inline-flex;align-items:center;justify-content:center;width:44px;height:44px;border-radius:999px;background:var(--sg-surface);color:var(--sg-text-muted);margin-bottom:12px}
|
|
2125
|
+
.sg-noroutes-title{font-size:16px;font-weight:700;margin-bottom:8px}
|
|
2126
|
+
.sg-noroutes-sub{font-size:13px;color:var(--sg-text-muted);line-height:1.5}
|
|
2127
|
+
.sg-meta{display:flex;flex-direction:column;gap:0;margin-top:10px}
|
|
2128
|
+
.sg-meta-row{display:flex;align-items:center;justify-content:space-between;padding:9px 0;border-bottom:1px solid var(--sg-border);font-size:13px}
|
|
2129
|
+
.sg-meta-row:last-child{border-bottom:none}
|
|
2130
|
+
.sg-meta-row b{font-weight:600;font-variant-numeric:tabular-nums}
|
|
2131
|
+
.sg-meta-label{color:var(--sg-text-muted)}
|
|
2132
|
+
.sg-recv-amt{font-size:28px;font-weight:700;font-variant-numeric:tabular-nums;letter-spacing:-0.01em}
|
|
2133
|
+
.sg-recv-sub{font-size:12px;color:var(--sg-text-muted);margin-top:2px}
|
|
2134
|
+
|
|
2135
|
+
/* head tools: history entry point beside the wallet pill / brand chip */
|
|
2136
|
+
.sg-head-tools{display:flex;align-items:center;gap:8px}
|
|
2137
|
+
.sg-hist{width:32px;height:32px;flex:0 0 auto;border:1px solid var(--sg-border);border-radius:999px;background:transparent;color:var(--sg-text-muted);cursor:pointer;font:inherit;display:flex;align-items:center;justify-content:center;transition:color 120ms ease,border-color 120ms ease}
|
|
2138
|
+
.sg-hist:hover{color:var(--sg-accent);border-color:var(--sg-accent)}
|
|
2139
|
+
|
|
2140
|
+
/* transaction detail: copyable hash row (no external links \u2014 everything stays in-widget) */
|
|
2141
|
+
.sg-txd-hash{display:flex;align-items:center;gap:8px;margin-top:12px;font-size:13px}
|
|
2142
|
+
.sg-txd-hash .sg-mono{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
2143
|
+
.sg-copy{display:inline-flex;align-items:center;justify-content:center;flex:0 0 auto;width:26px;height:26px;border:1px solid var(--sg-border);border-radius:var(--sg-radius-control);background:transparent;color:var(--sg-text-muted);cursor:pointer;transition:color 120ms ease,border-color 120ms ease}
|
|
2144
|
+
.sg-copy:hover{color:var(--sg-accent);border-color:var(--sg-accent)}
|
|
2145
|
+
|
|
2146
|
+
@media (prefers-reduced-motion:reduce){.sg-widget *{transition:none!important;animation:none!important}.sg-widget .sg-spinner{display:none!important}.sg-widget .sg-rm-dot{display:inline-block}}
|
|
2147
|
+
|
|
2148
|
+
/* \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
|
|
2149
|
+
ZeroDelta Link \u2014 the "pill" variant (PaymentIsland). A collapsed express-checkout button that
|
|
2150
|
+
morphs in place (Apple Dynamic-Island style) into a compact 1-click card. Everything lives on the
|
|
2151
|
+
.sg-island root, which carries the --sg-* vars inline (the pill renders OUTSIDE .sg-widget, so it
|
|
2152
|
+
cannot inherit vars from there \u2014 see PaymentIsland). Accent-led throughout; never a green surface.
|
|
2153
|
+
\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550 */
|
|
2154
|
+
|
|
2155
|
+
/* sr-only utility (none existed) \u2014 every live region + hidden state word uses it. */
|
|
2156
|
+
.sg-sr-only{position:absolute!important;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}
|
|
2157
|
+
|
|
2158
|
+
/* container for the pill's own cell \u2014 densities key off the WIDGET'S width, not the viewport */
|
|
2159
|
+
.sg-island-wrap{container-type:inline-size;width:100%;font-family:var(--sg-font);color:var(--sg-text)}
|
|
2160
|
+
|
|
2161
|
+
/* morph root \u2014 the persistent element the pill and card share. radius/bg/shadow tween on expand */
|
|
2162
|
+
.sg-island{position:relative;width:100%;max-width:400px;margin:0 auto;border-radius:var(--sg-radius-cta);background:transparent;transition:border-radius var(--sg-motion-base) var(--sg-ease-in-out),box-shadow var(--sg-motion-base) var(--sg-ease-out-soft),background var(--sg-motion-base) var(--sg-ease-out-soft)}
|
|
2163
|
+
.sg-island[data-expanded="true"]{border-radius:var(--sg-radius)}
|
|
2164
|
+
|
|
2165
|
+
/* collapsed express button \u2014 peer geometry (48px) to Apple Pay / PayPal siblings */
|
|
2166
|
+
.sg-express{width:100%;min-height:48px;display:inline-flex;align-items:center;justify-content:center;gap:9px;padding:12px 18px;border:none;border-radius:var(--sg-radius-cta);background:var(--sg-accent);color:var(--sg-accent-text);font:inherit;font-family:var(--sg-font);font-size:15px;font-weight:600;line-height:1;cursor:pointer;box-shadow:0 1px 2px rgba(16,17,22,.06);transition:filter var(--sg-motion-fast) var(--sg-ease-out-soft),transform 60ms ease;animation:sg-fade-in var(--sg-motion-base) var(--sg-ease-out-soft) both}
|
|
2167
|
+
.sg-express:hover{filter:brightness(1.06)}
|
|
2168
|
+
.sg-express:active{transform:translateY(1px)}
|
|
2169
|
+
.sg-express:focus-visible{outline:2px solid var(--sg-accent);outline-offset:2px}
|
|
2170
|
+
.sg-island[data-expanded="true"] .sg-express{display:none}
|
|
2171
|
+
.sg-express-mark{flex:0 0 auto;display:inline-flex;align-items:center;justify-content:center;width:20px;height:20px;font-size:15px;line-height:1}
|
|
2172
|
+
.sg-express-label{display:inline-flex;align-items:baseline;gap:6px;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
2173
|
+
.sg-express-verb{opacity:.9}
|
|
2174
|
+
.sg-express-brand{font-weight:700;letter-spacing:-0.01em}
|
|
2175
|
+
.sg-express-dot{opacity:.6}
|
|
2176
|
+
.sg-express-amt{font-weight:700;font-variant-numeric:tabular-nums}
|
|
2177
|
+
.sg-express-caret{flex:0 0 auto;font-size:11px;opacity:.75;margin-left:2px}
|
|
2178
|
+
@container (max-width:210px){.sg-express-dot,.sg-express-amt{display:none}}
|
|
2179
|
+
@container (max-width:150px){.sg-express-verb,.sg-express-caret{display:none}}
|
|
2180
|
+
|
|
2181
|
+
/* reveal animator \u2014 grid-rows 0fr\u21921fr height morph; inner clips; body holds the card */
|
|
2182
|
+
.sg-island-reveal{display:grid;grid-template-rows:0fr;transition:grid-template-rows var(--sg-motion-base) var(--sg-ease-out-soft)}
|
|
2183
|
+
.sg-island[data-expanded="true"] .sg-island-reveal{grid-template-rows:1fr}
|
|
2184
|
+
.sg-island-reveal-inner{min-height:0;overflow:hidden}
|
|
2185
|
+
.sg-island-body{animation:sg-fade-in-up var(--sg-motion-base) var(--sg-ease-out-soft) both}
|
|
2186
|
+
|
|
2187
|
+
/* compact card overrides for the expanded island (reuses the .sg-widget shell) */
|
|
2188
|
+
.sg-widget[data-sg-express]{padding:16px;max-width:380px;box-shadow:0 1px 2px rgba(16,17,22,.05),0 12px 32px rgba(16,17,22,.10)}
|
|
2189
|
+
.sg-widget[data-sg-express] .sg-head{margin-bottom:12px}
|
|
2190
|
+
.sg-widget[data-sg-express] .sg-anchor{font-size:24px}
|
|
2191
|
+
.sg-widget[data-sg-express] .sg-foot{margin-top:12px}
|
|
2192
|
+
:root[data-theme="dark"] .sg-widget[data-sg-express],.sg-widget[data-sg-express][data-sg-mode="dark"]{box-shadow:0 12px 32px rgba(0,0,0,.5)}
|
|
2193
|
+
|
|
2194
|
+
/* brand mark + the "\u2026" menu in the head */
|
|
2195
|
+
.sg-link-brand{display:inline-flex;align-items:center;gap:7px;min-width:0}
|
|
2196
|
+
.sg-link-mono{flex:0 0 auto;display:inline-flex;align-items:center;justify-content:center;width:22px;height:22px}
|
|
2197
|
+
.sg-link-word{font-size:14px;font-weight:700;letter-spacing:-0.01em;color:var(--sg-text)}
|
|
2198
|
+
.sg-link-menu-wrap{position:relative;display:inline-flex}
|
|
2199
|
+
.sg-link-menu-btn{width:30px;height:30px;flex:0 0 auto;border:1px solid var(--sg-border);border-radius:999px;background:transparent;color:var(--sg-text-muted);cursor:pointer;font:inherit;display:flex;align-items:center;justify-content:center;letter-spacing:1px;transition:color var(--sg-motion-fast) var(--sg-ease-out-soft),border-color var(--sg-motion-fast) var(--sg-ease-out-soft)}
|
|
2200
|
+
.sg-link-menu-btn:hover{color:var(--sg-accent);border-color:var(--sg-accent)}
|
|
2201
|
+
.sg-link-menu{position:absolute;top:36px;right:0;z-index:20;min-width:196px;padding:6px;border:1px solid var(--sg-border);border-radius:var(--sg-radius-control);background:var(--sg-bg);box-shadow:0 8px 24px rgba(16,17,22,.14);animation:sg-menu-in var(--sg-motion-fast) var(--sg-ease-out-soft) both}
|
|
2202
|
+
.sg-link-menu-item{width:100%;display:block;padding:9px 10px;border:none;border-radius:8px;background:transparent;color:var(--sg-text);font:inherit;font-size:13px;text-align:left;cursor:pointer;transition:background var(--sg-motion-fast) var(--sg-ease-out-soft)}
|
|
2203
|
+
.sg-link-menu-item:hover,.sg-link-menu-item:focus-visible{background:var(--sg-surface);outline:none}
|
|
2204
|
+
.sg-link-menu-item[data-tone="danger"]{color:var(--sg-danger)}
|
|
2205
|
+
.sg-link-menu-sep{height:1px;margin:5px 2px;background:var(--sg-border)}
|
|
2206
|
+
|
|
2207
|
+
/* identity line (wallet + optional saved email) */
|
|
2208
|
+
.sg-link-id{display:flex;align-items:center;gap:10px;padding:11px 12px;border:1px solid var(--sg-border);border-radius:var(--sg-radius-control);background:var(--sg-surface)}
|
|
2209
|
+
.sg-link-id-icon{flex:0 0 auto;display:inline-flex;align-items:center;justify-content:center;width:30px;height:30px;border-radius:999px;background:color-mix(in srgb,var(--sg-accent) 14%,transparent);color:var(--sg-accent)}
|
|
2210
|
+
.sg-link-id-text{min-width:0;flex:1 1 auto;display:flex;flex-direction:column;line-height:1.25}
|
|
2211
|
+
.sg-link-id-primary{font-size:13px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
2212
|
+
.sg-link-id-secondary{font-size:11px;color:var(--sg-text-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
2213
|
+
|
|
2214
|
+
/* method row \u2014 horizontal TokenTile variant ("Pay with \u2022\u2022\u2022\u2022 \u2304") */
|
|
2215
|
+
.sg-tile--row{flex-direction:row;align-items:center;gap:12px;padding:12px 14px}
|
|
2216
|
+
.sg-tile--row .sg-tile-label{flex:0 0 auto;font-size:12px;color:var(--sg-text-muted)}
|
|
2217
|
+
.sg-tile-rowmain{flex:1 1 auto;display:flex;align-items:center;gap:10px;min-width:0;justify-content:flex-end}
|
|
2218
|
+
.sg-tile-chev{flex:0 0 auto;color:var(--sg-text-muted);display:inline-flex;align-items:center;transition:transform var(--sg-motion-fast) var(--sg-ease-out-soft)}
|
|
2219
|
+
.sg-tile--row:hover:not(:disabled) .sg-tile-chev{color:var(--sg-accent);transform:translateX(1px)}
|
|
2220
|
+
|
|
2221
|
+
/* funding-picker opt-in ("remember me" / save-email) */
|
|
2222
|
+
.sg-remember{margin-top:12px;padding:12px;border:1px solid var(--sg-border);border-radius:var(--sg-radius-control);background:var(--sg-surface)}
|
|
2223
|
+
.sg-remember-top{display:flex;align-items:flex-start;gap:10px}
|
|
2224
|
+
.sg-remember-copy{min-width:0}
|
|
2225
|
+
.sg-remember-label{font-size:13px;font-weight:600}
|
|
2226
|
+
.sg-remember-sub{font-size:11px;color:var(--sg-text-muted);margin-top:2px;line-height:1.4}
|
|
2227
|
+
.sg-remember-body{margin-top:10px}
|
|
2228
|
+
.sg-check{width:18px;height:18px;flex:0 0 auto;accent-color:var(--sg-accent);cursor:pointer}
|
|
2229
|
+
|
|
2230
|
+
/* settled receipt (accent-led, never a loud green surface) */
|
|
2231
|
+
.sg-receipt{margin-top:14px;padding:18px;border-radius:var(--sg-radius-control);background:color-mix(in srgb,var(--sg-accent) 8%,transparent);text-align:center;animation:sg-settle-flash var(--sg-motion-slow) var(--sg-ease-out-soft) both}
|
|
2232
|
+
.sg-receipt-eyebrow{font-size:11px;font-weight:700;text-transform:uppercase;letter-spacing:.08em;color:var(--sg-accent)}
|
|
2233
|
+
.sg-settle-disc{position:relative;width:44px;height:44px;margin:6px auto 8px;border-radius:999px;background:var(--sg-accent);color:var(--sg-accent-text);display:inline-flex;align-items:center;justify-content:center;animation:sg-settle-pop var(--sg-motion-slow) var(--sg-ease-spring) both}
|
|
2234
|
+
.sg-settle-disc::after{content:"";position:absolute;inset:-6px;border-radius:999px;border:2px solid color-mix(in srgb,var(--sg-accent) 45%,transparent);opacity:0;animation:sg-settle-ring var(--sg-motion-deliberate) var(--sg-ease-out-soft) both}
|
|
2235
|
+
.sg-settle-disc[data-pending="true"]{background:var(--sg-surface);color:var(--sg-text-muted);animation:none}
|
|
2236
|
+
.sg-settle-disc[data-pending="true"]::after{display:none}
|
|
2237
|
+
.sg-receipt-amt{font-size:22px;font-weight:700;font-variant-numeric:tabular-nums}
|
|
2238
|
+
.sg-receipt-sub{font-size:12px;color:var(--sg-text-muted);margin-top:3px}
|
|
2239
|
+
.sg-link-alt{width:100%;margin-top:10px;padding:10px;border:none;background:transparent;color:var(--sg-text-muted);font:inherit;font-size:13px;cursor:pointer;border-radius:var(--sg-radius-control);transition:color var(--sg-motion-fast) var(--sg-ease-out-soft)}
|
|
2240
|
+
.sg-link-alt:hover{color:var(--sg-accent)}
|
|
2241
|
+
|
|
2242
|
+
/* honest coming-soon inside the island (neutral \u2014 no orange token exists, no quote implied) */
|
|
2243
|
+
.sg-soonpanel{margin-top:12px;padding:16px;border:1px solid var(--sg-border);border-radius:var(--sg-radius-control);background:var(--sg-surface);text-align:center}
|
|
2244
|
+
.sg-soonpanel-title{font-size:14px;font-weight:700;margin-bottom:6px}
|
|
2245
|
+
.sg-soonpanel-sub{font-size:12px;color:var(--sg-text-muted);line-height:1.45}
|
|
2246
|
+
|
|
2247
|
+
/* compact merchant-receives anchor + click-to-expand "Details" disclosure (merchant-configured;
|
|
2248
|
+
the payer never edits it). Reveal mirrors the island's grid-rows morph; reduced-motion covered by
|
|
2249
|
+
the .sg-island guard below (it disables transitions on .sg-island *). */
|
|
2250
|
+
.sg-merch-head{display:flex;align-items:flex-start;justify-content:space-between;gap:12px}
|
|
2251
|
+
.sg-merch-lead{min-width:0}
|
|
2252
|
+
/* bank payout destination (settlement="bank") \u2014 sits in the same anchor slot as the stablecoin
|
|
2253
|
+
amount so the two settlement modes share one layout. */
|
|
2254
|
+
.sg-bank{display:flex;align-items:center;gap:10px;margin-top:2px;min-width:0}
|
|
2255
|
+
.sg-bank-icon{flex:0 0 auto;display:inline-flex;align-items:center;justify-content:center;width:32px;height:32px;border:1px solid var(--sg-border);border-radius:var(--sg-radius-control);color:var(--sg-text-muted)}
|
|
2256
|
+
.sg-bank-text{display:flex;flex-direction:column;min-width:0}
|
|
2257
|
+
.sg-bank-name{font-size:16px;font-weight:700;color:var(--sg-text);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
2258
|
+
.sg-bank-cur{font-size:12px;color:var(--sg-text-muted)}
|
|
2259
|
+
.sg-details-toggle{flex:0 0 auto;display:inline-flex;align-items:center;gap:4px;padding:5px 10px;border:1px solid var(--sg-border);border-radius:var(--sg-radius-cta);background:transparent;color:var(--sg-text-muted);font:inherit;font-size:12px;font-weight:600;cursor:pointer;white-space:nowrap;transition:color var(--sg-motion-fast) var(--sg-ease-out-soft),border-color var(--sg-motion-fast) var(--sg-ease-out-soft)}
|
|
2260
|
+
.sg-details-toggle:hover{color:var(--sg-accent);border-color:var(--sg-accent)}
|
|
2261
|
+
.sg-details-chev{display:inline-flex;font-size:11px;line-height:1;transition:transform var(--sg-motion-fast) var(--sg-ease-out-soft)}
|
|
2262
|
+
.sg-details-toggle[data-open="true"] .sg-details-chev{transform:rotate(180deg)}
|
|
2263
|
+
.sg-details-reveal{display:grid;grid-template-rows:0fr;transition:grid-template-rows var(--sg-motion-base) var(--sg-ease-out-soft)}
|
|
2264
|
+
.sg-details-reveal[data-open="true"]{grid-template-rows:1fr}
|
|
2265
|
+
.sg-details-reveal-inner{min-height:0;overflow:hidden}
|
|
2266
|
+
.sg-details-body{margin-top:12px;padding-top:12px;border-top:1px solid var(--sg-border)}
|
|
2267
|
+
.sg-details-row{display:flex;align-items:baseline;justify-content:space-between;gap:12px;padding:4px 0;font-size:12px}
|
|
2268
|
+
.sg-details-k{flex:0 0 auto;color:var(--sg-text-muted)}
|
|
2269
|
+
.sg-details-v{min-width:0;text-align:right;color:var(--sg-text)}
|
|
2270
|
+
.sg-details-addr{word-break:break-all;font-size:11px}
|
|
2271
|
+
.sg-details-note{margin-top:8px;font-size:11px;color:var(--sg-text-muted);line-height:1.45}
|
|
2272
|
+
|
|
2273
|
+
/* express-card compaction for the 5-tab method selector (already overflow-x:auto for narrow cells) */
|
|
2274
|
+
.sg-widget[data-sg-express] .sg-tabs{margin:12px 0 8px}
|
|
2275
|
+
.sg-widget[data-sg-express] .sg-tab{padding:6px 10px;font-size:12px}
|
|
2276
|
+
|
|
2277
|
+
/* step-done "verify" verdict word under the ticker */
|
|
2278
|
+
.sg-step-verdict{margin-top:6px;font-size:12px;color:var(--sg-text-muted)}
|
|
2279
|
+
.sg-steps li[data-state="error"] span{color:var(--sg-danger)}
|
|
2280
|
+
|
|
2281
|
+
/* static accent dot shown ONLY under reduced motion (a frozen spinner ring reads as broken) */
|
|
2282
|
+
.sg-rm-dot{display:none;width:8px;height:8px;border-radius:999px;background:var(--sg-accent);vertical-align:-1px}
|
|
2283
|
+
|
|
2284
|
+
/* pill-face state tint while paying / settled (collapsed mid-flight) */
|
|
2285
|
+
.sg-island[data-status="submitting"] .sg-express{filter:none}
|
|
2286
|
+
|
|
2287
|
+
@keyframes sg-fade-in{from{opacity:0}to{opacity:1}}
|
|
2288
|
+
@keyframes sg-fade-in-up{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:translateY(0)}}
|
|
2289
|
+
@keyframes sg-scale-in{from{opacity:0;transform:scale(.96)}to{opacity:1;transform:scale(1)}}
|
|
2290
|
+
@keyframes sg-tick-pop{0%{transform:scale(.6);opacity:0}60%{transform:scale(1.12)}100%{transform:scale(1);opacity:1}}
|
|
2291
|
+
@keyframes sg-settle-flash{from{opacity:0;transform:translateY(4px)}to{opacity:1;transform:translateY(0)}}
|
|
2292
|
+
@keyframes sg-settle-pop{0%{transform:scale(.7);opacity:0}55%{transform:scale(1.08)}100%{transform:scale(1);opacity:1}}
|
|
2293
|
+
@keyframes sg-settle-ring{0%{transform:scale(.85);opacity:.8}100%{transform:scale(1.25);opacity:0}}
|
|
2294
|
+
@keyframes sg-menu-in{from{opacity:0;transform:translateY(-4px) scale(.98)}to{opacity:1;transform:translateY(0) scale(1)}}
|
|
2295
|
+
|
|
2296
|
+
/* Second reduced-motion guard \u2014 the existing guard only matches .sg-widget *; the pill lives on
|
|
2297
|
+
.sg-island, OUTSIDE .sg-widget, so it needs its own. Also hides spinners (a frozen ring looks
|
|
2298
|
+
broken) and shows the static accent dot instead; the label + live region carry the state. */
|
|
2299
|
+
@media (prefers-reduced-motion:reduce){
|
|
2300
|
+
.sg-island,.sg-island *{transition:none!important;animation:none!important}
|
|
2301
|
+
.sg-island-reveal,.sg-details-reveal{transition:none!important}
|
|
2302
|
+
.sg-island .sg-spinner{display:none!important}
|
|
2303
|
+
.sg-island .sg-rm-dot{display:inline-block}
|
|
2304
|
+
}
|
|
2305
|
+
`;
|
|
2306
|
+
var injected = false;
|
|
2307
|
+
function injectStyles() {
|
|
2308
|
+
if (injected || typeof document === "undefined") return;
|
|
2309
|
+
if (document.getElementById("stablegenie-widget-styles")) {
|
|
2310
|
+
injected = true;
|
|
2311
|
+
return;
|
|
2312
|
+
}
|
|
2313
|
+
const style = document.createElement("style");
|
|
2314
|
+
style.id = "stablegenie-widget-styles";
|
|
2315
|
+
style.textContent = WIDGET_CSS;
|
|
2316
|
+
document.head.appendChild(style);
|
|
2317
|
+
injected = true;
|
|
2318
|
+
}
|
|
2319
|
+
|
|
2320
|
+
// src/react/theme.ts
|
|
2321
|
+
var MOTION = {
|
|
2322
|
+
motionFast: "160ms",
|
|
2323
|
+
motionBase: "220ms",
|
|
2324
|
+
motionSlow: "320ms",
|
|
2325
|
+
motionDeliberate: "480ms",
|
|
2326
|
+
easeOutSoft: "cubic-bezier(0.22,0.61,0.36,1)",
|
|
2327
|
+
easeInOut: "cubic-bezier(0.4,0,0.2,1)",
|
|
2328
|
+
easeSpring: "cubic-bezier(0.34,1.56,0.64,1)"
|
|
2329
|
+
};
|
|
2330
|
+
var lightTheme = {
|
|
2331
|
+
mode: "light",
|
|
2332
|
+
accent: "#4358e1",
|
|
2333
|
+
accentText: "#ffffff",
|
|
2334
|
+
bg: "#ffffff",
|
|
2335
|
+
surface: "#f7f8fc",
|
|
2336
|
+
border: "#e6e8f0",
|
|
2337
|
+
text: "#0e1116",
|
|
2338
|
+
textMuted: "#6b7280",
|
|
2339
|
+
danger: "#df1b41",
|
|
2340
|
+
success: "#12805c",
|
|
2341
|
+
radius: "20px",
|
|
2342
|
+
radiusControl: "10px",
|
|
2343
|
+
radiusCta: "999px",
|
|
2344
|
+
font: "'Helvetica Neue', Helvetica, Arial, system-ui, sans-serif",
|
|
2345
|
+
...MOTION
|
|
2346
|
+
};
|
|
2347
|
+
var darkTheme = {
|
|
2348
|
+
mode: "dark",
|
|
2349
|
+
accent: "#7b8cff",
|
|
2350
|
+
accentText: "#0b0d12",
|
|
2351
|
+
bg: "#0e1116",
|
|
2352
|
+
surface: "#161a22",
|
|
2353
|
+
border: "#252b36",
|
|
2354
|
+
text: "#eef1f6",
|
|
2355
|
+
textMuted: "#9aa4b2",
|
|
2356
|
+
danger: "#ff5470",
|
|
2357
|
+
success: "#3ddc97",
|
|
2358
|
+
radius: "20px",
|
|
2359
|
+
radiusControl: "10px",
|
|
2360
|
+
radiusCta: "999px",
|
|
2361
|
+
font: "'Helvetica Neue', Helvetica, Arial, system-ui, sans-serif",
|
|
2362
|
+
...MOTION
|
|
2363
|
+
};
|
|
2364
|
+
function resolveTheme(theme) {
|
|
2365
|
+
const base = theme?.mode === "dark" ? darkTheme : lightTheme;
|
|
2366
|
+
return { ...base, ...theme };
|
|
2367
|
+
}
|
|
2368
|
+
function themeToVars(theme) {
|
|
2369
|
+
return {
|
|
2370
|
+
"--sg-accent": theme.accent,
|
|
2371
|
+
"--sg-accent-text": theme.accentText,
|
|
2372
|
+
"--sg-bg": theme.bg,
|
|
2373
|
+
"--sg-surface": theme.surface,
|
|
2374
|
+
"--sg-border": theme.border,
|
|
2375
|
+
"--sg-text": theme.text,
|
|
2376
|
+
"--sg-text-muted": theme.textMuted,
|
|
2377
|
+
"--sg-danger": theme.danger,
|
|
2378
|
+
"--sg-success": theme.success,
|
|
2379
|
+
"--sg-radius": theme.radius,
|
|
2380
|
+
"--sg-radius-control": theme.radiusControl,
|
|
2381
|
+
"--sg-radius-cta": theme.radiusCta,
|
|
2382
|
+
"--sg-font": theme.font,
|
|
2383
|
+
"--sg-motion-fast": theme.motionFast,
|
|
2384
|
+
"--sg-motion-base": theme.motionBase,
|
|
2385
|
+
"--sg-motion-slow": theme.motionSlow,
|
|
2386
|
+
"--sg-motion-deliberate": theme.motionDeliberate,
|
|
2387
|
+
"--sg-ease-out-soft": theme.easeOutSoft,
|
|
2388
|
+
"--sg-ease-in-out": theme.easeInOut,
|
|
2389
|
+
"--sg-ease-spring": theme.easeSpring
|
|
2390
|
+
};
|
|
2391
|
+
}
|
|
2392
|
+
var PATHS = [
|
|
2393
|
+
{
|
|
2394
|
+
fill: "#8C9BFF",
|
|
2395
|
+
d: "M32.7018 21.9107C32.8383 21.9814 32.9396 22.0498 32.9946 22.0873L32.9968 22.0807C31.8896 20.2754 30.0691 17.2476 27.9119 13.3965C27.9119 13.3965 26.0871 9.95494 25.0965 8.74124C24.1059 7.52755 22.0147 7.52745 21.1342 7.74814C20.2537 7.96883 19.9235 8.1896 19.4833 8.63098C19.043 9.07236 18.8493 9.34467 18.605 10.1811C18.2528 11.3816 19.1377 13.4517 19.7364 14.5971C21.9245 18.788 22.7874 20.0658 24.2358 20.8007C25.7239 21.5576 27.4563 21.3524 28.044 21.3237C29.2899 21.2641 30.582 21.2178 31.9886 21.6503C32.3629 21.7651 32.7018 21.9107 32.7018 21.9107Z"
|
|
2396
|
+
},
|
|
2397
|
+
{
|
|
2398
|
+
fill: "#1A2BA3",
|
|
2399
|
+
d: "M1.80275 22.2019C1.99646 24.0645 2.84175 25.3181 3.59678 25.883C4.35181 26.448 5.40841 26.7128 6.06219 26.7371C9.60841 26.8651 21.1826 26.6687 22.455 26.7636C22.455 26.7636 23.7383 26.8364 24.6298 27.8096C24.9292 28.1385 25.5543 28.9881 25.671 30.1975C25.8141 31.6717 25.0502 33.029 24.0333 33.7903C24.0267 33.7948 24.0222 33.7992 24.0156 33.8036C23.3905 34.267 22.62 34.4877 21.8452 34.4811C16.593 34.4237 14.1232 34.5076 7.73954 34.4392C7.57885 34.4392 5.7364 34.4392 4.98137 34.1942C2.29583 33.3269 1.06973 32.069 0.253067 29.3567C-0.0286943 28.4232 0.0153298 27.4786 0.00432351 27.2072C-0.0727205 25.4019 0.893632 23.1001 1.80715 22.2019H1.80275Z"
|
|
2400
|
+
},
|
|
2401
|
+
{
|
|
2402
|
+
fill: "#4358E1",
|
|
2403
|
+
d: "M24.0443 7.79949C22.3327 7.04654 20.8017 7.19806 19.9133 7.61076C19.0249 8.02346 18.2359 8.86389 17.8683 9.4537C15.8774 12.6548 9.91015 23.4098 9.15356 24.5338C9.15356 24.5338 8.41019 25.679 7.09679 26.0132C6.65401 26.1244 5.58859 26.2752 4.48205 25.7779C3.13275 25.1726 2.36535 23.7907 2.24689 22.4736C2.24658 22.4653 2.2451 22.4591 2.24479 22.4508C2.17594 21.6435 2.39381 20.8237 2.81037 20.1136C5.64479 15.3065 6.88191 12.9905 10.3258 7.14707C10.411 6.99911 11.3879 5.30271 11.9999 4.73001C14.173 2.69101 15.9097 2.19106 18.6856 2.79527C19.6414 3.0026 20.434 3.51541 20.6743 3.641C22.2745 4.47269 23.7505 6.51334 24.042 7.80355L24.0443 7.79949Z"
|
|
2404
|
+
},
|
|
2405
|
+
{
|
|
2406
|
+
fill: "#9962FF",
|
|
2407
|
+
d: "M35.0154 28.2911C35.066 27.6797 35.4688 25.133 33.666 23.1335C33.3534 22.7871 32.8867 22.2751 31.0971 21.9418C28.1959 21.4011 26.3534 22.2442 24.5198 22.3766C25.2814 23.2108 26.3842 24.8682 26.7408 27.4215C26.8707 28.3462 26.9918 29.7344 26.3512 31.3388C25.3562 33.8326 24.3349 34.0422 23.7823 34.3137H23.3905C23.3905 34.3137 29.7279 34.6933 32.7767 32.1642C35.0044 30.317 34.9757 28.7898 35.0154 28.2888V28.2911Z"
|
|
2408
|
+
}
|
|
2409
|
+
];
|
|
2410
|
+
function BrandMark({ size = 18, mono = false, className, style, title }) {
|
|
2411
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2412
|
+
"svg",
|
|
2413
|
+
{
|
|
2414
|
+
className,
|
|
2415
|
+
width: size,
|
|
2416
|
+
height: size * 34.4815 / 35.0888,
|
|
2417
|
+
viewBox: "0 0 35.0888 34.4815",
|
|
2418
|
+
fill: "none",
|
|
2419
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
2420
|
+
style,
|
|
2421
|
+
role: title ? "img" : void 0,
|
|
2422
|
+
"aria-hidden": title ? void 0 : true,
|
|
2423
|
+
"aria-label": title,
|
|
2424
|
+
children: [
|
|
2425
|
+
title ? /* @__PURE__ */ jsxRuntime.jsx("title", { children: title }) : null,
|
|
2426
|
+
PATHS.map((p) => /* @__PURE__ */ jsxRuntime.jsx("path", { d: p.d, fill: mono ? "currentColor" : p.fill }, p.d))
|
|
2427
|
+
]
|
|
2428
|
+
}
|
|
2429
|
+
);
|
|
2430
|
+
}
|
|
2431
|
+
function LockGlyph() {
|
|
2432
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "11", height: "11", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
|
|
2433
|
+
/* @__PURE__ */ jsxRuntime.jsx("rect", { x: "4", y: "11", width: "16", height: "10", rx: "2" }),
|
|
2434
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M8 11V8a4 4 0 0 1 8 0v3" })
|
|
2435
|
+
] });
|
|
2436
|
+
}
|
|
2437
|
+
function WidgetShell(props) {
|
|
2438
|
+
injectStyles();
|
|
2439
|
+
const resolved = resolveTheme(props.theme);
|
|
2440
|
+
const vars = themeToVars(resolved);
|
|
2441
|
+
const fixed = Number.isFinite(props.heightPx) && props.heightPx > 0;
|
|
2442
|
+
const style = fixed ? { ...vars, height: props.heightPx } : vars;
|
|
2443
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-widget", "data-sg-mode": resolved.mode, "data-sg-fixed": fixed || void 0, "data-sg-express": props.variant === "express" || void 0, style, children: [
|
|
2444
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-head", children: [
|
|
2445
|
+
props.brandSlot ?? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-title", children: props.title }),
|
|
2446
|
+
props.walletSlot ?? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-brand", children: [
|
|
2447
|
+
/* @__PURE__ */ jsxRuntime.jsx(BrandMark, { size: 14, className: "sg-brand-mark" }),
|
|
2448
|
+
"ZeroDelta"
|
|
2449
|
+
] })
|
|
2450
|
+
] }),
|
|
2451
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-body", children: props.children }),
|
|
2452
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-foot", children: [
|
|
2453
|
+
/* @__PURE__ */ jsxRuntime.jsx(LockGlyph, {}),
|
|
2454
|
+
" Your wallet signs every transaction \xB7 Powered by ZeroDelta"
|
|
2455
|
+
] })
|
|
2456
|
+
] });
|
|
2457
|
+
}
|
|
2458
|
+
function shortAddress(a) {
|
|
2459
|
+
if (!a) return "";
|
|
2460
|
+
return `${a.slice(0, 6)}\u2026${a.slice(-4)}`;
|
|
2461
|
+
}
|
|
2462
|
+
var CHAIN_LABELS = {
|
|
2463
|
+
1: "Ethereum",
|
|
2464
|
+
10: "Optimism",
|
|
2465
|
+
130: "Unichain",
|
|
2466
|
+
146: "Sonic",
|
|
2467
|
+
8453: "Base",
|
|
2468
|
+
9745: "Plasma",
|
|
2469
|
+
57073: "Ink",
|
|
2470
|
+
42161: "Arbitrum"
|
|
2471
|
+
};
|
|
2472
|
+
var SUPPORTED_CHAINS = [1, 10, 42161, 8453, 57073, 130, 9745, 146];
|
|
2473
|
+
var SUPPORTED_ASSETS2 = ["USDC", "USDT", "USDE", "XAUT"];
|
|
2474
|
+
function Button(props) {
|
|
2475
|
+
const soft = !!props.softDisabled && !props.disabled;
|
|
2476
|
+
const nativeDisabled = props.disabled || props.busy && !props.softDisabled;
|
|
2477
|
+
return (
|
|
2478
|
+
// type="button": a host page may wrap the widget in a <form> — the default type="submit"
|
|
2479
|
+
// would turn any widget CTA into a page-navigating form submission.
|
|
2480
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
2481
|
+
"button",
|
|
2482
|
+
{
|
|
2483
|
+
type: "button",
|
|
2484
|
+
className: props.variant === "ghost" ? "sg-btn sg-btn-ghost" : "sg-btn",
|
|
2485
|
+
onClick: soft ? void 0 : props.onClick,
|
|
2486
|
+
disabled: nativeDisabled,
|
|
2487
|
+
"aria-disabled": soft || void 0,
|
|
2488
|
+
"aria-busy": props.busy || void 0,
|
|
2489
|
+
"aria-label": props.ariaLabel,
|
|
2490
|
+
children: [
|
|
2491
|
+
props.busy ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
2492
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-spinner", "aria-hidden": "true" }),
|
|
2493
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-rm-dot", "aria-hidden": "true" })
|
|
2494
|
+
] }) : null,
|
|
2495
|
+
props.children
|
|
2496
|
+
]
|
|
2497
|
+
}
|
|
2498
|
+
)
|
|
2499
|
+
);
|
|
2500
|
+
}
|
|
2501
|
+
function Select(props) {
|
|
2502
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-field", children: /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "sg-label-wrap", children: [
|
|
2503
|
+
props.label ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-label", children: props.label }) : null,
|
|
2504
|
+
/* @__PURE__ */ jsxRuntime.jsx("select", { className: "sg-select", value: props.value, disabled: props.disabled, onChange: (e) => props.onChange(e.target.value), children: props.options.map((o) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: o.value, children: o.label }, String(o.value))) })
|
|
2505
|
+
] }) });
|
|
2506
|
+
}
|
|
2507
|
+
function AmountInput(props) {
|
|
2508
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2509
|
+
"input",
|
|
2510
|
+
{
|
|
2511
|
+
className: "sg-input sg-amount sg-mono",
|
|
2512
|
+
inputMode: "decimal",
|
|
2513
|
+
placeholder: props.placeholder ?? "0.0",
|
|
2514
|
+
value: props.value,
|
|
2515
|
+
disabled: props.disabled,
|
|
2516
|
+
onChange: (e) => props.onChange(e.target.value.replace(/[^0-9.,]/g, ""))
|
|
2517
|
+
}
|
|
2518
|
+
);
|
|
2519
|
+
}
|
|
2520
|
+
function StatusPanel(props) {
|
|
2521
|
+
const tone = props.tone ?? "neutral";
|
|
2522
|
+
return (
|
|
2523
|
+
// Errors must be announced assertively; neutral/ok stay polite.
|
|
2524
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-status", "data-tone": tone, role: tone === "error" ? "alert" : "status", children: props.children })
|
|
2525
|
+
);
|
|
2526
|
+
}
|
|
2527
|
+
var STEP_STATE_WORD = {
|
|
2528
|
+
pending: "pending",
|
|
2529
|
+
active: "in progress",
|
|
2530
|
+
done: "done",
|
|
2531
|
+
error: "failed"
|
|
2532
|
+
};
|
|
2533
|
+
function StepList(props) {
|
|
2534
|
+
if (!props.steps.length) return null;
|
|
2535
|
+
const rich = props.variant === "rich";
|
|
2536
|
+
const verifyDone = props.steps.some((s) => s.id === "verify" && s.state === "done");
|
|
2537
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
2538
|
+
/* @__PURE__ */ jsxRuntime.jsx("ul", { className: "sg-steps", children: props.steps.map((s) => /* @__PURE__ */ jsxRuntime.jsxs("li", { "data-state": s.state, children: [
|
|
2539
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-dot", "data-state": s.state, "aria-hidden": "true" }),
|
|
2540
|
+
" ",
|
|
2541
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: s.state === "done" ? "sg-muted" : "", children: s.label }),
|
|
2542
|
+
rich ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-sr-only", children: ` \u2014 ${STEP_STATE_WORD[s.state]}` }) : null
|
|
2543
|
+
] }, s.id)) }),
|
|
2544
|
+
rich && props.verdict && verifyDone ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-step-verdict", children: props.verdict.status === "confirmed" ? "Confirmed on-chain \u2014 the merchant has been settled." : props.verdict.status === "mismatch" ? "The submitted transaction did not match the reviewed plan." : "Payment sent \u2014 confirmation is still pending." }) : null
|
|
2545
|
+
] });
|
|
2546
|
+
}
|
|
2547
|
+
var SHOW_ROADMAP_METHODS = true;
|
|
2548
|
+
var METHODS = [
|
|
2549
|
+
{ id: "recommended", label: "Recommended", live: true },
|
|
2550
|
+
{ id: "stablecoin", label: "Stablecoin", live: true },
|
|
2551
|
+
{ id: "anyasset", label: "Any asset", live: true },
|
|
2552
|
+
{ id: "card", label: "Card", live: false },
|
|
2553
|
+
{ id: "bank", label: "Bank", live: false }
|
|
2554
|
+
];
|
|
2555
|
+
function isLiveMethod(m) {
|
|
2556
|
+
return m === "recommended" || m === "stablecoin" || m === "anyasset";
|
|
2557
|
+
}
|
|
2558
|
+
function MethodTabs(props) {
|
|
2559
|
+
const showRoadmap = props.showRoadmap ?? SHOW_ROADMAP_METHODS;
|
|
2560
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-tabs", role: "tablist", "aria-label": "Payment method", children: METHODS.filter((m) => m.live || showRoadmap).map((m) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2561
|
+
"button",
|
|
2562
|
+
{
|
|
2563
|
+
type: "button",
|
|
2564
|
+
className: "sg-tab",
|
|
2565
|
+
role: "tab",
|
|
2566
|
+
"aria-selected": props.value === m.id,
|
|
2567
|
+
"data-selected": props.value === m.id,
|
|
2568
|
+
"aria-disabled": !m.live,
|
|
2569
|
+
style: m.live ? void 0 : { opacity: 0.55 },
|
|
2570
|
+
onClick: () => props.onChange(m.id),
|
|
2571
|
+
children: [
|
|
2572
|
+
m.label,
|
|
2573
|
+
!m.live ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-soon", children: "Soon" }) : null
|
|
2574
|
+
]
|
|
2575
|
+
},
|
|
2576
|
+
m.id
|
|
2577
|
+
)) });
|
|
2578
|
+
}
|
|
2579
|
+
function routeBalanceKey(r) {
|
|
2580
|
+
return `${Number(r.source.chainId)}:${String(r.source.tokenAddress || "").toLowerCase()}`;
|
|
2581
|
+
}
|
|
2582
|
+
function RouteList(props) {
|
|
2583
|
+
const [expanded, setExpanded] = react.useState(false);
|
|
2584
|
+
const maxVisible = props.maxVisible ?? 5;
|
|
2585
|
+
if (!props.routes.length) return null;
|
|
2586
|
+
const hiddenCount = props.routes.length - maxVisible;
|
|
2587
|
+
const visible = expanded || hiddenCount <= 0 ? props.routes : props.routes.slice(0, maxVisible);
|
|
2588
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-route", role: "radiogroup", "aria-label": props.ariaLabel ?? "Pay from", children: [
|
|
2589
|
+
visible.map((r) => {
|
|
2590
|
+
const selected = props.selectedId === r.id;
|
|
2591
|
+
const bal = props.balances?.[routeBalanceKey(r)];
|
|
2592
|
+
const short = props.shortIds?.has(r.id) ?? false;
|
|
2593
|
+
const held = props.heldIds?.has(r.id) ?? false;
|
|
2594
|
+
return (
|
|
2595
|
+
// a11y note: a native radio cannot contain the rich
|
|
2596
|
+
// multi-line route summary (token glyphs, chain badges, amounts) this row renders, and
|
|
2597
|
+
// restyling one away from its UA appearance across every host page is worse. The
|
|
2598
|
+
// keyboard contract is implemented explicitly below (Enter/Space + tabIndex).
|
|
2599
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
2600
|
+
"div",
|
|
2601
|
+
{
|
|
2602
|
+
className: "sg-route-item",
|
|
2603
|
+
"data-selected": selected,
|
|
2604
|
+
"data-short": short || void 0,
|
|
2605
|
+
"data-held": held || void 0,
|
|
2606
|
+
role: "radio",
|
|
2607
|
+
"aria-checked": selected,
|
|
2608
|
+
tabIndex: 0,
|
|
2609
|
+
onClick: () => props.onSelect(r.id),
|
|
2610
|
+
onKeyDown: (e) => {
|
|
2611
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
2612
|
+
e.preventDefault();
|
|
2613
|
+
props.onSelect(r.id);
|
|
2614
|
+
}
|
|
2615
|
+
},
|
|
2616
|
+
children: [
|
|
2617
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-chip", children: [
|
|
2618
|
+
/* @__PURE__ */ jsxRuntime.jsx("b", { children: r.source.asset }),
|
|
2619
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: CHAIN_LABELS[r.source.chainId] || r.source.chainName })
|
|
2620
|
+
] }),
|
|
2621
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-route-main", children: [
|
|
2622
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-route-amt", children: [
|
|
2623
|
+
r.source.payAmount,
|
|
2624
|
+
" ",
|
|
2625
|
+
r.source.asset
|
|
2626
|
+
] }),
|
|
2627
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-route-sub", children: [
|
|
2628
|
+
"from ",
|
|
2629
|
+
CHAIN_LABELS[r.source.chainId] || r.source.chainName,
|
|
2630
|
+
" \xB7 ",
|
|
2631
|
+
r.deltaLabel
|
|
2632
|
+
] })
|
|
2633
|
+
] }),
|
|
2634
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-route-end", children: [
|
|
2635
|
+
bal ? /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-bal", children: [
|
|
2636
|
+
"bal ",
|
|
2637
|
+
bal.formatted
|
|
2638
|
+
] }) : null,
|
|
2639
|
+
short ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-badge", "data-tone": "warn", children: "Short" }) : r.state === "DIRECT" ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-badge", "data-tone": "ok", children: "Direct" }) : r.recommended ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-badge", "data-tone": "accent", children: "Best" }) : null,
|
|
2640
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-radio", "aria-hidden": "true" })
|
|
2641
|
+
] })
|
|
2642
|
+
]
|
|
2643
|
+
},
|
|
2644
|
+
r.id
|
|
2645
|
+
)
|
|
2646
|
+
);
|
|
2647
|
+
}),
|
|
2648
|
+
hiddenCount > 0 && !expanded ? /* @__PURE__ */ jsxRuntime.jsxs("button", { type: "button", className: "sg-more", onClick: () => setExpanded(true), children: [
|
|
2649
|
+
"More (",
|
|
2650
|
+
hiddenCount,
|
|
2651
|
+
")"
|
|
2652
|
+
] }) : null
|
|
2653
|
+
] });
|
|
2654
|
+
}
|
|
2655
|
+
var CHAIN_SHORT = {
|
|
2656
|
+
1: "ETH",
|
|
2657
|
+
10: "OP",
|
|
2658
|
+
130: "UNI",
|
|
2659
|
+
146: "SON",
|
|
2660
|
+
8453: "BASE",
|
|
2661
|
+
9745: "PLS",
|
|
2662
|
+
57073: "INK",
|
|
2663
|
+
42161: "ARB"
|
|
2664
|
+
};
|
|
2665
|
+
function isHttpsUrl(u) {
|
|
2666
|
+
return typeof u === "string" && /^https:\/\//i.test(u);
|
|
2667
|
+
}
|
|
2668
|
+
function TokenGlyph(props) {
|
|
2669
|
+
const [broken, setBroken] = react.useState(false);
|
|
2670
|
+
const showImg = isHttpsUrl(props.logoUrl) && !broken;
|
|
2671
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-tok", "data-size": props.size === "sm" ? "sm" : void 0, children: [
|
|
2672
|
+
showImg ? /* @__PURE__ */ jsxRuntime.jsx("img", { src: props.logoUrl, alt: "", loading: "lazy", onError: () => setBroken(true) }) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-tok-fb", children: props.symbol.slice(0, 4) }),
|
|
2673
|
+
props.chainId ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-tok-badge", children: CHAIN_SHORT[props.chainId] || "?" }) : null
|
|
2674
|
+
] });
|
|
2675
|
+
}
|
|
2676
|
+
function ChevronGlyph() {
|
|
2677
|
+
return /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.4", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "m9 18 6-6-6-6" }) });
|
|
2678
|
+
}
|
|
2679
|
+
function TokenTile(props) {
|
|
2680
|
+
const glyph = props.pick ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
2681
|
+
/* @__PURE__ */ jsxRuntime.jsx(TokenGlyph, { symbol: props.pick.symbol, logoUrl: props.token?.logoUrl, chainId: props.pick.chainId }),
|
|
2682
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { style: { minWidth: 0 }, children: [
|
|
2683
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-tile-sym", children: props.pick.symbol }),
|
|
2684
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-tile-chain", children: CHAIN_LABELS[props.pick.chainId] || `Chain ${props.pick.chainId}` })
|
|
2685
|
+
] })
|
|
2686
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
2687
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-tok", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-tok-fb", children: "?" }) }),
|
|
2688
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-tile-empty", children: "Select\u2026" })
|
|
2689
|
+
] });
|
|
2690
|
+
const ariaLabel = `${props.label}: ${props.pick ? `${props.pick.symbol} on ${CHAIN_LABELS[props.pick.chainId] || props.pick.chainId}` : "select token"}`;
|
|
2691
|
+
if (props.row) {
|
|
2692
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("button", { type: "button", ref: props.btnRef, className: "sg-tile sg-tile--row", disabled: props.disabled, onClick: props.onClick, "aria-label": ariaLabel, children: [
|
|
2693
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-tile-label", children: props.label }),
|
|
2694
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-tile-rowmain", children: glyph }),
|
|
2695
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-tile-chev", children: /* @__PURE__ */ jsxRuntime.jsx(ChevronGlyph, {}) })
|
|
2696
|
+
] });
|
|
2697
|
+
}
|
|
2698
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("button", { type: "button", ref: props.btnRef, className: "sg-tile", disabled: props.disabled, onClick: props.onClick, "aria-label": ariaLabel, children: [
|
|
2699
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-tile-label", children: props.label }),
|
|
2700
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-tile-main", children: glyph })
|
|
2701
|
+
] });
|
|
2702
|
+
}
|
|
2703
|
+
function ChainChip(props) {
|
|
2704
|
+
const [broken, setBroken] = react.useState(false);
|
|
2705
|
+
const logo = props.chain?.logoUrl;
|
|
2706
|
+
const showImg = isHttpsUrl(logo) && !broken;
|
|
2707
|
+
return /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "sg-chain-chip", "data-selected": props.selected, title: props.label, "aria-pressed": props.selected, onClick: props.onClick, children: showImg ? /* @__PURE__ */ jsxRuntime.jsx("img", { src: logo, alt: props.label, loading: "lazy", onError: () => setBroken(true) }) : props.label });
|
|
2708
|
+
}
|
|
2709
|
+
function SearchGlyph() {
|
|
2710
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.4", strokeLinecap: "round", "aria-hidden": "true", children: [
|
|
2711
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "11", cy: "11", r: "7" }),
|
|
2712
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "m20 20-3.5-3.5" })
|
|
2713
|
+
] });
|
|
2714
|
+
}
|
|
2715
|
+
function BackGlyph() {
|
|
2716
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "17", height: "17", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.4", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
|
|
2717
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M19 12H5" }),
|
|
2718
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "m12 19-7-7 7-7" })
|
|
2719
|
+
] });
|
|
2720
|
+
}
|
|
2721
|
+
function TokenSelect(props) {
|
|
2722
|
+
const [chainFilter, setChainFilter] = react.useState(null);
|
|
2723
|
+
const [query, setQuery] = react.useState("");
|
|
2724
|
+
const rows = react.useMemo(() => {
|
|
2725
|
+
const q = query.trim().toLowerCase();
|
|
2726
|
+
const filtered = props.tokens.filter((t) => chainFilter == null ? true : Number(t.chainId) === chainFilter).filter((t) => {
|
|
2727
|
+
if (!q) return true;
|
|
2728
|
+
return String(t.symbol || "").toLowerCase().includes(q) || String(t.name || "").toLowerCase().includes(q) || String(t.address || "").toLowerCase().includes(q);
|
|
2729
|
+
});
|
|
2730
|
+
if (!props.balances) return filtered;
|
|
2731
|
+
const balNum = (t) => {
|
|
2732
|
+
const n = Number(props.balances?.[`${Number(t.chainId)}:${String(t.address || "").toLowerCase()}`]?.formatted);
|
|
2733
|
+
return Number.isFinite(n) ? n : 0;
|
|
2734
|
+
};
|
|
2735
|
+
return [...filtered].sort((a, b) => balNum(b) - balNum(a));
|
|
2736
|
+
}, [props.tokens, chainFilter, query, props.balances]);
|
|
2737
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
2738
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-sel-head", children: [
|
|
2739
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "sg-back", onClick: props.onBack, "aria-label": "Back", children: /* @__PURE__ */ jsxRuntime.jsx(BackGlyph, {}) }),
|
|
2740
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-sel-title", children: props.title })
|
|
2741
|
+
] }),
|
|
2742
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-chain-grid", role: "group", "aria-label": "Filter by chain", children: [
|
|
2743
|
+
/* @__PURE__ */ jsxRuntime.jsx(ChainChip, { label: "All", selected: chainFilter == null, onClick: () => setChainFilter(null) }),
|
|
2744
|
+
props.chains.map((c) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2745
|
+
ChainChip,
|
|
2746
|
+
{
|
|
2747
|
+
chain: c,
|
|
2748
|
+
label: CHAIN_SHORT[Number(c.chainId)] || String(c.chainId),
|
|
2749
|
+
selected: chainFilter === Number(c.chainId),
|
|
2750
|
+
onClick: () => setChainFilter(Number(c.chainId))
|
|
2751
|
+
},
|
|
2752
|
+
c.chainId
|
|
2753
|
+
))
|
|
2754
|
+
] }),
|
|
2755
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-search", children: [
|
|
2756
|
+
/* @__PURE__ */ jsxRuntime.jsx(SearchGlyph, {}),
|
|
2757
|
+
/* @__PURE__ */ jsxRuntime.jsx("input", { autoFocus: true, placeholder: "Search by token or address", value: query, onChange: (e) => setQuery(e.target.value), spellCheck: false, "aria-label": "Search by token or address" })
|
|
2758
|
+
] }),
|
|
2759
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-toklist", role: "group", "aria-label": props.title, children: rows.length ? rows.map((t) => {
|
|
2760
|
+
const chainId = Number(t.chainId);
|
|
2761
|
+
const key = `${chainId}:${String(t.address || "").toLowerCase()}`;
|
|
2762
|
+
const bal = props.balances?.[key];
|
|
2763
|
+
const st = props.optionStates?.[key];
|
|
2764
|
+
const disabled = !!st?.disabled;
|
|
2765
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2766
|
+
"button",
|
|
2767
|
+
{
|
|
2768
|
+
type: "button",
|
|
2769
|
+
className: `sg-tokrow${disabled ? " sg-tokrow--off" : ""}`,
|
|
2770
|
+
disabled,
|
|
2771
|
+
"aria-disabled": disabled || void 0,
|
|
2772
|
+
"data-disabled": disabled || void 0,
|
|
2773
|
+
onClick: disabled ? void 0 : () => props.onPick({ chainId, symbol: t.symbol }),
|
|
2774
|
+
children: [
|
|
2775
|
+
/* @__PURE__ */ jsxRuntime.jsx(TokenGlyph, { symbol: t.symbol, logoUrl: t.logoUrl, chainId }),
|
|
2776
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-tokrow-main", children: [
|
|
2777
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-tokrow-sym", children: t.symbol }),
|
|
2778
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-tokrow-name", children: t.name || t.symbol })
|
|
2779
|
+
] }),
|
|
2780
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-tokrow-end", children: [
|
|
2781
|
+
bal ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-tokrow-bal sg-mono", children: bal.formatted }) : null,
|
|
2782
|
+
disabled && st?.hint ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-tokrow-hint", children: st.hint }) : null,
|
|
2783
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-tokrow-chain", children: CHAIN_LABELS[chainId] || `Chain ${chainId}` })
|
|
2784
|
+
] })
|
|
2785
|
+
]
|
|
2786
|
+
},
|
|
2787
|
+
`${chainId}:${t.address}`
|
|
2788
|
+
);
|
|
2789
|
+
}) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-sel-empty", children: "No tokens match \u2014 try another chain or search." }) })
|
|
2790
|
+
] });
|
|
2791
|
+
}
|
|
2792
|
+
function useTxHistory(account) {
|
|
2793
|
+
const [entries, setEntries] = react.useState(() => readTxHistory(account));
|
|
2794
|
+
react.useEffect(() => {
|
|
2795
|
+
setEntries(readTxHistory(account));
|
|
2796
|
+
if (typeof window === "undefined" || !account) return;
|
|
2797
|
+
const key = txHistoryKey(account);
|
|
2798
|
+
const onLocal = (e) => {
|
|
2799
|
+
const detail = e.detail;
|
|
2800
|
+
if (!detail?.account || detail.account === account.toLowerCase()) setEntries(readTxHistory(account));
|
|
2801
|
+
};
|
|
2802
|
+
const onStorage = (e) => {
|
|
2803
|
+
if (e.key === key) setEntries(readTxHistory(account));
|
|
2804
|
+
};
|
|
2805
|
+
window.addEventListener(TX_HISTORY_EVENT, onLocal);
|
|
2806
|
+
window.addEventListener("storage", onStorage);
|
|
2807
|
+
return () => {
|
|
2808
|
+
window.removeEventListener(TX_HISTORY_EVENT, onLocal);
|
|
2809
|
+
window.removeEventListener("storage", onStorage);
|
|
2810
|
+
};
|
|
2811
|
+
}, [account]);
|
|
2812
|
+
return entries;
|
|
2813
|
+
}
|
|
2814
|
+
function BackGlyph2() {
|
|
2815
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "17", height: "17", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.4", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
|
|
2816
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M19 12H5" }),
|
|
2817
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "m12 19-7-7 7-7" })
|
|
2818
|
+
] });
|
|
2819
|
+
}
|
|
2820
|
+
function HistoryGlyph() {
|
|
2821
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
|
|
2822
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M3 12a9 9 0 1 0 3-6.7" }),
|
|
2823
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M3 4v5h5" }),
|
|
2824
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M12 8v4l3 2" })
|
|
2825
|
+
] });
|
|
2826
|
+
}
|
|
2827
|
+
function CopyGlyph() {
|
|
2828
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "13", height: "13", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
|
|
2829
|
+
/* @__PURE__ */ jsxRuntime.jsx("rect", { x: "9", y: "9", width: "12", height: "12", rx: "2" }),
|
|
2830
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" })
|
|
2831
|
+
] });
|
|
2832
|
+
}
|
|
2833
|
+
function CheckGlyph() {
|
|
2834
|
+
return /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "13", height: "13", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.6", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M20 6 9 17l-5-5" }) });
|
|
2835
|
+
}
|
|
2836
|
+
function HistoryButton(props) {
|
|
2837
|
+
return /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", ref: props.btnRef, className: "sg-hist", disabled: props.disabled, onClick: props.onClick, "aria-label": "Transaction history", title: "Transaction history", children: /* @__PURE__ */ jsxRuntime.jsx(HistoryGlyph, {}) });
|
|
2838
|
+
}
|
|
2839
|
+
function chainLabel(entry) {
|
|
2840
|
+
return entry.chainId != null && CHAIN_LABELS[entry.chainId] || entry.chainName || (entry.chainId != null ? `Chain ${entry.chainId}` : "Unknown chain");
|
|
2841
|
+
}
|
|
2842
|
+
function statusBadge(status) {
|
|
2843
|
+
if (status === "confirmed")
|
|
2844
|
+
return /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-badge", "data-tone": "ok", children: "Confirmed" });
|
|
2845
|
+
if (status === "error")
|
|
2846
|
+
return /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-badge", "data-tone": "warn", children: "Failed" });
|
|
2847
|
+
return /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-badge", children: "Pending" });
|
|
2848
|
+
}
|
|
2849
|
+
function whenLabel(at) {
|
|
2850
|
+
const d = new Date(at);
|
|
2851
|
+
return Number.isNaN(d.getTime()) ? "" : d.toLocaleString();
|
|
2852
|
+
}
|
|
2853
|
+
function logoFor(tokens, symbol, chainId) {
|
|
2854
|
+
if (!tokens?.length) return void 0;
|
|
2855
|
+
const key = symbolKey(symbol);
|
|
2856
|
+
if (!key) return void 0;
|
|
2857
|
+
const sameChain = chainId == null ? void 0 : tokens.find((t) => Number(t.chainId) === chainId && symbolKey(t.symbol) === key);
|
|
2858
|
+
return (sameChain ?? tokens.find((t) => symbolKey(t.symbol) === key))?.logoUrl;
|
|
2859
|
+
}
|
|
2860
|
+
function TxHistoryList(props) {
|
|
2861
|
+
if (!props.entries.length) {
|
|
2862
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-sel-empty", children: "No transactions yet \u2014 activity from this wallet will appear here." });
|
|
2863
|
+
}
|
|
2864
|
+
return /* @__PURE__ */ jsxRuntime.jsx("section", { className: "sg-toklist", "aria-label": "Transaction history", children: props.entries.map((e) => /* @__PURE__ */ jsxRuntime.jsxs("button", { type: "button", className: "sg-tokrow", onClick: () => props.onPick(e), children: [
|
|
2865
|
+
/* @__PURE__ */ jsxRuntime.jsx(TokenGlyph, { symbol: e.fromAsset || e.toAsset || "?", logoUrl: logoFor(props.tokens, e.fromAsset, e.chainId), chainId: e.chainId ?? void 0 }),
|
|
2866
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-tokrow-main", children: [
|
|
2867
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-tokrow-sym sg-mono", children: [
|
|
2868
|
+
e.payAmount,
|
|
2869
|
+
" ",
|
|
2870
|
+
e.fromAsset,
|
|
2871
|
+
" \u2192 ",
|
|
2872
|
+
e.receiveAmount,
|
|
2873
|
+
" ",
|
|
2874
|
+
e.toAsset
|
|
2875
|
+
] }),
|
|
2876
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-tokrow-name", children: [
|
|
2877
|
+
e.kind === "payment" ? "Payment" : "Swap",
|
|
2878
|
+
" \xB7 ",
|
|
2879
|
+
chainLabel(e),
|
|
2880
|
+
whenLabel(e.at) ? ` \xB7 ${whenLabel(e.at)}` : ""
|
|
2881
|
+
] })
|
|
2882
|
+
] }),
|
|
2883
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-tokrow-end", children: statusBadge(e.status) })
|
|
2884
|
+
] }, `${e.hash}:${e.at}`)) });
|
|
2885
|
+
}
|
|
2886
|
+
function TxDetail(props) {
|
|
2887
|
+
const e = props.entry;
|
|
2888
|
+
const [copied, setCopied] = react.useState(false);
|
|
2889
|
+
const copyTimer = react.useRef(null);
|
|
2890
|
+
react.useEffect(
|
|
2891
|
+
() => () => {
|
|
2892
|
+
if (copyTimer.current) clearTimeout(copyTimer.current);
|
|
2893
|
+
},
|
|
2894
|
+
[]
|
|
2895
|
+
);
|
|
2896
|
+
const copyHash = async () => {
|
|
2897
|
+
try {
|
|
2898
|
+
if (!navigator.clipboard?.writeText) return;
|
|
2899
|
+
await navigator.clipboard.writeText(e.hash);
|
|
2900
|
+
setCopied(true);
|
|
2901
|
+
if (copyTimer.current) clearTimeout(copyTimer.current);
|
|
2902
|
+
copyTimer.current = setTimeout(() => setCopied(false), 1500);
|
|
2903
|
+
} catch {
|
|
2904
|
+
}
|
|
2905
|
+
};
|
|
2906
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-panel", children: [
|
|
2907
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-anchor sg-mono", children: [
|
|
2908
|
+
e.receiveAmount,
|
|
2909
|
+
" ",
|
|
2910
|
+
e.toAsset
|
|
2911
|
+
] }),
|
|
2912
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-anchor-sub", children: [
|
|
2913
|
+
e.kind === "payment" ? "Payment" : "Swap",
|
|
2914
|
+
whenLabel(e.at) ? ` \xB7 ${whenLabel(e.at)}` : ""
|
|
2915
|
+
] }),
|
|
2916
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-meta", children: [
|
|
2917
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-meta-row", children: [
|
|
2918
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-meta-label", children: "Status" }),
|
|
2919
|
+
statusBadge(e.status)
|
|
2920
|
+
] }),
|
|
2921
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-meta-row", children: [
|
|
2922
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-meta-label", children: "You sent" }),
|
|
2923
|
+
/* @__PURE__ */ jsxRuntime.jsxs("b", { className: "sg-mono", children: [
|
|
2924
|
+
e.payAmount,
|
|
2925
|
+
" ",
|
|
2926
|
+
e.fromAsset
|
|
2927
|
+
] })
|
|
2928
|
+
] }),
|
|
2929
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-meta-row", children: [
|
|
2930
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-meta-label", children: "Chain" }),
|
|
2931
|
+
/* @__PURE__ */ jsxRuntime.jsx("b", { children: chainLabel(e) })
|
|
2932
|
+
] }),
|
|
2933
|
+
e.recipient ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-meta-row", children: [
|
|
2934
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-meta-label", children: "Recipient" }),
|
|
2935
|
+
/* @__PURE__ */ jsxRuntime.jsx("b", { className: "sg-mono", children: shortAddress(e.recipient) })
|
|
2936
|
+
] }) : null,
|
|
2937
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-meta-row", children: [
|
|
2938
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-meta-label", children: "Settlement" }),
|
|
2939
|
+
/* @__PURE__ */ jsxRuntime.jsx("b", { children: e.settlement === "direct" ? "Direct" : "Escrow" })
|
|
2940
|
+
] })
|
|
2941
|
+
] }),
|
|
2942
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-txd-hash", children: [
|
|
2943
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-meta-label", children: "Tx hash" }),
|
|
2944
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-mono", children: `${e.hash.slice(0, 10)}\u2026${e.hash.slice(-8)}` }),
|
|
2945
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "sg-copy", onClick: copyHash, "aria-label": copied ? "Copied" : "Copy transaction hash", "aria-live": "polite", title: "Copy transaction hash", children: copied ? /* @__PURE__ */ jsxRuntime.jsx(CheckGlyph, {}) : /* @__PURE__ */ jsxRuntime.jsx(CopyGlyph, {}) })
|
|
2946
|
+
] })
|
|
2947
|
+
] });
|
|
2948
|
+
}
|
|
2949
|
+
function displayableHistory(entries) {
|
|
2950
|
+
return entries.filter((e) => e.txKind !== "approve");
|
|
2951
|
+
}
|
|
2952
|
+
function TxHistoryPanel(props) {
|
|
2953
|
+
const entries = displayableHistory(useTxHistory(props.account));
|
|
2954
|
+
const [selected, setSelected] = react.useState(props.initialEntry ?? null);
|
|
2955
|
+
const backRef = react.useRef(null);
|
|
2956
|
+
react.useEffect(() => setSelected(props.initialEntry ?? null), [props.initialEntry]);
|
|
2957
|
+
const pick = (entry) => {
|
|
2958
|
+
setSelected(entry);
|
|
2959
|
+
requestAnimationFrame(() => backRef.current?.focus());
|
|
2960
|
+
};
|
|
2961
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
2962
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-sel-head", children: [
|
|
2963
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", autoFocus: true, ref: backRef, className: "sg-back", onClick: selected ? () => setSelected(null) : props.onBack, "aria-label": "Back", children: /* @__PURE__ */ jsxRuntime.jsx(BackGlyph2, {}) }),
|
|
2964
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-sel-title", children: selected ? "Transaction" : "Transaction history" })
|
|
2965
|
+
] }),
|
|
2966
|
+
selected ? /* @__PURE__ */ jsxRuntime.jsx(TxDetail, { entry: selected }) : /* @__PURE__ */ jsxRuntime.jsx(TxHistoryList, { entries, tokens: props.tokens, onPick: pick })
|
|
2967
|
+
] });
|
|
2968
|
+
}
|
|
2969
|
+
var IDENTITY_KEY_PREFIX = "sg:link:v1:";
|
|
2970
|
+
var LEGACY_IDENTITY_KEY = "zd-link-identity";
|
|
2971
|
+
var ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;
|
|
2972
|
+
var EMAIL_RE = /^[^\s@]{1,64}@[^\s@]{1,190}$/;
|
|
2973
|
+
function identityKey(account) {
|
|
2974
|
+
return `${IDENTITY_KEY_PREFIX}${account.toLowerCase()}`;
|
|
2975
|
+
}
|
|
2976
|
+
function storage() {
|
|
2977
|
+
try {
|
|
2978
|
+
return typeof window !== "undefined" ? window.localStorage : null;
|
|
2979
|
+
} catch {
|
|
2980
|
+
return null;
|
|
2981
|
+
}
|
|
2982
|
+
}
|
|
2983
|
+
function parseIdentity(raw) {
|
|
2984
|
+
if (!raw) return null;
|
|
2985
|
+
try {
|
|
2986
|
+
const p = JSON.parse(raw);
|
|
2987
|
+
if (!p || typeof p !== "object") return null;
|
|
2988
|
+
const walletAddress = typeof p.walletAddress === "string" ? p.walletAddress : "";
|
|
2989
|
+
if (!ADDRESS_RE.test(walletAddress)) return null;
|
|
2990
|
+
const preferredChainId = Number(p.preferredChainId);
|
|
2991
|
+
if (!Number.isFinite(preferredChainId) || !SUPPORTED_CHAIN_IDS.has(preferredChainId)) return null;
|
|
2992
|
+
const preferredAsset = String(p.preferredAsset || "").toUpperCase();
|
|
2993
|
+
if (!SUPPORTED_ASSETS.has(preferredAsset)) return null;
|
|
2994
|
+
const email = typeof p.email === "string" && EMAIL_RE.test(p.email) ? p.email : void 0;
|
|
2995
|
+
const lastUsedAt = typeof p.lastUsedAt === "string" ? p.lastUsedAt.slice(0, 40) : "";
|
|
2996
|
+
return { email, walletAddress, preferredAsset, preferredChainId, lastUsedAt };
|
|
2997
|
+
} catch {
|
|
2998
|
+
return null;
|
|
2999
|
+
}
|
|
3000
|
+
}
|
|
3001
|
+
function loadIdentity(account) {
|
|
3002
|
+
const s = storage();
|
|
3003
|
+
if (!s || !account || !ADDRESS_RE.test(account)) return null;
|
|
3004
|
+
try {
|
|
3005
|
+
return parseIdentity(s.getItem(identityKey(account)));
|
|
3006
|
+
} catch {
|
|
3007
|
+
return null;
|
|
3008
|
+
}
|
|
3009
|
+
}
|
|
3010
|
+
function saveIdentity(id) {
|
|
3011
|
+
const s = storage();
|
|
3012
|
+
if (!s || !ADDRESS_RE.test(id.walletAddress)) return;
|
|
3013
|
+
try {
|
|
3014
|
+
s.setItem(identityKey(id.walletAddress), JSON.stringify(id));
|
|
3015
|
+
s.removeItem(LEGACY_IDENTITY_KEY);
|
|
3016
|
+
} catch {
|
|
3017
|
+
}
|
|
3018
|
+
}
|
|
3019
|
+
function forgetIdentity(account) {
|
|
3020
|
+
const s = storage();
|
|
3021
|
+
if (!s) return;
|
|
3022
|
+
try {
|
|
3023
|
+
if (account && ADDRESS_RE.test(account)) s.removeItem(identityKey(account));
|
|
3024
|
+
s.removeItem(LEGACY_IDENTITY_KEY);
|
|
3025
|
+
} catch {
|
|
3026
|
+
}
|
|
3027
|
+
}
|
|
3028
|
+
var addrEq = (a, b) => String(a || "").toLowerCase() === String(b || "").toLowerCase();
|
|
3029
|
+
var chainName = (id) => id != null ? CHAIN_LABELS[id] || `Chain ${id}` : "";
|
|
3030
|
+
var STABLES = /* @__PURE__ */ new Set(["USDC", "USDT", "USDE"]);
|
|
3031
|
+
function MerchantReceives(props) {
|
|
3032
|
+
const [open, setOpen] = react.useState(false);
|
|
3033
|
+
const bodyId = react.useId();
|
|
3034
|
+
const hasDetails = Boolean(props.recipient);
|
|
3035
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-panel sg-merch", children: [
|
|
3036
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-merch-head", children: [
|
|
3037
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-merch-lead", children: [
|
|
3038
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-label", children: "Merchant receives exactly" }),
|
|
3039
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-anchor sg-mono", children: [
|
|
3040
|
+
props.amount,
|
|
3041
|
+
" ",
|
|
3042
|
+
props.asset
|
|
3043
|
+
] })
|
|
3044
|
+
] }),
|
|
3045
|
+
hasDetails ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3046
|
+
"button",
|
|
3047
|
+
{
|
|
3048
|
+
type: "button",
|
|
3049
|
+
className: "sg-details-toggle",
|
|
3050
|
+
"data-open": open,
|
|
3051
|
+
"aria-expanded": open,
|
|
3052
|
+
"aria-controls": bodyId,
|
|
3053
|
+
onClick: () => setOpen((o) => !o),
|
|
3054
|
+
children: [
|
|
3055
|
+
"Details",
|
|
3056
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-details-chev", "aria-hidden": "true", children: "\u2304" })
|
|
3057
|
+
]
|
|
3058
|
+
}
|
|
3059
|
+
) : null
|
|
3060
|
+
] }),
|
|
3061
|
+
hasDetails ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-details-reveal", "data-open": open, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-details-reveal-inner", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-details-body", id: bodyId, children: [
|
|
3062
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-details-row", children: [
|
|
3063
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-details-k", children: "Network" }),
|
|
3064
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-details-v", children: chainName(props.chainId) })
|
|
3065
|
+
] }),
|
|
3066
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-details-row", children: [
|
|
3067
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-details-k", children: "Recipient" }),
|
|
3068
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-details-v sg-mono sg-details-addr", children: props.recipient })
|
|
3069
|
+
] }),
|
|
3070
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-details-note", children: [
|
|
3071
|
+
"Settled like a card \u2014 the merchant always receives exactly ",
|
|
3072
|
+
props.amount,
|
|
3073
|
+
" ",
|
|
3074
|
+
props.asset,
|
|
3075
|
+
". You pay a little more to cover the network cost."
|
|
3076
|
+
] })
|
|
3077
|
+
] }) }) }) : null
|
|
3078
|
+
] });
|
|
3079
|
+
}
|
|
3080
|
+
function BankGlyph() {
|
|
3081
|
+
return /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M3 10h18M5 10v8M10 10v8M14 10v8M19 10v8M3 19h18M12 3 3 8h18Z" }) });
|
|
3082
|
+
}
|
|
3083
|
+
function MerchantBankPayout(props) {
|
|
3084
|
+
const bankName = props.account?.bankName?.trim() || "Bank account";
|
|
3085
|
+
const last4 = props.account?.last4?.trim();
|
|
3086
|
+
const currency = props.account?.currency?.trim();
|
|
3087
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-panel sg-merch", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-merch-head", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-merch-lead", children: [
|
|
3088
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-label", children: "Merchant receives" }),
|
|
3089
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-bank", children: [
|
|
3090
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-bank-icon", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx(BankGlyph, {}) }),
|
|
3091
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-bank-text", children: [
|
|
3092
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-bank-name", children: [
|
|
3093
|
+
bankName,
|
|
3094
|
+
last4 ? /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-mono", children: [
|
|
3095
|
+
" \xB7\xB7\xB7\xB7",
|
|
3096
|
+
last4
|
|
3097
|
+
] }) : null
|
|
3098
|
+
] }),
|
|
3099
|
+
currency ? /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-bank-cur", children: [
|
|
3100
|
+
"Paid out in ",
|
|
3101
|
+
currency
|
|
3102
|
+
] }) : null
|
|
3103
|
+
] })
|
|
3104
|
+
] })
|
|
3105
|
+
] }) }) });
|
|
3106
|
+
}
|
|
3107
|
+
function CheckGlyph2() {
|
|
3108
|
+
return /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "3", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M20 6 9 17l-5-5" }) });
|
|
3109
|
+
}
|
|
3110
|
+
function ArrowGlyph() {
|
|
3111
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.4", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
|
|
3112
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M5 12h14" }),
|
|
3113
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "m13 6 6 6-6 6" })
|
|
3114
|
+
] });
|
|
3115
|
+
}
|
|
3116
|
+
function ClockGlyph() {
|
|
3117
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
|
|
3118
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "12", r: "9" }),
|
|
3119
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M12 7v5l3 2" })
|
|
3120
|
+
] });
|
|
3121
|
+
}
|
|
3122
|
+
function WalletGlyph() {
|
|
3123
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
|
|
3124
|
+
/* @__PURE__ */ jsxRuntime.jsx("rect", { x: "3", y: "6", width: "18", height: "13", rx: "2" }),
|
|
3125
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M16 12h.01M3 9h18" })
|
|
3126
|
+
] });
|
|
3127
|
+
}
|
|
3128
|
+
function LinkMenu(props) {
|
|
3129
|
+
const [open, setOpen] = react.useState(false);
|
|
3130
|
+
const [active, setActive] = react.useState(0);
|
|
3131
|
+
const btnRef = react.useRef(null);
|
|
3132
|
+
const menuRef = react.useRef(null);
|
|
3133
|
+
const itemRefs = react.useRef([]);
|
|
3134
|
+
const menuId = react.useId();
|
|
3135
|
+
const close = (restoreFocus = true) => {
|
|
3136
|
+
setOpen(false);
|
|
3137
|
+
if (restoreFocus) requestAnimationFrame(() => btnRef.current?.focus());
|
|
3138
|
+
};
|
|
3139
|
+
react.useEffect(() => {
|
|
3140
|
+
if (!open) return;
|
|
3141
|
+
setActive(0);
|
|
3142
|
+
const onDoc = (e) => {
|
|
3143
|
+
if (!menuRef.current?.contains(e.target) && !btnRef.current?.contains(e.target)) setOpen(false);
|
|
3144
|
+
};
|
|
3145
|
+
document.addEventListener("mousedown", onDoc);
|
|
3146
|
+
requestAnimationFrame(() => itemRefs.current[0]?.focus());
|
|
3147
|
+
return () => document.removeEventListener("mousedown", onDoc);
|
|
3148
|
+
}, [open]);
|
|
3149
|
+
const focusAt = (i) => {
|
|
3150
|
+
const n = props.items.length;
|
|
3151
|
+
const idx = (i % n + n) % n;
|
|
3152
|
+
setActive(idx);
|
|
3153
|
+
itemRefs.current[idx]?.focus();
|
|
3154
|
+
};
|
|
3155
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-link-menu-wrap", children: [
|
|
3156
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3157
|
+
"button",
|
|
3158
|
+
{
|
|
3159
|
+
ref: btnRef,
|
|
3160
|
+
type: "button",
|
|
3161
|
+
className: "sg-link-menu-btn",
|
|
3162
|
+
"aria-haspopup": "menu",
|
|
3163
|
+
"aria-expanded": open,
|
|
3164
|
+
"aria-controls": open ? menuId : void 0,
|
|
3165
|
+
"aria-label": "ZeroDelta Link options",
|
|
3166
|
+
onClick: () => setOpen((o) => !o),
|
|
3167
|
+
children: "\u22EF"
|
|
3168
|
+
}
|
|
3169
|
+
),
|
|
3170
|
+
open ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
3171
|
+
"div",
|
|
3172
|
+
{
|
|
3173
|
+
ref: menuRef,
|
|
3174
|
+
id: menuId,
|
|
3175
|
+
className: "sg-link-menu",
|
|
3176
|
+
role: "menu",
|
|
3177
|
+
"aria-label": "ZeroDelta Link options",
|
|
3178
|
+
onKeyDown: (e) => {
|
|
3179
|
+
if (e.key === "Escape") {
|
|
3180
|
+
e.preventDefault();
|
|
3181
|
+
close();
|
|
3182
|
+
} else if (e.key === "Tab") {
|
|
3183
|
+
close(false);
|
|
3184
|
+
}
|
|
3185
|
+
},
|
|
3186
|
+
children: props.items.map((it, i) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
3187
|
+
"button",
|
|
3188
|
+
{
|
|
3189
|
+
ref: (el) => {
|
|
3190
|
+
itemRefs.current[i] = el;
|
|
3191
|
+
},
|
|
3192
|
+
type: "button",
|
|
3193
|
+
role: "menuitem",
|
|
3194
|
+
tabIndex: i === active ? 0 : -1,
|
|
3195
|
+
className: "sg-link-menu-item",
|
|
3196
|
+
"data-tone": it.tone,
|
|
3197
|
+
onClick: () => {
|
|
3198
|
+
close(!it.collapses);
|
|
3199
|
+
it.onSelect();
|
|
3200
|
+
},
|
|
3201
|
+
onKeyDown: (e) => {
|
|
3202
|
+
if (e.key === "ArrowDown") {
|
|
3203
|
+
e.preventDefault();
|
|
3204
|
+
focusAt(i + 1);
|
|
3205
|
+
} else if (e.key === "ArrowUp") {
|
|
3206
|
+
e.preventDefault();
|
|
3207
|
+
focusAt(i - 1);
|
|
3208
|
+
} else if (e.key === "Home") {
|
|
3209
|
+
e.preventDefault();
|
|
3210
|
+
focusAt(0);
|
|
3211
|
+
} else if (e.key === "End") {
|
|
3212
|
+
e.preventDefault();
|
|
3213
|
+
focusAt(props.items.length - 1);
|
|
3214
|
+
}
|
|
3215
|
+
},
|
|
3216
|
+
children: it.label
|
|
3217
|
+
},
|
|
3218
|
+
it.label
|
|
3219
|
+
))
|
|
3220
|
+
}
|
|
3221
|
+
) : null
|
|
3222
|
+
] });
|
|
3223
|
+
}
|
|
3224
|
+
function IdentityLine(props) {
|
|
3225
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-link-id", children: [
|
|
3226
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-link-id-icon", children: /* @__PURE__ */ jsxRuntime.jsx(WalletGlyph, {}) }),
|
|
3227
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-link-id-text", children: [
|
|
3228
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-link-id-primary", children: props.account ? shortAddress(props.account) : "ZeroDelta Link" }),
|
|
3229
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-link-id-secondary", children: props.email ? props.email : props.account ? "Connected wallet" : "Connect your wallet to continue" })
|
|
3230
|
+
] }),
|
|
3231
|
+
props.account ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-wallet-dot", "aria-hidden": "true" }) : null
|
|
3232
|
+
] });
|
|
3233
|
+
}
|
|
3234
|
+
function PaymentIsland(props) {
|
|
3235
|
+
injectStyles();
|
|
3236
|
+
const config = useMergedConfig(props);
|
|
3237
|
+
const engine = useEngine({ apiBase: config.apiBase, apiKey: config.apiKey, trustedApiOrigin: config.trustedApiOrigin, rpcOverrides: config.rpcOverrides, onTransaction: config.onTransaction });
|
|
3238
|
+
const wallet = useWallet(config.provider);
|
|
3239
|
+
const kind = props.kind;
|
|
3240
|
+
const isPay = kind === "pay";
|
|
3241
|
+
const mode = props.mode ?? "exchange";
|
|
3242
|
+
const rampMode = kind === "exchange" && mode !== "exchange";
|
|
3243
|
+
const bankSettlement = isPay && props.settlement === "bank";
|
|
3244
|
+
const exAllowed = react.useMemo(
|
|
3245
|
+
() => (props.assets?.length ? props.assets : ["USDC", "USDT", "USDE"]).map((a) => symbolKey(a)),
|
|
3246
|
+
[props.assets]
|
|
3247
|
+
);
|
|
3248
|
+
const [exFrom, setExFrom] = react.useState(() => {
|
|
3249
|
+
const chainId = props.defaultFromChainId ?? (kind === "swap" ? 42161 : void 0);
|
|
3250
|
+
const asset = props.defaultFromAsset ?? (kind === "swap" ? "USDT" : void 0);
|
|
3251
|
+
return chainId && asset && exAllowed.includes(symbolKey(asset)) ? { chainId, symbol: symbolKey(asset) } : null;
|
|
3252
|
+
});
|
|
3253
|
+
const [exTo, setExTo] = react.useState(() => {
|
|
3254
|
+
const chainId = props.defaultToChainId ?? (kind === "swap" ? 8453 : void 0);
|
|
3255
|
+
const asset = props.defaultToAsset ?? (kind === "swap" ? "USDC" : void 0);
|
|
3256
|
+
return chainId && asset && exAllowed.includes(symbolKey(asset)) ? { chainId, symbol: symbolKey(asset) } : null;
|
|
3257
|
+
});
|
|
3258
|
+
const [exAmount, setExAmount] = react.useState(props.defaultAmount ?? "");
|
|
3259
|
+
const exFromChainId = exFrom?.chainId;
|
|
3260
|
+
const exFromAsset = exFrom?.symbol;
|
|
3261
|
+
const exToChainId = exTo?.chainId;
|
|
3262
|
+
const exToAsset = exTo?.symbol;
|
|
3263
|
+
const normEx = normalizeDecimalText(exAmount);
|
|
3264
|
+
const exAmountValid = /^\d+(\.\d+)?$/.test(normEx) && Number(normEx) > 0 && Number(normEx) <= 1e9;
|
|
3265
|
+
const exQuotable = !rampMode && exAmountValid && Boolean(exFromChainId && exFromAsset && exToChainId && exToAsset);
|
|
3266
|
+
const payParamsKey = `pay|${props.recipient}|${props.toChainId}|${props.toAsset}|${props.amount}`;
|
|
3267
|
+
const exParamsKey = `${kind}|${mode}|${exFromChainId}|${exFromAsset}|${exToChainId}|${exToAsset}|${normEx}|${props.recipient ?? ""}`;
|
|
3268
|
+
const flow = useFlow({
|
|
3269
|
+
engine,
|
|
3270
|
+
wallet,
|
|
3271
|
+
kind: isPay ? "payment" : "swap",
|
|
3272
|
+
// Bank settlement parks the card, so gate the network work off too — otherwise the island would
|
|
3273
|
+
// quote (and fire onQuote) for a payment whose CTA it never shows.
|
|
3274
|
+
enabled: isPay ? Boolean(props.recipient && props.amount) && !bankSettlement : exQuotable,
|
|
3275
|
+
paramsKey: isPay ? payParamsKey : exParamsKey,
|
|
3276
|
+
loadPlan: isPay ? (e, payer, chainId) => e.fetchPaymentPlan({ address: props.recipient, chainId: props.toChainId, asset: props.toAsset, amount: props.amount }, payer, { chainId }) : (e, payer) => e.buildSwapPlan({ fromChainId: exFromChainId, toChainId: exToChainId, fromToken: exFromAsset, toToken: exToAsset, amountIn: normEx, recipient: props.recipient }, payer),
|
|
3277
|
+
recipientFor: (account) => isPay ? props.recipient : props.recipient || account,
|
|
3278
|
+
onQuote: config.onQuote,
|
|
3279
|
+
onSuccess: config.onSuccess,
|
|
3280
|
+
onError: config.onError
|
|
3281
|
+
});
|
|
3282
|
+
const [method, setMethod] = react.useState("recommended");
|
|
3283
|
+
const parked = isPay && !isLiveMethod(method);
|
|
3284
|
+
const fundingSet = react.useMemo(
|
|
3285
|
+
() => props.fundingAssets?.length ? new Set(props.fundingAssets.map((a) => a.toUpperCase())) : null,
|
|
3286
|
+
[props.fundingAssets]
|
|
3287
|
+
);
|
|
3288
|
+
const visibleRoutes = react.useMemo(() => {
|
|
3289
|
+
const base = fundingSet ? flow.routes.filter((r) => fundingSet.has(r.source.asset.toUpperCase()) || r.state === "DIRECT") : flow.routes;
|
|
3290
|
+
return isPay && method === "stablecoin" ? base.filter((r) => STABLES.has(r.source.asset)) : base;
|
|
3291
|
+
}, [flow.routes, fundingSet, isPay, method]);
|
|
3292
|
+
const holdings = useHoldings(engine, wallet.account, flow.routes);
|
|
3293
|
+
const annotated = react.useMemo(
|
|
3294
|
+
() => visibleRoutes.map((r) => {
|
|
3295
|
+
const balance = holdings.balances[balanceKey(r.source.chainId, r.source.tokenAddress)];
|
|
3296
|
+
let affordable;
|
|
3297
|
+
if (balance && r.source.decimals != null) {
|
|
3298
|
+
try {
|
|
3299
|
+
affordable = BigInt(balance.raw) >= parseUnitsDecimal(r.source.payAmount || r.source.amount, r.source.decimals);
|
|
3300
|
+
} catch {
|
|
3301
|
+
affordable = void 0;
|
|
3302
|
+
}
|
|
3303
|
+
}
|
|
3304
|
+
return { route: r, balance, affordable };
|
|
3305
|
+
}),
|
|
3306
|
+
[visibleRoutes, holdings.balances]
|
|
3307
|
+
);
|
|
3308
|
+
const held = react.useMemo(() => annotated.filter((a) => a.affordable === true), [annotated]);
|
|
3309
|
+
const heldIds = react.useMemo(() => new Set(held.map((a) => a.route.id)), [held]);
|
|
3310
|
+
const optionStates = react.useMemo(() => {
|
|
3311
|
+
const map = {};
|
|
3312
|
+
for (const a of annotated) {
|
|
3313
|
+
const key = balanceKey(a.route.source.chainId, a.route.source.tokenAddress);
|
|
3314
|
+
if (!a.balance || holdings.loading) {
|
|
3315
|
+
map[key] = { disabled: false, reason: "checking" };
|
|
3316
|
+
continue;
|
|
3317
|
+
}
|
|
3318
|
+
let zero = false;
|
|
3319
|
+
try {
|
|
3320
|
+
zero = BigInt(a.balance.raw) === 0n;
|
|
3321
|
+
} catch {
|
|
3322
|
+
zero = false;
|
|
3323
|
+
}
|
|
3324
|
+
if (zero) map[key] = { disabled: true, reason: "no-balance", hint: "No balance on this chain" };
|
|
3325
|
+
else if (a.affordable === false) map[key] = { disabled: true, reason: "insufficient", hint: `Need ${a.route.source.payAmount} ${a.route.source.asset}` };
|
|
3326
|
+
else map[key] = { disabled: false };
|
|
3327
|
+
}
|
|
3328
|
+
return map;
|
|
3329
|
+
}, [annotated, holdings.loading]);
|
|
3330
|
+
const [chains, setChains] = react.useState([]);
|
|
3331
|
+
const [registryTokens, setRegistryTokens] = react.useState([]);
|
|
3332
|
+
react.useEffect(() => {
|
|
3333
|
+
if (bankSettlement || !isPay && rampMode) return;
|
|
3334
|
+
let alive = true;
|
|
3335
|
+
Promise.all([engine.fetchChains().catch(() => []), engine.fetchTokens().catch(() => [])]).then(([cs, ts]) => {
|
|
3336
|
+
if (!alive) return;
|
|
3337
|
+
const order = new Map(SUPPORTED_CHAINS.map((id, i) => [id, i]));
|
|
3338
|
+
setChains(
|
|
3339
|
+
cs.filter((c) => SUPPORTED_CHAIN_IDS.has(Number(c.chainId)) && c.isEnabled !== false).sort((a, b) => (order.get(Number(a.chainId)) ?? 99) - (order.get(Number(b.chainId)) ?? 99))
|
|
3340
|
+
);
|
|
3341
|
+
setRegistryTokens(ts.filter((t) => tokenEnabled(t) && SUPPORTED_CHAIN_IDS.has(Number(t.chainId))));
|
|
3342
|
+
});
|
|
3343
|
+
return () => {
|
|
3344
|
+
alive = false;
|
|
3345
|
+
};
|
|
3346
|
+
}, [engine, isPay, rampMode, bankSettlement]);
|
|
3347
|
+
const exchangeTokens = react.useMemo(
|
|
3348
|
+
() => isPay ? [] : registryTokens.filter((t) => exAllowed.includes(symbolKey(t.symbol)) && isDeliverable(symbolKey(t.symbol), Number(t.chainId))),
|
|
3349
|
+
[isPay, registryTokens, exAllowed]
|
|
3350
|
+
);
|
|
3351
|
+
const [exBalances, setExBalances] = react.useState({});
|
|
3352
|
+
const exBalReq = react.useRef(0);
|
|
3353
|
+
react.useEffect(() => {
|
|
3354
|
+
if (isPay) return;
|
|
3355
|
+
setExBalances({});
|
|
3356
|
+
if (!wallet.account || !exchangeTokens.length) return;
|
|
3357
|
+
const id = ++exBalReq.current;
|
|
3358
|
+
const targets = [];
|
|
3359
|
+
for (const t of exchangeTokens) {
|
|
3360
|
+
try {
|
|
3361
|
+
targets.push({ chainId: Number(t.chainId), tokenAddress: t.address, decimals: assetDecimals(t) });
|
|
3362
|
+
} catch {
|
|
3363
|
+
}
|
|
3364
|
+
}
|
|
3365
|
+
if (!targets.length) return;
|
|
3366
|
+
engine.readBalances(wallet.account, targets).then((res) => {
|
|
3367
|
+
if (id === exBalReq.current) setExBalances(res);
|
|
3368
|
+
});
|
|
3369
|
+
}, [engine, isPay, wallet.account, exchangeTokens]);
|
|
3370
|
+
const exFromToken = react.useMemo(() => exFrom ? findToken(exchangeTokens, exFrom.chainId, exFrom.symbol) : null, [exchangeTokens, exFrom]);
|
|
3371
|
+
const exToToken = react.useMemo(() => exTo ? findToken(exchangeTokens, exTo.chainId, exTo.symbol) : null, [exchangeTokens, exTo]);
|
|
3372
|
+
const exFromBal = exFrom && exFromToken ? exBalances[balanceKey(exFrom.chainId, exFromToken.address)] : void 0;
|
|
3373
|
+
const fundingTokens = react.useMemo(() => {
|
|
3374
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3375
|
+
const list = [];
|
|
3376
|
+
for (const r of visibleRoutes) {
|
|
3377
|
+
const key = balanceKey(r.source.chainId, r.source.tokenAddress);
|
|
3378
|
+
if (seen.has(key)) continue;
|
|
3379
|
+
seen.add(key);
|
|
3380
|
+
const reg = registryTokens.find((t) => Number(t.chainId) === r.source.chainId && addrEq(t.address, r.source.tokenAddress));
|
|
3381
|
+
list.push(reg ?? { symbol: r.source.asset, name: r.source.asset, chainId: r.source.chainId, address: r.source.tokenAddress ?? "", decimals: r.source.decimals ?? 18 });
|
|
3382
|
+
}
|
|
3383
|
+
return list;
|
|
3384
|
+
}, [visibleRoutes, registryTokens]);
|
|
3385
|
+
const fundingChains = react.useMemo(() => {
|
|
3386
|
+
const ids = new Set(fundingTokens.map((t) => Number(t.chainId)));
|
|
3387
|
+
return chains.filter((c) => ids.has(Number(c.chainId)));
|
|
3388
|
+
}, [chains, fundingTokens]);
|
|
3389
|
+
const userPicked = react.useRef(false);
|
|
3390
|
+
const selectRoute = react.useCallback(
|
|
3391
|
+
(id) => {
|
|
3392
|
+
userPicked.current = true;
|
|
3393
|
+
flow.selectRoute(id);
|
|
3394
|
+
},
|
|
3395
|
+
[flow.selectRoute]
|
|
3396
|
+
);
|
|
3397
|
+
react.useEffect(() => {
|
|
3398
|
+
userPicked.current = false;
|
|
3399
|
+
}, [wallet.account, payParamsKey, method]);
|
|
3400
|
+
react.useEffect(() => {
|
|
3401
|
+
if (!isPay || !isLiveMethod(method) || !visibleRoutes.length) return;
|
|
3402
|
+
const inFilter = visibleRoutes.some((r) => r.id === flow.selected?.id);
|
|
3403
|
+
if (!inFilter) {
|
|
3404
|
+
const next = held[0]?.route ?? visibleRoutes.find((r) => r.recommended) ?? visibleRoutes[0];
|
|
3405
|
+
if (next) flow.selectRoute(next.id);
|
|
3406
|
+
return;
|
|
3407
|
+
}
|
|
3408
|
+
if (!userPicked.current && held.length && !heldIds.has(flow.selected?.id ?? "")) {
|
|
3409
|
+
flow.selectRoute(held[0].route.id);
|
|
3410
|
+
}
|
|
3411
|
+
}, [isPay, method, visibleRoutes, held, heldIds, flow.selected?.id]);
|
|
3412
|
+
const [identity, setIdentity] = react.useState(null);
|
|
3413
|
+
react.useEffect(() => {
|
|
3414
|
+
setIdentity(loadIdentity(wallet.account));
|
|
3415
|
+
}, [wallet.account]);
|
|
3416
|
+
const identityMatchesWallet = Boolean(identity && wallet.account && addrEq(identity.walletAddress, wallet.account));
|
|
3417
|
+
react.useEffect(() => {
|
|
3418
|
+
if (!isPay || !identityMatchesWallet || !identity || userPicked.current) return;
|
|
3419
|
+
const match = visibleRoutes.find((r) => r.source.chainId === identity.preferredChainId && symbolKey(r.source.asset) === symbolKey(identity.preferredAsset));
|
|
3420
|
+
if (match) {
|
|
3421
|
+
userPicked.current = true;
|
|
3422
|
+
if (flow.selected?.id !== match.id) flow.selectRoute(match.id);
|
|
3423
|
+
}
|
|
3424
|
+
}, [isPay, identityMatchesWallet, visibleRoutes]);
|
|
3425
|
+
const [rememberChecked, setRememberChecked] = react.useState(false);
|
|
3426
|
+
const [emailInput, setEmailInput] = react.useState("");
|
|
3427
|
+
const persistIdentity = () => {
|
|
3428
|
+
if (!wallet.account) return;
|
|
3429
|
+
const src = flow.selected?.source;
|
|
3430
|
+
const preferredChainId = src?.chainId ?? props.toChainId ?? exFromChainId ?? 0;
|
|
3431
|
+
if (!SUPPORTED_CHAIN_IDS.has(Number(preferredChainId))) return;
|
|
3432
|
+
const id = {
|
|
3433
|
+
email: emailInput.trim() || void 0,
|
|
3434
|
+
walletAddress: wallet.account,
|
|
3435
|
+
preferredAsset: src?.asset ?? props.toAsset ?? exFromAsset ?? "USDC",
|
|
3436
|
+
preferredChainId,
|
|
3437
|
+
lastUsedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
3438
|
+
};
|
|
3439
|
+
saveIdentity(id);
|
|
3440
|
+
setIdentity(id);
|
|
3441
|
+
props.onIdentitySave?.(id);
|
|
3442
|
+
};
|
|
3443
|
+
const forget = () => {
|
|
3444
|
+
forgetIdentity(wallet.account);
|
|
3445
|
+
setIdentity(null);
|
|
3446
|
+
setRememberChecked(false);
|
|
3447
|
+
};
|
|
3448
|
+
const [expanded, setExpanded] = react.useState(() => Boolean(props.defaultExpanded) || rampMode);
|
|
3449
|
+
const [view, setView] = react.useState("main");
|
|
3450
|
+
const [hist, setHist] = react.useState(null);
|
|
3451
|
+
const pillRef = react.useRef(null);
|
|
3452
|
+
const methodRowRef = react.useRef(null);
|
|
3453
|
+
const exFromTileRef = react.useRef(null);
|
|
3454
|
+
const exToTileRef = react.useRef(null);
|
|
3455
|
+
const regionRef = react.useRef(null);
|
|
3456
|
+
const panelId = react.useId();
|
|
3457
|
+
react.useEffect(() => setView("main"), [wallet.account, payParamsKey]);
|
|
3458
|
+
const firstRender = react.useRef(true);
|
|
3459
|
+
react.useEffect(() => {
|
|
3460
|
+
if (firstRender.current) {
|
|
3461
|
+
firstRender.current = false;
|
|
3462
|
+
return;
|
|
3463
|
+
}
|
|
3464
|
+
if (expanded) requestAnimationFrame(() => (methodRowRef.current ?? regionRef.current)?.focus());
|
|
3465
|
+
else requestAnimationFrame(() => pillRef.current?.focus());
|
|
3466
|
+
}, [expanded]);
|
|
3467
|
+
const prevStatus = react.useRef(flow.status);
|
|
3468
|
+
react.useEffect(() => {
|
|
3469
|
+
const was = prevStatus.current;
|
|
3470
|
+
prevStatus.current = flow.status;
|
|
3471
|
+
if (expanded && was === "submitting" && (flow.status === "success" || flow.status === "pending" || flow.status === "error")) {
|
|
3472
|
+
requestAnimationFrame(() => regionRef.current?.focus());
|
|
3473
|
+
}
|
|
3474
|
+
}, [flow.status, expanded]);
|
|
3475
|
+
const closeSelector = (opener) => {
|
|
3476
|
+
setView("main");
|
|
3477
|
+
requestAnimationFrame(() => (opener?.current ?? methodRowRef.current ?? regionRef.current)?.focus());
|
|
3478
|
+
};
|
|
3479
|
+
const closeHistory = () => {
|
|
3480
|
+
setHist(null);
|
|
3481
|
+
requestAnimationFrame(() => (methodRowRef.current ?? regionRef.current)?.focus());
|
|
3482
|
+
};
|
|
3483
|
+
const pickFunding = (pick) => {
|
|
3484
|
+
const r = visibleRoutes.find((x) => x.source.chainId === pick.chainId && symbolKey(x.source.asset) === symbolKey(pick.symbol));
|
|
3485
|
+
if (r) selectRoute(r.id);
|
|
3486
|
+
closeSelector();
|
|
3487
|
+
};
|
|
3488
|
+
const submitting = flow.status === "submitting";
|
|
3489
|
+
const sel = flow.selected;
|
|
3490
|
+
const selectedVisible = Boolean(sel && visibleRoutes.some((r) => r.id === sel.id));
|
|
3491
|
+
const selPick = sel && selectedVisible ? { chainId: sel.source.chainId, symbol: sel.source.asset } : null;
|
|
3492
|
+
const selToken = sel ? registryTokens.find((t) => Number(t.chainId) === sel.source.chainId && addrEq(t.address, sel.source.tokenAddress)) ?? null : null;
|
|
3493
|
+
const selBal = sel ? holdings.balances[balanceKey(sel.source.chainId, sel.source.tokenAddress)] : void 0;
|
|
3494
|
+
const lastTxOwned = Boolean(flow.lastTxEntry?.hash && wallet.account && flow.lastTxEntry.account === wallet.account.toLowerCase());
|
|
3495
|
+
const mismatch = flow.status === "error" && flow.verdict?.status === "mismatch";
|
|
3496
|
+
const destAsset = isPay ? props.toAsset : exToAsset;
|
|
3497
|
+
const destChainId = isPay ? props.toChainId : exToChainId;
|
|
3498
|
+
const anchorLabel = isPay ? "Merchant receives exactly" : "You receive (estimated)";
|
|
3499
|
+
const anchorAmount = isPay ? props.amount : sel?.receive.amount ?? (flow.status === "loading" ? "\u2026" : "\u2014");
|
|
3500
|
+
const successAmount = isPay ? props.amount : sel?.receive.amount;
|
|
3501
|
+
const money = props.moneyDisplay ?? (isPay ? props.amount ? `${props.amount} ${props.toAsset}` : "" : exAmount ? `${exAmount} ${exFromAsset ?? ""}`.trim() : "");
|
|
3502
|
+
const verb = isPay ? { present: "Pay", gerund: "Paying", past: "Paid" } : kind === "swap" ? { present: "Swap", gerund: "Swapping", past: "Swapped" } : { present: "Exchange", gerund: "Exchanging", past: "Exchanged" };
|
|
3503
|
+
const paid = flow.status === "success";
|
|
3504
|
+
const settling = flow.status === "pending";
|
|
3505
|
+
const pillAria = `${paid ? verb.past : settling ? "Submitted, awaiting confirmation \u2014" : submitting ? verb.gerund : verb.present} ${money} with ZeroDelta`.replace(/\s+/g, " ").trim();
|
|
3506
|
+
const pillFace = /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3507
|
+
"button",
|
|
3508
|
+
{
|
|
3509
|
+
ref: pillRef,
|
|
3510
|
+
type: "button",
|
|
3511
|
+
className: "sg-express",
|
|
3512
|
+
"aria-expanded": expanded,
|
|
3513
|
+
"aria-controls": panelId,
|
|
3514
|
+
"aria-label": pillAria,
|
|
3515
|
+
onClick: () => setExpanded((e) => !e),
|
|
3516
|
+
children: [
|
|
3517
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-express-mark", "aria-hidden": "true", children: paid ? /* @__PURE__ */ jsxRuntime.jsx(CheckGlyph2, {}) : settling ? /* @__PURE__ */ jsxRuntime.jsx(ClockGlyph, {}) : submitting ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3518
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-spinner" }),
|
|
3519
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-rm-dot" })
|
|
3520
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsx(BrandMark, { mono: true, size: 18 }) }),
|
|
3521
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-express-label", children: paid ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-express-brand", children: verb.past }) : settling ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-express-brand", children: "Confirming\u2026" }) : submitting ? /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-express-brand", children: [
|
|
3522
|
+
verb.gerund,
|
|
3523
|
+
"\u2026"
|
|
3524
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3525
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-express-verb", children: [
|
|
3526
|
+
verb.present,
|
|
3527
|
+
" with"
|
|
3528
|
+
] }),
|
|
3529
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-express-brand", children: "ZeroDelta" })
|
|
3530
|
+
] }) }),
|
|
3531
|
+
money ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3532
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-express-dot", "aria-hidden": "true", children: "\xB7" }),
|
|
3533
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-express-amt", children: money })
|
|
3534
|
+
] }) : null,
|
|
3535
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-express-caret", "aria-hidden": "true", children: "\u2304" })
|
|
3536
|
+
]
|
|
3537
|
+
}
|
|
3538
|
+
);
|
|
3539
|
+
const menuItems = [];
|
|
3540
|
+
if (!rampMode) menuItems.push({ label: isPay ? "Pay another way" : "Close", onSelect: () => setExpanded(false), collapses: true });
|
|
3541
|
+
if (identity) menuItems.push({ label: "Log out of ZeroDelta Link", onSelect: forget, tone: "danger" });
|
|
3542
|
+
const brandSlot = /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-link-brand", children: [
|
|
3543
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-link-mono", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx(BrandMark, { size: 18 }) }),
|
|
3544
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-link-word", children: "ZeroDelta" }),
|
|
3545
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-badge", "data-tone": "accent", children: "Link" })
|
|
3546
|
+
] });
|
|
3547
|
+
const walletSlot = menuItems.length ? /* @__PURE__ */ jsxRuntime.jsx(LinkMenu, { items: menuItems }) : void 0;
|
|
3548
|
+
const activeStep = flow.steps.find((s) => s.state === "active");
|
|
3549
|
+
const liveMsg = flow.status === "loading" ? isPay ? "Finding the best way to pay." : "Finding the best route." : flow.status === "submitting" ? `${activeStep?.label ?? (isPay ? "Processing your payment" : `Processing your ${verb.present.toLowerCase()}`)} \u2014 in progress.` : flow.status === "success" || flow.status === "pending" ? flow.verdict?.status === "confirmed" ? isPay ? "Payment confirmed on-chain \u2014 the merchant has been settled." : `${verb.past} \u2014 confirmed on-chain.` : isPay ? "Payment sent \u2014 confirmation is still pending." : "Submitted \u2014 confirmation is still pending." : "";
|
|
3550
|
+
const loading = flow.status === "loading";
|
|
3551
|
+
const payReady = isPay ? Boolean(sel && selectedVisible) : Boolean(sel);
|
|
3552
|
+
const ctaLabel = submitting ? isPay ? "Paying\u2026" : kind === "swap" ? "Swapping\u2026" : "Exchanging\u2026" : flow.insufficient ? "Insufficient balance" : flow.nativeShortfall ? flow.nativeShortfall : loading ? "Getting a price\u2026" : isPay ? sel && selectedVisible ? `Pay ${sel.source.payAmount} ${sel.source.asset}` : "Pay" : kind === "swap" ? "Swap" : "Exchange";
|
|
3553
|
+
const exPct = (p) => {
|
|
3554
|
+
if (!exFromBal || !exFromToken) return;
|
|
3555
|
+
const raw = BigInt(exFromBal.raw);
|
|
3556
|
+
setExAmount(formatUnits(p === 100 ? raw : raw * BigInt(p) / 100n, assetDecimals(exFromToken)));
|
|
3557
|
+
};
|
|
3558
|
+
const exchangeControls = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3559
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-ft", style: { marginTop: 12 }, children: [
|
|
3560
|
+
/* @__PURE__ */ jsxRuntime.jsx(TokenTile, { label: "From", pick: exFrom, token: exFromToken, disabled: submitting, btnRef: exFromTileRef, onClick: () => setView("from") }),
|
|
3561
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-ft-arrow", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx(ArrowGlyph, {}) }),
|
|
3562
|
+
/* @__PURE__ */ jsxRuntime.jsx(TokenTile, { label: "To", pick: exTo, token: exToToken, disabled: submitting, btnRef: exToTileRef, onClick: () => setView("to") })
|
|
3563
|
+
] }),
|
|
3564
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-panel", style: { marginTop: 12 }, children: [
|
|
3565
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-label", children: "Send" }),
|
|
3566
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-send-row", children: [
|
|
3567
|
+
exFrom ? /* @__PURE__ */ jsxRuntime.jsx(TokenGlyph, { symbol: exFrom.symbol, logoUrl: exFromToken?.logoUrl, chainId: exFrom.chainId, size: "sm" }) : null,
|
|
3568
|
+
/* @__PURE__ */ jsxRuntime.jsx(AmountInput, { value: exAmount, onChange: setExAmount, disabled: submitting })
|
|
3569
|
+
] }),
|
|
3570
|
+
exFromBal ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-send-bal sg-mono", children: [
|
|
3571
|
+
"Balance: ",
|
|
3572
|
+
exFromBal.formatted,
|
|
3573
|
+
" ",
|
|
3574
|
+
exFrom?.symbol
|
|
3575
|
+
] }) : null,
|
|
3576
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-pct-row", role: "group", "aria-label": "Amount shortcuts", children: [25, 50, 75, 100].map((p) => /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "sg-pct", disabled: !exFromBal || submitting, onClick: () => exPct(p), children: p === 100 ? "MAX" : `${p}%` }, p)) })
|
|
3577
|
+
] })
|
|
3578
|
+
] });
|
|
3579
|
+
let body;
|
|
3580
|
+
if (hist && wallet.account) {
|
|
3581
|
+
body = /* @__PURE__ */ jsxRuntime.jsx(TxHistoryPanel, { account: wallet.account, tokens: registryTokens, initialEntry: hist.entry ?? null, onBack: closeHistory });
|
|
3582
|
+
} else if (isPay && view === "select" && wallet.account) {
|
|
3583
|
+
body = /* @__PURE__ */ jsxRuntime.jsx(TokenSelect, { title: "Pay with", chains: fundingChains, tokens: fundingTokens, balances: holdings.balances, optionStates, onBack: () => closeSelector(), onPick: pickFunding });
|
|
3584
|
+
} else if (!isPay && (view === "from" || view === "to")) {
|
|
3585
|
+
const isFrom = view === "from";
|
|
3586
|
+
const openerRef = isFrom ? exFromTileRef : exToTileRef;
|
|
3587
|
+
body = /* @__PURE__ */ jsxRuntime.jsx(
|
|
3588
|
+
TokenSelect,
|
|
3589
|
+
{
|
|
3590
|
+
title: isFrom ? "Exchange from" : "Exchange to",
|
|
3591
|
+
chains,
|
|
3592
|
+
tokens: exchangeTokens,
|
|
3593
|
+
balances: exBalances,
|
|
3594
|
+
onBack: () => closeSelector(openerRef),
|
|
3595
|
+
onPick: (pick) => {
|
|
3596
|
+
(isFrom ? setExFrom : setExTo)({ chainId: pick.chainId, symbol: symbolKey(pick.symbol) });
|
|
3597
|
+
closeSelector(openerRef);
|
|
3598
|
+
}
|
|
3599
|
+
}
|
|
3600
|
+
);
|
|
3601
|
+
} else if (rampMode) {
|
|
3602
|
+
body = /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-soonpanel", children: [
|
|
3603
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-soonpanel-title", children: mode === "onramp" ? "Buying with fiat is coming soon" : "Cashing out to fiat is coming soon" }),
|
|
3604
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-soonpanel-sub", children: "Fiat on/off-ramps are on the roadmap. ZeroDelta settles crypto-to-crypto today \u2014 connect a wallet to pay with stablecoins." })
|
|
3605
|
+
] });
|
|
3606
|
+
} else if (bankSettlement) {
|
|
3607
|
+
const payingByRoadmapRail = !isLiveMethod(method);
|
|
3608
|
+
const soonTitle = method === "card" ? "Card payments are coming soon" : method === "bank" ? "Bank transfers are coming soon" : "Bank payout is coming soon";
|
|
3609
|
+
body = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3610
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { marginTop: 12 }, children: /* @__PURE__ */ jsxRuntime.jsx(MerchantBankPayout, { account: props.bankAccount }) }),
|
|
3611
|
+
/* @__PURE__ */ jsxRuntime.jsx(MethodTabs, { value: method, onChange: setMethod }),
|
|
3612
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-soonpanel", children: [
|
|
3613
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-soonpanel-title", children: soonTitle }),
|
|
3614
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-soonpanel-sub", children: payingByRoadmapRail ? `Two roadmap rails at once \u2014 paying by ${method === "card" ? "card" : "bank transfer"} and settling the merchant to a bank. ZeroDelta settles crypto-to-crypto today.` : "Paying a merchant out to a bank account is on the roadmap. ZeroDelta settles crypto-to-crypto today \u2014 switch settlement to a stablecoin to take this payment now." })
|
|
3615
|
+
] }),
|
|
3616
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-cta-wrap", children: /* @__PURE__ */ jsxRuntime.jsx(Button, { disabled: true, children: method === "card" ? "Card \u2014 coming soon" : method === "bank" ? "Bank transfer \u2014 coming soon" : "Bank payout \u2014 coming soon" }) })
|
|
3617
|
+
] });
|
|
3618
|
+
} else if (!wallet.account) {
|
|
3619
|
+
body = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3620
|
+
/* @__PURE__ */ jsxRuntime.jsx(IdentityLine, { account: null, email: identity?.email }),
|
|
3621
|
+
isPay ? /* @__PURE__ */ jsxRuntime.jsx("div", { style: { marginTop: 12 }, children: /* @__PURE__ */ jsxRuntime.jsx(MerchantReceives, { amount: props.amount, asset: destAsset, chainId: destChainId, recipient: props.recipient }) }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3622
|
+
exchangeControls,
|
|
3623
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-panel", style: { marginTop: 12 }, children: [
|
|
3624
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-label", children: "You receive (estimated)" }),
|
|
3625
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-anchor sg-mono", children: [
|
|
3626
|
+
"\u2014 ",
|
|
3627
|
+
exToAsset ?? ""
|
|
3628
|
+
] }),
|
|
3629
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-anchor-sub", children: "Connect your wallet to see the estimated receive amount." })
|
|
3630
|
+
] })
|
|
3631
|
+
] }),
|
|
3632
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-cta-wrap", children: [
|
|
3633
|
+
/* @__PURE__ */ jsxRuntime.jsx(Button, { onClick: wallet.connect, busy: wallet.connecting, children: "Connect wallet" }),
|
|
3634
|
+
wallet.error ? /* @__PURE__ */ jsxRuntime.jsx(StatusPanel, { tone: "error", children: wallet.error }) : null
|
|
3635
|
+
] })
|
|
3636
|
+
] });
|
|
3637
|
+
} else if (paid || settling) {
|
|
3638
|
+
const confirmed = flow.verdict?.status === "confirmed";
|
|
3639
|
+
body = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3640
|
+
/* @__PURE__ */ jsxRuntime.jsx(IdentityLine, { account: wallet.account, email: identity?.email }),
|
|
3641
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-receipt", children: [
|
|
3642
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-receipt-eyebrow", children: isPay ? confirmed ? "Merchant settled" : "Payment sent" : confirmed ? `${verb.past} on-chain` : "Submitted" }),
|
|
3643
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-settle-disc", "data-pending": confirmed ? void 0 : "true", children: confirmed ? /* @__PURE__ */ jsxRuntime.jsx(CheckGlyph2, {}) : /* @__PURE__ */ jsxRuntime.jsx(ClockGlyph, {}) }),
|
|
3644
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-receipt-amt sg-mono", children: [
|
|
3645
|
+
successAmount,
|
|
3646
|
+
" ",
|
|
3647
|
+
destAsset
|
|
3648
|
+
] }),
|
|
3649
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-receipt-sub", children: [
|
|
3650
|
+
confirmed ? "Confirmed on-chain" : "Confirmation pending",
|
|
3651
|
+
isPay && props.recipient ? ` \xB7 ${shortAddress(props.recipient)}` : ""
|
|
3652
|
+
] })
|
|
3653
|
+
] }),
|
|
3654
|
+
!identityMatchesWallet ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-remember", children: [
|
|
3655
|
+
/* @__PURE__ */ jsxRuntime.jsxs("label", { className: "sg-remember-top", children: [
|
|
3656
|
+
/* @__PURE__ */ jsxRuntime.jsx("input", { className: "sg-check", type: "checkbox", checked: rememberChecked, onChange: (e) => setRememberChecked(e.target.checked) }),
|
|
3657
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-remember-copy", children: [
|
|
3658
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-remember-label", children: "Save for 1-click next time" }),
|
|
3659
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-remember-sub", children: "Remembers this wallet + your preferred stablecoin on ZeroDelta Link. Crypto only \u2014 forgettable anytime." })
|
|
3660
|
+
] })
|
|
3661
|
+
] }),
|
|
3662
|
+
rememberChecked ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-remember-body", children: [
|
|
3663
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3664
|
+
"input",
|
|
3665
|
+
{
|
|
3666
|
+
className: "sg-input",
|
|
3667
|
+
type: "email",
|
|
3668
|
+
inputMode: "email",
|
|
3669
|
+
placeholder: "Email (optional)",
|
|
3670
|
+
value: emailInput,
|
|
3671
|
+
onChange: (e) => setEmailInput(e.target.value),
|
|
3672
|
+
"aria-label": "Email for ZeroDelta Link (optional)"
|
|
3673
|
+
}
|
|
3674
|
+
),
|
|
3675
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-cta-wrap", children: /* @__PURE__ */ jsxRuntime.jsx(Button, { onClick: persistIdentity, children: "Save" }) })
|
|
3676
|
+
] }) : null
|
|
3677
|
+
] }) : null,
|
|
3678
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-cta-wrap", children: lastTxOwned ? /* @__PURE__ */ jsxRuntime.jsx(Button, { variant: "ghost", onClick: () => setHist({ entry: flow.lastTxEntry }), children: "View transaction" }) : null }),
|
|
3679
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "sg-link-alt", onClick: () => props.onDone ? props.onDone() : setExpanded(false), children: "Done" })
|
|
3680
|
+
] });
|
|
3681
|
+
} else if (mismatch) {
|
|
3682
|
+
body = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3683
|
+
/* @__PURE__ */ jsxRuntime.jsx(IdentityLine, { account: wallet.account, email: identity?.email }),
|
|
3684
|
+
/* @__PURE__ */ jsxRuntime.jsx(StatusPanel, { tone: "error", children: "Payment stopped for review \u2014 the submitted transaction did not match the reviewed plan. Do not retry." }),
|
|
3685
|
+
lastTxOwned ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-cta-wrap", children: /* @__PURE__ */ jsxRuntime.jsx(Button, { variant: "ghost", onClick: () => setHist({ entry: flow.lastTxEntry }), children: "View transaction" }) }) : null
|
|
3686
|
+
] });
|
|
3687
|
+
} else {
|
|
3688
|
+
const quoteError = flow.status === "error" && flow.steps.length === 0;
|
|
3689
|
+
const walletError = flow.status === "error" && flow.steps.length > 0;
|
|
3690
|
+
body = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3691
|
+
/* @__PURE__ */ jsxRuntime.jsx(IdentityLine, { account: wallet.account, email: identity?.email }),
|
|
3692
|
+
isPay ? /* @__PURE__ */ jsxRuntime.jsx("div", { style: { marginTop: 12 }, children: /* @__PURE__ */ jsxRuntime.jsx(MerchantReceives, { amount: props.amount, asset: destAsset, chainId: destChainId, recipient: props.recipient }) }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3693
|
+
exchangeControls,
|
|
3694
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-panel", style: { marginTop: 12 }, children: [
|
|
3695
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-label", children: anchorLabel }),
|
|
3696
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-anchor sg-mono", children: [
|
|
3697
|
+
anchorAmount,
|
|
3698
|
+
" ",
|
|
3699
|
+
destAsset
|
|
3700
|
+
] })
|
|
3701
|
+
] })
|
|
3702
|
+
] }),
|
|
3703
|
+
isPay ? /* @__PURE__ */ jsxRuntime.jsx(MethodTabs, { value: method, onChange: setMethod }) : null,
|
|
3704
|
+
parked ? (
|
|
3705
|
+
// Honest roadmap park — Card / Bank are not live. No quote, no funding row, no Pay CTA.
|
|
3706
|
+
/* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3707
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-soonpanel", children: [
|
|
3708
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-soonpanel-title", children: method === "card" ? "Card payments are coming soon" : "Bank transfers are coming soon" }),
|
|
3709
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-soonpanel-sub", children: [
|
|
3710
|
+
"Today ZeroDelta settles from your connected wallet. Fiat ",
|
|
3711
|
+
method === "card" ? "card" : "bank",
|
|
3712
|
+
" rails are on the roadmap \u2014 crypto-to-crypto is live now."
|
|
3713
|
+
] })
|
|
3714
|
+
] }),
|
|
3715
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-cta-wrap", children: /* @__PURE__ */ jsxRuntime.jsx(Button, { disabled: true, children: method === "card" ? "Card \u2014 coming soon" : "Bank \u2014 coming soon" }) })
|
|
3716
|
+
] })
|
|
3717
|
+
) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3718
|
+
isPay ? /* @__PURE__ */ jsxRuntime.jsx("div", { style: { marginTop: 12 }, children: /* @__PURE__ */ jsxRuntime.jsx(TokenTile, { row: true, label: "Pay with", pick: selPick, token: selToken, disabled: submitting || !visibleRoutes.length, btnRef: methodRowRef, onClick: () => setView("select") }) }) : null,
|
|
3719
|
+
loading ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-panel", style: { marginTop: 12 }, children: [
|
|
3720
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-skel" }),
|
|
3721
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-muted", style: { fontSize: 13 }, children: [
|
|
3722
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-spinner" }),
|
|
3723
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-rm-dot" }),
|
|
3724
|
+
" Finding the best way to pay\u2026"
|
|
3725
|
+
] })
|
|
3726
|
+
] }) : null,
|
|
3727
|
+
isPay && sel && selectedVisible && !loading ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-panel", style: { marginTop: 12 }, children: [
|
|
3728
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-label", children: "You pay" }),
|
|
3729
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-anchor sg-mono", children: [
|
|
3730
|
+
sel.source.payAmount,
|
|
3731
|
+
" ",
|
|
3732
|
+
sel.source.asset
|
|
3733
|
+
] }),
|
|
3734
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-anchor-sub", children: [
|
|
3735
|
+
"on ",
|
|
3736
|
+
chainName(sel.source.chainId),
|
|
3737
|
+
selBal ? ` \xB7 balance ${selBal.formatted}` : ""
|
|
3738
|
+
] })
|
|
3739
|
+
] }) : null,
|
|
3740
|
+
!isPay && sel && !loading ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-panel", style: { marginTop: 12 }, children: [
|
|
3741
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-label", children: "You pay" }),
|
|
3742
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-anchor sg-mono", children: [
|
|
3743
|
+
sel.source.payAmount,
|
|
3744
|
+
" ",
|
|
3745
|
+
sel.source.asset
|
|
3746
|
+
] }),
|
|
3747
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-anchor-sub", children: [
|
|
3748
|
+
"on ",
|
|
3749
|
+
chainName(sel.source.chainId)
|
|
3750
|
+
] })
|
|
3751
|
+
] }) : null,
|
|
3752
|
+
quoteError ? /* @__PURE__ */ jsxRuntime.jsx(StatusPanel, { tone: "error", children: flow.error || "Couldn't get a price right now." }) : null,
|
|
3753
|
+
walletError ? /* @__PURE__ */ jsxRuntime.jsx(StatusPanel, { tone: "error", children: flow.error || "The wallet could not complete this payment." }) : null,
|
|
3754
|
+
submitting || walletError ? /* @__PURE__ */ jsxRuntime.jsx(StepList, { variant: "rich", steps: flow.steps, verdict: flow.verdict }) : null,
|
|
3755
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-cta-wrap", children: quoteError ? /* @__PURE__ */ jsxRuntime.jsx(Button, { onClick: flow.reload, children: "Try again" }) : walletError ? /* @__PURE__ */ jsxRuntime.jsx(Button, { onClick: payReady ? flow.submit : void 0, disabled: !payReady, children: "Try again" }) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
3756
|
+
Button,
|
|
3757
|
+
{
|
|
3758
|
+
onClick: payReady && !submitting && !flow.insufficient && !flow.nativeShortfall && !loading ? flow.submit : void 0,
|
|
3759
|
+
busy: submitting || loading,
|
|
3760
|
+
softDisabled: submitting,
|
|
3761
|
+
disabled: !submitting && (!payReady || flow.insufficient || !!flow.nativeShortfall || loading),
|
|
3762
|
+
children: ctaLabel
|
|
3763
|
+
}
|
|
3764
|
+
) })
|
|
3765
|
+
] })
|
|
3766
|
+
] });
|
|
3767
|
+
}
|
|
3768
|
+
const resolved = resolveTheme(config.theme);
|
|
3769
|
+
const islandVars = themeToVars(resolved);
|
|
3770
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-island-wrap", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-island", "data-sg-mode": resolved.mode, "data-expanded": expanded, "data-status": flow.status, style: islandVars, children: [
|
|
3771
|
+
pillFace,
|
|
3772
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-island-reveal", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-island-reveal-inner", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-island-body", id: panelId, ref: regionRef, role: "region", "aria-label": isPay ? "ZeroDelta Link checkout" : `ZeroDelta Link ${verb.present.toLowerCase()}`, tabIndex: -1, children: expanded ? /* @__PURE__ */ jsxRuntime.jsxs(WidgetShell, { variant: "express", title: "ZeroDelta Link", theme: config.theme, heightPx: props.heightPx, brandSlot, walletSlot, children: [
|
|
3773
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-sr-only", role: "status", "aria-live": "polite", children: liveMsg }),
|
|
3774
|
+
body
|
|
3775
|
+
] }) : null }) }) })
|
|
3776
|
+
] }) });
|
|
3777
|
+
}
|
|
3778
|
+
var STABLES2 = /* @__PURE__ */ new Set(["USDC", "USDT", "USDE"]);
|
|
3779
|
+
function CheckGlyph3() {
|
|
3780
|
+
return /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "3", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M20 6 9 17l-5-5" }) });
|
|
3781
|
+
}
|
|
3782
|
+
var addrEq2 = (a, b) => String(a || "").toLowerCase() === String(b || "").toLowerCase();
|
|
3783
|
+
function StableGeniePay(props) {
|
|
3784
|
+
const config = useMergedConfig(props);
|
|
3785
|
+
const engine = useEngine({ apiBase: config.apiBase, apiKey: config.apiKey, trustedApiOrigin: config.trustedApiOrigin, rpcOverrides: config.rpcOverrides, onTransaction: config.onTransaction });
|
|
3786
|
+
const wallet = useWallet(config.provider);
|
|
3787
|
+
const paramsKey = `${props.recipient}|${props.toChainId}|${props.toAsset}|${props.amount}`;
|
|
3788
|
+
const flow = useFlow({
|
|
3789
|
+
engine,
|
|
3790
|
+
wallet,
|
|
3791
|
+
kind: "payment",
|
|
3792
|
+
// When variant="pill" this component delegates to PaymentIsland (which runs its OWN flow) — do no
|
|
3793
|
+
// network work here, or every quote / balance read fires twice and onQuote/onError double-fire.
|
|
3794
|
+
enabled: Boolean(props.recipient && props.amount) && props.variant !== "pill",
|
|
3795
|
+
paramsKey,
|
|
3796
|
+
loadPlan: (e, payer, chainId) => e.fetchPaymentPlan({ address: props.recipient, chainId: props.toChainId, asset: props.toAsset, amount: props.amount }, payer, { chainId }),
|
|
3797
|
+
recipientFor: () => props.recipient,
|
|
3798
|
+
onQuote: config.onQuote,
|
|
3799
|
+
onSuccess: config.onSuccess,
|
|
3800
|
+
onError: config.onError
|
|
3801
|
+
});
|
|
3802
|
+
const [method, setMethod] = react.useState("recommended");
|
|
3803
|
+
const fundingSet = react.useMemo(
|
|
3804
|
+
() => props.fundingAssets?.length ? new Set(props.fundingAssets.map((a) => a.toUpperCase())) : null,
|
|
3805
|
+
[props.fundingAssets]
|
|
3806
|
+
);
|
|
3807
|
+
const visibleRoutes = react.useMemo(() => {
|
|
3808
|
+
const base = fundingSet ? flow.routes.filter((r) => fundingSet.has(r.source.asset.toUpperCase()) || r.state === "DIRECT") : flow.routes;
|
|
3809
|
+
return method === "stablecoin" ? base.filter((r) => STABLES2.has(r.source.asset)) : base;
|
|
3810
|
+
}, [flow.routes, method, fundingSet]);
|
|
3811
|
+
const holdings = useHoldings(engine, wallet.account, flow.routes);
|
|
3812
|
+
const annotated = react.useMemo(
|
|
3813
|
+
() => visibleRoutes.map((r) => {
|
|
3814
|
+
const balance = holdings.balances[balanceKey(r.source.chainId, r.source.tokenAddress)];
|
|
3815
|
+
let affordable;
|
|
3816
|
+
if (balance && r.source.decimals != null) {
|
|
3817
|
+
try {
|
|
3818
|
+
affordable = BigInt(balance.raw) >= parseUnitsDecimal(r.source.payAmount || r.source.amount, r.source.decimals);
|
|
3819
|
+
} catch {
|
|
3820
|
+
affordable = void 0;
|
|
3821
|
+
}
|
|
3822
|
+
}
|
|
3823
|
+
return { route: r, balance, affordable };
|
|
3824
|
+
}),
|
|
3825
|
+
[visibleRoutes, holdings.balances]
|
|
3826
|
+
);
|
|
3827
|
+
const held = react.useMemo(() => annotated.filter((a) => a.affordable === true), [annotated]);
|
|
3828
|
+
const heldIds = react.useMemo(() => new Set(held.map((a) => a.route.id)), [held]);
|
|
3829
|
+
const scannedEmpty = !holdings.loading && Object.keys(holdings.balances).length > 0 && held.length === 0;
|
|
3830
|
+
const optionStates = react.useMemo(() => {
|
|
3831
|
+
const map = {};
|
|
3832
|
+
for (const a of annotated) {
|
|
3833
|
+
const key = balanceKey(a.route.source.chainId, a.route.source.tokenAddress);
|
|
3834
|
+
if (!a.balance || holdings.loading) {
|
|
3835
|
+
map[key] = { disabled: false, reason: "checking" };
|
|
3836
|
+
continue;
|
|
3837
|
+
}
|
|
3838
|
+
let zero = false;
|
|
3839
|
+
try {
|
|
3840
|
+
zero = BigInt(a.balance.raw) === 0n;
|
|
3841
|
+
} catch {
|
|
3842
|
+
zero = false;
|
|
3843
|
+
}
|
|
3844
|
+
if (zero) {
|
|
3845
|
+
map[key] = { disabled: true, reason: "no-balance", hint: "No balance on this chain" };
|
|
3846
|
+
} else if (a.affordable === false) {
|
|
3847
|
+
map[key] = { disabled: true, reason: "insufficient", hint: `Need ${a.route.source.payAmount} ${a.route.source.asset}` };
|
|
3848
|
+
} else {
|
|
3849
|
+
map[key] = { disabled: false };
|
|
3850
|
+
}
|
|
3851
|
+
}
|
|
3852
|
+
return map;
|
|
3853
|
+
}, [annotated, holdings.loading]);
|
|
3854
|
+
const [chains, setChains] = react.useState([]);
|
|
3855
|
+
const [registryTokens, setRegistryTokens] = react.useState([]);
|
|
3856
|
+
react.useEffect(() => {
|
|
3857
|
+
if (props.variant === "pill") return;
|
|
3858
|
+
let alive = true;
|
|
3859
|
+
Promise.all([engine.fetchChains().catch(() => []), engine.fetchTokens().catch(() => [])]).then(([cs, ts]) => {
|
|
3860
|
+
if (!alive) return;
|
|
3861
|
+
const order = new Map(SUPPORTED_CHAINS.map((id, i) => [id, i]));
|
|
3862
|
+
setChains(
|
|
3863
|
+
cs.filter((c) => SUPPORTED_CHAIN_IDS.has(Number(c.chainId)) && c.isEnabled !== false).sort((a, b) => (order.get(Number(a.chainId)) ?? 99) - (order.get(Number(b.chainId)) ?? 99))
|
|
3864
|
+
);
|
|
3865
|
+
setRegistryTokens(ts.filter((t) => tokenEnabled(t) && SUPPORTED_CHAIN_IDS.has(Number(t.chainId))));
|
|
3866
|
+
});
|
|
3867
|
+
return () => {
|
|
3868
|
+
alive = false;
|
|
3869
|
+
};
|
|
3870
|
+
}, [engine]);
|
|
3871
|
+
const fundingTokens = react.useMemo(() => {
|
|
3872
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3873
|
+
const list = [];
|
|
3874
|
+
for (const r of visibleRoutes) {
|
|
3875
|
+
const key = balanceKey(r.source.chainId, r.source.tokenAddress);
|
|
3876
|
+
if (seen.has(key)) continue;
|
|
3877
|
+
seen.add(key);
|
|
3878
|
+
const reg = registryTokens.find((t) => Number(t.chainId) === r.source.chainId && addrEq2(t.address, r.source.tokenAddress));
|
|
3879
|
+
list.push(reg ?? { symbol: r.source.asset, name: r.source.asset, chainId: r.source.chainId, address: r.source.tokenAddress ?? "", decimals: r.source.decimals ?? 18 });
|
|
3880
|
+
}
|
|
3881
|
+
return list;
|
|
3882
|
+
}, [visibleRoutes, registryTokens]);
|
|
3883
|
+
const fundingChains = react.useMemo(() => {
|
|
3884
|
+
const ids = new Set(fundingTokens.map((t) => Number(t.chainId)));
|
|
3885
|
+
return chains.filter((c) => ids.has(Number(c.chainId)));
|
|
3886
|
+
}, [chains, fundingTokens]);
|
|
3887
|
+
const userPicked = react.useRef(false);
|
|
3888
|
+
const selectRoute = react.useCallback(
|
|
3889
|
+
(id) => {
|
|
3890
|
+
userPicked.current = true;
|
|
3891
|
+
flow.selectRoute(id);
|
|
3892
|
+
},
|
|
3893
|
+
[flow.selectRoute]
|
|
3894
|
+
);
|
|
3895
|
+
react.useEffect(() => {
|
|
3896
|
+
userPicked.current = false;
|
|
3897
|
+
}, [method, wallet.account, paramsKey]);
|
|
3898
|
+
react.useEffect(() => {
|
|
3899
|
+
if (!isLiveMethod(method) || !visibleRoutes.length) return;
|
|
3900
|
+
const inFilter = visibleRoutes.some((r) => r.id === flow.selected?.id);
|
|
3901
|
+
if (!inFilter) {
|
|
3902
|
+
const next = held[0]?.route ?? visibleRoutes.find((r) => r.recommended) ?? visibleRoutes[0];
|
|
3903
|
+
if (next) flow.selectRoute(next.id);
|
|
3904
|
+
return;
|
|
3905
|
+
}
|
|
3906
|
+
if (!userPicked.current && held.length && !heldIds.has(flow.selected?.id ?? "")) {
|
|
3907
|
+
flow.selectRoute(held[0].route.id);
|
|
3908
|
+
}
|
|
3909
|
+
}, [method, visibleRoutes, held, heldIds, flow.selected?.id]);
|
|
3910
|
+
const [view, setView] = react.useState("main");
|
|
3911
|
+
const payTileRef = react.useRef(null);
|
|
3912
|
+
const closeSelector = () => {
|
|
3913
|
+
setView("main");
|
|
3914
|
+
requestAnimationFrame(() => payTileRef.current?.focus());
|
|
3915
|
+
};
|
|
3916
|
+
react.useEffect(() => setView("main"), [wallet.account, paramsKey]);
|
|
3917
|
+
const [hist, setHist] = react.useState(null);
|
|
3918
|
+
const histBtnRef = react.useRef(null);
|
|
3919
|
+
const closeHistory = () => {
|
|
3920
|
+
setHist(null);
|
|
3921
|
+
requestAnimationFrame(() => histBtnRef.current?.focus());
|
|
3922
|
+
};
|
|
3923
|
+
react.useEffect(() => setHist(null), [wallet.account]);
|
|
3924
|
+
const lastTxOwned = Boolean(flow.lastTxEntry?.hash && wallet.account && flow.lastTxEntry.account === wallet.account.toLowerCase());
|
|
3925
|
+
const pickFunding = (pick) => {
|
|
3926
|
+
const r = visibleRoutes.find((x) => x.source.chainId === pick.chainId && symbolKey(x.source.asset) === symbolKey(pick.symbol));
|
|
3927
|
+
if (r) selectRoute(r.id);
|
|
3928
|
+
closeSelector();
|
|
3929
|
+
};
|
|
3930
|
+
const chainName2 = CHAIN_LABELS[props.toChainId] || `Chain ${props.toChainId}`;
|
|
3931
|
+
const parked = !isLiveMethod(method);
|
|
3932
|
+
const submitting = flow.status === "submitting";
|
|
3933
|
+
const sel = flow.selected;
|
|
3934
|
+
const selectedVisible = Boolean(sel && visibleRoutes.some((r) => r.id === sel.id));
|
|
3935
|
+
const selPick = sel && selectedVisible ? { chainId: sel.source.chainId, symbol: sel.source.asset } : null;
|
|
3936
|
+
const selToken = sel ? registryTokens.find((t) => Number(t.chainId) === sel.source.chainId && addrEq2(t.address, sel.source.tokenAddress)) ?? null : null;
|
|
3937
|
+
const selBal = sel ? holdings.balances[balanceKey(sel.source.chainId, sel.source.tokenAddress)] : void 0;
|
|
3938
|
+
const why = parked ? "" : sel && selectedVisible ? sel.state === "DIRECT" ? `Direct ${sel.source.asset} transfer on ${CHAIN_LABELS[sel.source.chainId] || sel.source.chainName} \xB7 lowest cost` : `Routed through ZeroDelta \u2014 the merchant still receives exactly ${props.amount} ${props.toAsset}` : method === "stablecoin" ? "Pay with USDC, USDT, or USDE from your wallet." : method === "anyasset" ? "Pay with any supported asset \u2014 we route it to exactly what the merchant needs." : "Best route \xB7 picked for you";
|
|
3939
|
+
const comingSoon = method === "card" ? "Card payments are coming soon. Today StableGenie pays from your connected wallet." : "Bank transfers are coming soon.";
|
|
3940
|
+
const payLabel = parked ? method === "card" ? "Card \u2014 coming soon" : "Bank \u2014 coming soon" : submitting ? "Paying\u2026" : flow.insufficient ? "Insufficient balance" : flow.nativeShortfall ? flow.nativeShortfall : sel && selectedVisible ? `Pay ${sel.source.payAmount} ${sel.source.asset}` : "Pay";
|
|
3941
|
+
const walletSlot = wallet.account ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-head-tools", children: [
|
|
3942
|
+
/* @__PURE__ */ jsxRuntime.jsx(HistoryButton, { btnRef: histBtnRef, disabled: submitting, onClick: () => setHist({}) }),
|
|
3943
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-brand", children: [
|
|
3944
|
+
/* @__PURE__ */ jsxRuntime.jsx(BrandMark, { size: 14, className: "sg-brand-mark" }),
|
|
3945
|
+
"ZeroDelta"
|
|
3946
|
+
] })
|
|
3947
|
+
] }) : void 0;
|
|
3948
|
+
if (props.variant === "pill") return /* @__PURE__ */ jsxRuntime.jsx(PaymentIsland, { kind: "pay", ...props });
|
|
3949
|
+
return /* @__PURE__ */ jsxRuntime.jsx(WidgetShell, { title: config.title || "Complete payment", theme: config.theme, heightPx: props.heightPx, walletSlot, children: hist && wallet.account ? /* @__PURE__ */ jsxRuntime.jsx(TxHistoryPanel, { account: wallet.account, tokens: registryTokens, initialEntry: hist.entry ?? null, onBack: closeHistory }) : view === "select" && wallet.account ? /* @__PURE__ */ jsxRuntime.jsx(TokenSelect, { title: "Pay with", chains: fundingChains, tokens: fundingTokens, balances: holdings.balances, optionStates, onBack: closeSelector, onPick: pickFunding }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3950
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-panel", children: [
|
|
3951
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-label", children: "Merchant receives exactly" }),
|
|
3952
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-anchor sg-mono", children: [
|
|
3953
|
+
props.amount,
|
|
3954
|
+
" ",
|
|
3955
|
+
props.toAsset
|
|
3956
|
+
] }),
|
|
3957
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-anchor-sub", children: [
|
|
3958
|
+
"on ",
|
|
3959
|
+
chainName2,
|
|
3960
|
+
" \xB7 ",
|
|
3961
|
+
shortAddress(props.recipient)
|
|
3962
|
+
] })
|
|
3963
|
+
] }),
|
|
3964
|
+
!wallet.account ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-cta-wrap", children: [
|
|
3965
|
+
/* @__PURE__ */ jsxRuntime.jsx(Button, { onClick: wallet.connect, busy: wallet.connecting, children: "Connect wallet" }),
|
|
3966
|
+
wallet.error ? /* @__PURE__ */ jsxRuntime.jsx(StatusPanel, { tone: "error", children: wallet.error }) : null
|
|
3967
|
+
] }) : flow.status === "success" || flow.status === "pending" ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3968
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-success", children: [
|
|
3969
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-success-check", "data-pending": flow.verdict?.status !== "confirmed", children: /* @__PURE__ */ jsxRuntime.jsx(CheckGlyph3, {}) }),
|
|
3970
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-success-amt sg-mono", children: [
|
|
3971
|
+
props.amount,
|
|
3972
|
+
" ",
|
|
3973
|
+
props.toAsset
|
|
3974
|
+
] }),
|
|
3975
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-success-sub", children: [
|
|
3976
|
+
flow.verdict?.status === "confirmed" ? "Confirmed on-chain" : "Submitted \u2014 awaiting confirmation",
|
|
3977
|
+
" \xB7 ",
|
|
3978
|
+
shortAddress(props.recipient)
|
|
3979
|
+
] })
|
|
3980
|
+
] }),
|
|
3981
|
+
lastTxOwned ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-cta-wrap", children: /* @__PURE__ */ jsxRuntime.jsx(Button, { variant: "ghost", onClick: () => setHist({ entry: flow.lastTxEntry }), children: "View transaction" }) }) : null
|
|
3982
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3983
|
+
/* @__PURE__ */ jsxRuntime.jsx(MethodTabs, { value: method, onChange: setMethod }),
|
|
3984
|
+
parked ? /* @__PURE__ */ jsxRuntime.jsx(StatusPanel, { children: comingSoon }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3985
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { marginTop: 12 }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3986
|
+
TokenTile,
|
|
3987
|
+
{
|
|
3988
|
+
label: "Pay with",
|
|
3989
|
+
pick: selPick,
|
|
3990
|
+
token: selToken,
|
|
3991
|
+
disabled: submitting || !visibleRoutes.length,
|
|
3992
|
+
btnRef: payTileRef,
|
|
3993
|
+
onClick: () => setView("select")
|
|
3994
|
+
}
|
|
3995
|
+
) }),
|
|
3996
|
+
flow.status === "loading" ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-route", style: { marginTop: 12 }, children: [
|
|
3997
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-skel" }),
|
|
3998
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-muted", style: { fontSize: 13 }, children: [
|
|
3999
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-spinner" }),
|
|
4000
|
+
" Finding the best way to pay\u2026"
|
|
4001
|
+
] })
|
|
4002
|
+
] }) : null,
|
|
4003
|
+
flow.status === "error" && flow.error ? /* @__PURE__ */ jsxRuntime.jsx(StatusPanel, { tone: "error", children: flow.error }) : null,
|
|
4004
|
+
sel && selectedVisible && flow.status !== "loading" ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-panel", style: { marginTop: 12 }, children: [
|
|
4005
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-label", children: "You pay" }),
|
|
4006
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-anchor sg-mono", children: [
|
|
4007
|
+
sel.source.payAmount,
|
|
4008
|
+
" ",
|
|
4009
|
+
sel.source.asset
|
|
4010
|
+
] }),
|
|
4011
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-anchor-sub", children: [
|
|
4012
|
+
"on ",
|
|
4013
|
+
CHAIN_LABELS[sel.source.chainId] || sel.source.chainName,
|
|
4014
|
+
selBal ? ` \xB7 balance ${selBal.formatted}` : ""
|
|
4015
|
+
] })
|
|
4016
|
+
] }) : null,
|
|
4017
|
+
why ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-why", style: { marginTop: 10 }, children: why }) : null,
|
|
4018
|
+
scannedEmpty ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-note", children: "None of your balances can cover this yet \u2014 pick a different asset to fund with." }) : null,
|
|
4019
|
+
flow.status === "ready" && !visibleRoutes.length ? /* @__PURE__ */ jsxRuntime.jsx(StatusPanel, { children: "No funding route matches the accepted assets for this payment." }) : null
|
|
4020
|
+
] }),
|
|
4021
|
+
submitting ? /* @__PURE__ */ jsxRuntime.jsx(StepList, { steps: flow.steps }) : null,
|
|
4022
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-cta-wrap", children: /* @__PURE__ */ jsxRuntime.jsx(Button, { onClick: parked || !selectedVisible ? void 0 : flow.submit, busy: submitting, disabled: parked || !selectedVisible || flow.insufficient || !!flow.nativeShortfall || flow.status === "loading", children: payLabel }) })
|
|
4023
|
+
] })
|
|
4024
|
+
] }) });
|
|
4025
|
+
}
|
|
4026
|
+
var chainOptions = SUPPORTED_CHAINS.map((c) => ({ value: c, label: CHAIN_LABELS[c] || `Chain ${c}` }));
|
|
4027
|
+
var assetOptions = SUPPORTED_ASSETS2.map((a) => ({ value: a, label: a }));
|
|
4028
|
+
function CheckGlyph4() {
|
|
4029
|
+
return /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "3", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M20 6 9 17l-5-5" }) });
|
|
4030
|
+
}
|
|
4031
|
+
function StableGenieSwap(props) {
|
|
4032
|
+
const config = useMergedConfig(props);
|
|
4033
|
+
const engine = useEngine({ apiBase: config.apiBase, apiKey: config.apiKey, trustedApiOrigin: config.trustedApiOrigin, rpcOverrides: config.rpcOverrides, onTransaction: config.onTransaction });
|
|
4034
|
+
const wallet = useWallet(config.provider);
|
|
4035
|
+
const [fromChainId, setFromChainId] = react.useState(props.defaultFromChainId ?? 42161);
|
|
4036
|
+
const [fromAsset, setFromAsset] = react.useState(props.defaultFromAsset ?? "USDT");
|
|
4037
|
+
const [toChainId, setToChainId] = react.useState(props.defaultToChainId ?? 8453);
|
|
4038
|
+
const [toAsset, setToAsset] = react.useState(props.defaultToAsset ?? "USDC");
|
|
4039
|
+
const [amount, setAmount] = react.useState(props.defaultAmount ?? "");
|
|
4040
|
+
const amountValid = /^\d+(\.\d+)?$/.test(amount.replace(",", ".")) && Number(amount.replace(",", ".")) > 0;
|
|
4041
|
+
const enabled = amountValid && props.variant !== "pill";
|
|
4042
|
+
const paramsKey = `${fromChainId}|${fromAsset}|${toChainId}|${toAsset}|${amount}|${props.recipient ?? ""}`;
|
|
4043
|
+
const flow = useFlow({
|
|
4044
|
+
engine,
|
|
4045
|
+
wallet,
|
|
4046
|
+
kind: "swap",
|
|
4047
|
+
enabled,
|
|
4048
|
+
paramsKey,
|
|
4049
|
+
loadPlan: (e, payer) => e.buildSwapPlan({ fromChainId, toChainId, fromToken: fromAsset, toToken: toAsset, amountIn: amount, recipient: props.recipient }, payer),
|
|
4050
|
+
recipientFor: (account) => props.recipient || account,
|
|
4051
|
+
onQuote: config.onQuote,
|
|
4052
|
+
onSuccess: config.onSuccess,
|
|
4053
|
+
onError: config.onError
|
|
4054
|
+
});
|
|
4055
|
+
const reverse = () => {
|
|
4056
|
+
setFromChainId(toChainId);
|
|
4057
|
+
setFromAsset(toAsset);
|
|
4058
|
+
setToChainId(fromChainId);
|
|
4059
|
+
setToAsset(fromAsset);
|
|
4060
|
+
};
|
|
4061
|
+
const receive = flow.selected?.receive.amount;
|
|
4062
|
+
const submitting = flow.status === "submitting";
|
|
4063
|
+
const swapLabel = submitting ? "Swapping\u2026" : flow.insufficient ? "Insufficient balance" : flow.nativeShortfall || "Swap";
|
|
4064
|
+
const toValue = react.useMemo(() => receive ? `${receive}` : flow.status === "loading" ? "\u2026" : "\u2014", [receive, flow.status]);
|
|
4065
|
+
const [hist, setHist] = react.useState(null);
|
|
4066
|
+
const histBtnRef = react.useRef(null);
|
|
4067
|
+
const closeHistory = () => {
|
|
4068
|
+
setHist(null);
|
|
4069
|
+
requestAnimationFrame(() => histBtnRef.current?.focus());
|
|
4070
|
+
};
|
|
4071
|
+
react.useEffect(() => setHist(null), [wallet.account]);
|
|
4072
|
+
const [registryTokens, setRegistryTokens] = react.useState([]);
|
|
4073
|
+
react.useEffect(() => {
|
|
4074
|
+
if (props.variant === "pill" || !hist) return;
|
|
4075
|
+
let alive = true;
|
|
4076
|
+
engine.fetchTokens().then((ts) => {
|
|
4077
|
+
if (alive) setRegistryTokens(ts);
|
|
4078
|
+
}).catch(() => {
|
|
4079
|
+
});
|
|
4080
|
+
return () => {
|
|
4081
|
+
alive = false;
|
|
4082
|
+
};
|
|
4083
|
+
}, [engine, props.variant, hist]);
|
|
4084
|
+
const lastTxOwned = Boolean(flow.lastTxEntry?.hash && wallet.account && flow.lastTxEntry.account === wallet.account.toLowerCase());
|
|
4085
|
+
if (props.variant === "pill") return /* @__PURE__ */ jsxRuntime.jsx(PaymentIsland, { kind: "swap", ...props });
|
|
4086
|
+
const walletSlot = wallet.account ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-head-tools", children: [
|
|
4087
|
+
/* @__PURE__ */ jsxRuntime.jsx(HistoryButton, { btnRef: histBtnRef, disabled: submitting, onClick: () => setHist({}) }),
|
|
4088
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-brand", children: "ZeroDelta" })
|
|
4089
|
+
] }) : void 0;
|
|
4090
|
+
if (hist && wallet.account) {
|
|
4091
|
+
return /* @__PURE__ */ jsxRuntime.jsx(WidgetShell, { title: config.title || "Swap", theme: config.theme, walletSlot, children: /* @__PURE__ */ jsxRuntime.jsx(TxHistoryPanel, { account: wallet.account, tokens: registryTokens, initialEntry: hist.entry ?? null, onBack: closeHistory }) });
|
|
4092
|
+
}
|
|
4093
|
+
if (flow.status === "success" || flow.status === "pending") {
|
|
4094
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(WidgetShell, { title: config.title || "Swap", theme: config.theme, walletSlot, children: [
|
|
4095
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-success", children: [
|
|
4096
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-success-check", "data-pending": flow.verdict?.status !== "confirmed", children: /* @__PURE__ */ jsxRuntime.jsx(CheckGlyph4, {}) }),
|
|
4097
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-success-amt sg-mono", children: [
|
|
4098
|
+
receive,
|
|
4099
|
+
" ",
|
|
4100
|
+
toAsset
|
|
4101
|
+
] }),
|
|
4102
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-success-sub", children: [
|
|
4103
|
+
flow.verdict?.status === "confirmed" ? "Confirmed on-chain" : "Submitted \u2014 awaiting confirmation",
|
|
4104
|
+
props.recipient ? ` \xB7 ${shortAddress(props.recipient)}` : ""
|
|
4105
|
+
] })
|
|
4106
|
+
] }),
|
|
4107
|
+
lastTxOwned ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-cta-wrap", children: /* @__PURE__ */ jsxRuntime.jsx(Button, { variant: "ghost", onClick: () => setHist({ entry: flow.lastTxEntry }), children: "View transaction" }) }) : null
|
|
4108
|
+
] });
|
|
4109
|
+
}
|
|
4110
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(WidgetShell, { title: config.title || "Swap", theme: config.theme, walletSlot, children: [
|
|
4111
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-panel", children: [
|
|
4112
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-label", children: "You pay" }),
|
|
4113
|
+
/* @__PURE__ */ jsxRuntime.jsx(AmountInput, { value: amount, onChange: setAmount, disabled: submitting }),
|
|
4114
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-row", style: { marginTop: 8 }, children: [
|
|
4115
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-grow", children: /* @__PURE__ */ jsxRuntime.jsx(Select, { value: fromAsset, onChange: setFromAsset, options: assetOptions, disabled: submitting }) }),
|
|
4116
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-grow", children: /* @__PURE__ */ jsxRuntime.jsx(Select, { value: fromChainId, onChange: (v) => setFromChainId(Number(v)), options: chainOptions, disabled: submitting }) })
|
|
4117
|
+
] })
|
|
4118
|
+
] }),
|
|
4119
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "sg-reverse", onClick: reverse, "aria-label": "Reverse", disabled: submitting, children: "\u2193" }),
|
|
4120
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-panel", children: [
|
|
4121
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-label", children: "You receive (estimated)" }),
|
|
4122
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-anchor sg-mono", children: toValue }),
|
|
4123
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-row", style: { marginTop: 8 }, children: [
|
|
4124
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-grow", children: /* @__PURE__ */ jsxRuntime.jsx(Select, { value: toAsset, onChange: setToAsset, options: assetOptions, disabled: submitting }) }),
|
|
4125
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-grow", children: /* @__PURE__ */ jsxRuntime.jsx(Select, { value: toChainId, onChange: (v) => setToChainId(Number(v)), options: chainOptions, disabled: submitting }) })
|
|
4126
|
+
] })
|
|
4127
|
+
] }),
|
|
4128
|
+
flow.status === "error" && flow.error ? /* @__PURE__ */ jsxRuntime.jsx(StatusPanel, { tone: "error", children: flow.error }) : null,
|
|
4129
|
+
flow.routes.length ? /* @__PURE__ */ jsxRuntime.jsx(RouteList, { routes: flow.routes, selectedId: flow.selected?.id ?? null, onSelect: flow.selectRoute }) : null,
|
|
4130
|
+
submitting ? /* @__PURE__ */ jsxRuntime.jsx(StepList, { steps: flow.steps }) : null,
|
|
4131
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-cta-wrap", children: [
|
|
4132
|
+
!wallet.account ? /* @__PURE__ */ jsxRuntime.jsx(Button, { onClick: wallet.connect, busy: wallet.connecting, children: "Connect wallet" }) : /* @__PURE__ */ jsxRuntime.jsx(Button, { onClick: flow.submit, busy: submitting, disabled: !flow.selected || flow.insufficient || !!flow.nativeShortfall || !enabled || flow.status === "loading", children: swapLabel }),
|
|
4133
|
+
wallet.error ? /* @__PURE__ */ jsxRuntime.jsx(StatusPanel, { tone: "error", children: wallet.error }) : null
|
|
4134
|
+
] })
|
|
4135
|
+
] });
|
|
4136
|
+
}
|
|
4137
|
+
var STABLE_ASSETS = ["USDC", "USDT", "USDE"];
|
|
4138
|
+
var FIAT = [
|
|
4139
|
+
{ code: "USD", glyph: "$", label: "US Dollar" },
|
|
4140
|
+
{ code: "EUR", glyph: "\u20AC", label: "Euro" },
|
|
4141
|
+
{ code: "GBP", glyph: "\xA3", label: "British Pound" },
|
|
4142
|
+
{ code: "CHF", glyph: "\u20A3", label: "Swiss Franc" }
|
|
4143
|
+
];
|
|
4144
|
+
function ArrowGlyph2() {
|
|
4145
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.4", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
|
|
4146
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M5 12h14" }),
|
|
4147
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "m13 6 6 6-6 6" })
|
|
4148
|
+
] });
|
|
4149
|
+
}
|
|
4150
|
+
function RouteGlyph() {
|
|
4151
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", "aria-hidden": "true", children: [
|
|
4152
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "6", cy: "19", r: "2.4" }),
|
|
4153
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "18", cy: "5", r: "2.4" }),
|
|
4154
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M8.4 19H15a3 3 0 0 0 0-6H9a3 3 0 0 1 0-6h6.6" })
|
|
4155
|
+
] });
|
|
4156
|
+
}
|
|
4157
|
+
function CheckGlyph5() {
|
|
4158
|
+
return /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "3", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M20 6 9 17l-5-5" }) });
|
|
4159
|
+
}
|
|
4160
|
+
function FiatTile(props) {
|
|
4161
|
+
const fiat = FIAT.find((f) => f.code === props.currency) ?? FIAT[0];
|
|
4162
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-tile", style: { cursor: "default" }, children: [
|
|
4163
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-tile-label", children: props.label }),
|
|
4164
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "sg-tile-main", children: [
|
|
4165
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-fiat", children: fiat.glyph }),
|
|
4166
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { style: { minWidth: 0, flex: 1 }, children: [
|
|
4167
|
+
/* @__PURE__ */ jsxRuntime.jsx("select", { className: "sg-select", style: { padding: "6px 8px", fontSize: 14, fontWeight: 700 }, value: fiat.code, disabled: props.disabled, onChange: (e) => props.onCurrency(e.target.value), "aria-label": `${props.label} currency`, children: FIAT.map((f) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: f.code, children: f.code }, f.code)) }),
|
|
4168
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-tile-chain", children: fiat.label })
|
|
4169
|
+
] })
|
|
4170
|
+
] })
|
|
4171
|
+
] });
|
|
4172
|
+
}
|
|
4173
|
+
function StableGenieExchange(props) {
|
|
4174
|
+
const config = useMergedConfig(props);
|
|
4175
|
+
const engine = useEngine({ apiBase: config.apiBase, apiKey: config.apiKey, trustedApiOrigin: config.trustedApiOrigin, rpcOverrides: config.rpcOverrides, onTransaction: config.onTransaction });
|
|
4176
|
+
const wallet = useWallet(config.provider);
|
|
4177
|
+
const mode = props.mode ?? "exchange";
|
|
4178
|
+
const wide = props.variant === "wide";
|
|
4179
|
+
const isPill = props.variant === "pill";
|
|
4180
|
+
const allowed = react.useMemo(() => (props.assets?.length ? props.assets : STABLE_ASSETS).map((a) => symbolKey(a)), [props.assets]);
|
|
4181
|
+
const [chains, setChains] = react.useState([]);
|
|
4182
|
+
const [tokens, setTokens] = react.useState([]);
|
|
4183
|
+
react.useEffect(() => {
|
|
4184
|
+
if (isPill) return;
|
|
4185
|
+
let alive = true;
|
|
4186
|
+
Promise.all([engine.fetchChains().catch(() => []), engine.fetchTokens().catch(() => [])]).then(([cs, ts]) => {
|
|
4187
|
+
if (!alive) return;
|
|
4188
|
+
const order = new Map(SUPPORTED_CHAINS.map((id, i) => [id, i]));
|
|
4189
|
+
setChains(
|
|
4190
|
+
cs.filter((c) => SUPPORTED_CHAIN_IDS.has(Number(c.chainId)) && c.isEnabled !== false).sort((a, b) => (order.get(Number(a.chainId)) ?? 99) - (order.get(Number(b.chainId)) ?? 99))
|
|
4191
|
+
);
|
|
4192
|
+
setTokens(ts.filter((t) => tokenEnabled(t) && SUPPORTED_CHAIN_IDS.has(Number(t.chainId)) && allowed.includes(symbolKey(t.symbol)) && isDeliverable(symbolKey(t.symbol), Number(t.chainId))));
|
|
4193
|
+
});
|
|
4194
|
+
return () => {
|
|
4195
|
+
alive = false;
|
|
4196
|
+
};
|
|
4197
|
+
}, [engine, allowed]);
|
|
4198
|
+
const [view, setView] = react.useState("main");
|
|
4199
|
+
const [hist, setHist] = react.useState(null);
|
|
4200
|
+
const histBtnRef = react.useRef(null);
|
|
4201
|
+
const closeHistory = () => {
|
|
4202
|
+
setHist(null);
|
|
4203
|
+
requestAnimationFrame(() => histBtnRef.current?.focus());
|
|
4204
|
+
};
|
|
4205
|
+
react.useEffect(() => setHist(null), [wallet.account]);
|
|
4206
|
+
const [from, setFrom] = react.useState(
|
|
4207
|
+
() => props.defaultFromChainId && props.defaultFromAsset && allowed.includes(symbolKey(props.defaultFromAsset)) ? { chainId: props.defaultFromChainId, symbol: symbolKey(props.defaultFromAsset) } : null
|
|
4208
|
+
);
|
|
4209
|
+
const [to, setTo] = react.useState(
|
|
4210
|
+
() => props.defaultToChainId && props.defaultToAsset && allowed.includes(symbolKey(props.defaultToAsset)) ? { chainId: props.defaultToChainId, symbol: symbolKey(props.defaultToAsset) } : null
|
|
4211
|
+
);
|
|
4212
|
+
const [amount, setAmount] = react.useState(props.defaultAmount ?? "");
|
|
4213
|
+
const [fiatCurrency, setFiatCurrency] = react.useState(props.fiatCurrency ?? "EUR");
|
|
4214
|
+
const fromToken = react.useMemo(() => from ? findToken(tokens, from.chainId, from.symbol) : null, [tokens, from]);
|
|
4215
|
+
const toToken = react.useMemo(() => to ? findToken(tokens, to.chainId, to.symbol) : null, [tokens, to]);
|
|
4216
|
+
const normalizedAmount = normalizeDecimalText(amount);
|
|
4217
|
+
const amountValid = /^\d+(\.\d+)?$/.test(normalizedAmount) && Number(normalizedAmount) > 0 && Number(normalizedAmount) <= 1e9;
|
|
4218
|
+
const rampMode = mode !== "exchange";
|
|
4219
|
+
const inUniverse = (p) => Boolean(p && allowed.includes(p.symbol));
|
|
4220
|
+
const cryptoReady = rampMode ? inUniverse(mode === "onramp" ? to : from) : inUniverse(from) && inUniverse(to);
|
|
4221
|
+
const quotable = mode === "exchange" && inUniverse(from) && inUniverse(to) && amountValid;
|
|
4222
|
+
const [balances, setBalances] = react.useState({});
|
|
4223
|
+
const balReq = react.useRef(0);
|
|
4224
|
+
react.useEffect(() => {
|
|
4225
|
+
if (isPill) return;
|
|
4226
|
+
setBalances({});
|
|
4227
|
+
if (!wallet.account || !tokens.length) return;
|
|
4228
|
+
const id = ++balReq.current;
|
|
4229
|
+
const targets = [];
|
|
4230
|
+
for (const t of tokens) {
|
|
4231
|
+
try {
|
|
4232
|
+
targets.push({ chainId: Number(t.chainId), tokenAddress: t.address, decimals: assetDecimals(t) });
|
|
4233
|
+
} catch {
|
|
4234
|
+
}
|
|
4235
|
+
}
|
|
4236
|
+
if (!targets.length) return;
|
|
4237
|
+
engine.readBalances(wallet.account, targets).then((res) => {
|
|
4238
|
+
if (id === balReq.current) setBalances(res);
|
|
4239
|
+
});
|
|
4240
|
+
}, [engine, wallet.account, tokens]);
|
|
4241
|
+
const fromBal = from && fromToken ? balances[balanceKey(from.chainId, fromToken.address)] : void 0;
|
|
4242
|
+
const paramsKey = `${mode}|${from?.chainId}|${from?.symbol}|${to?.chainId}|${to?.symbol}|${normalizedAmount}|${props.recipient ?? ""}`;
|
|
4243
|
+
const flow = useFlow({
|
|
4244
|
+
engine,
|
|
4245
|
+
wallet,
|
|
4246
|
+
kind: "swap",
|
|
4247
|
+
enabled: quotable && !isPill,
|
|
4248
|
+
paramsKey,
|
|
4249
|
+
loadPlan: (e, payer) => e.buildSwapPlan({ fromChainId: from.chainId, toChainId: to.chainId, fromToken: from.symbol, toToken: to.symbol, amountIn: normalizedAmount, recipient: props.recipient }, payer),
|
|
4250
|
+
recipientFor: (account) => props.recipient || account,
|
|
4251
|
+
onQuote: config.onQuote,
|
|
4252
|
+
onSuccess: config.onSuccess,
|
|
4253
|
+
onError: config.onError
|
|
4254
|
+
});
|
|
4255
|
+
const [preview, setPreview] = react.useState({ status: "idle" });
|
|
4256
|
+
const prevReq = react.useRef(0);
|
|
4257
|
+
react.useEffect(() => {
|
|
4258
|
+
if (isPill || wallet.account || !quotable) {
|
|
4259
|
+
prevReq.current += 1;
|
|
4260
|
+
setPreview({ status: "idle" });
|
|
4261
|
+
return;
|
|
4262
|
+
}
|
|
4263
|
+
const id = ++prevReq.current;
|
|
4264
|
+
setPreview({ status: "loading" });
|
|
4265
|
+
const timer = setTimeout(() => {
|
|
4266
|
+
engine.quoteSwapPreview({ fromChainId: from.chainId, toChainId: to.chainId, fromToken: from.symbol, toToken: to.symbol, amountIn: normalizedAmount, recipient: props.recipient }).then((data) => {
|
|
4267
|
+
if (id === prevReq.current) setPreview({ status: "ready", data });
|
|
4268
|
+
}).catch((e) => {
|
|
4269
|
+
if (id === prevReq.current) setPreview({ status: "error", error: e instanceof Error ? e.message : String(e) });
|
|
4270
|
+
});
|
|
4271
|
+
}, 350);
|
|
4272
|
+
return () => clearTimeout(timer);
|
|
4273
|
+
}, [engine, wallet.account, quotable, paramsKey]);
|
|
4274
|
+
const connected = Boolean(wallet.account);
|
|
4275
|
+
const submitting = flow.status === "submitting";
|
|
4276
|
+
const lastTxOwned = Boolean(flow.lastTxEntry?.hash && wallet.account && flow.lastTxEntry.account === wallet.account.toLowerCase());
|
|
4277
|
+
const quoting = connected ? flow.status === "loading" : preview.status === "loading";
|
|
4278
|
+
const quoteError = !quotable ? null : connected ? flow.status === "error" ? flow.error : null : preview.status === "error" ? preview.error ?? "No route." : null;
|
|
4279
|
+
const receive = connected ? flow.selected?.receive.amount : preview.data?.receive;
|
|
4280
|
+
const meta = connected ? flow.selected ? { bridge: flow.selected.quote.bridge || "ZeroDelta", feeBps: Number(flow.selected.quote.feeBps || 0), duration: Number(flow.selected.quote.estimatedDuration || 0) } : null : preview.data ? { bridge: preview.data.bridge || "ZeroDelta", feeBps: preview.data.feeBps, duration: preview.data.estimatedDuration } : null;
|
|
4281
|
+
const pct = (p) => {
|
|
4282
|
+
if (!fromBal || !fromToken) return;
|
|
4283
|
+
const raw = BigInt(fromBal.raw);
|
|
4284
|
+
setAmount(formatUnits(p === 100 ? raw : raw * BigInt(p) / 100n, assetDecimals(fromToken)));
|
|
4285
|
+
};
|
|
4286
|
+
const title = config.title || (mode === "onramp" ? "Buy stablecoins" : mode === "offramp" ? "Cash out" : "Exchange");
|
|
4287
|
+
const soonLabel = mode === "onramp" ? "On-ramp coming soon" : "Off-ramp coming soon";
|
|
4288
|
+
const ctaLabel = rampMode ? soonLabel : submitting ? "Exchanging\u2026" : flow.insufficient ? "Insufficient balance" : flow.nativeShortfall || "Exchange";
|
|
4289
|
+
const walletSlot = /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-head-tools", children: [
|
|
4290
|
+
connected ? /* @__PURE__ */ jsxRuntime.jsx(HistoryButton, { btnRef: histBtnRef, disabled: submitting, onClick: () => setHist({}) }) : null,
|
|
4291
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "sg-wallet", "data-connected": connected || void 0, onClick: connected ? void 0 : wallet.connect, disabled: wallet.connecting, children: connected ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
4292
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-wallet-dot", "aria-hidden": "true" }),
|
|
4293
|
+
" ",
|
|
4294
|
+
shortAddress(wallet.account)
|
|
4295
|
+
] }) : wallet.connecting ? "Connecting\u2026" : "Connect wallet" })
|
|
4296
|
+
] });
|
|
4297
|
+
const fromTileRef = react.useRef(null);
|
|
4298
|
+
const toTileRef = react.useRef(null);
|
|
4299
|
+
const closeSelector = (isFrom) => {
|
|
4300
|
+
setView("main");
|
|
4301
|
+
requestAnimationFrame(() => (isFrom ? fromTileRef : toTileRef).current?.focus());
|
|
4302
|
+
};
|
|
4303
|
+
if (props.variant === "pill") return /* @__PURE__ */ jsxRuntime.jsx(PaymentIsland, { kind: "exchange", ...props });
|
|
4304
|
+
let body;
|
|
4305
|
+
if (hist && connected) {
|
|
4306
|
+
body = /* @__PURE__ */ jsxRuntime.jsx(TxHistoryPanel, { account: wallet.account, tokens, initialEntry: hist.entry ?? null, onBack: closeHistory });
|
|
4307
|
+
} else if (view === "from" || view === "to") {
|
|
4308
|
+
const isFrom = view === "from";
|
|
4309
|
+
body = /* @__PURE__ */ jsxRuntime.jsx(
|
|
4310
|
+
TokenSelect,
|
|
4311
|
+
{
|
|
4312
|
+
title: isFrom ? "Exchange from" : "Exchange to",
|
|
4313
|
+
chains,
|
|
4314
|
+
tokens,
|
|
4315
|
+
balances,
|
|
4316
|
+
onBack: () => closeSelector(isFrom),
|
|
4317
|
+
onPick: (pick) => {
|
|
4318
|
+
(isFrom ? setFrom : setTo)({ chainId: pick.chainId, symbol: symbolKey(pick.symbol) });
|
|
4319
|
+
closeSelector(isFrom);
|
|
4320
|
+
}
|
|
4321
|
+
}
|
|
4322
|
+
);
|
|
4323
|
+
} else if (flow.status === "success" || flow.status === "pending") {
|
|
4324
|
+
body = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
4325
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-success", children: [
|
|
4326
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-success-check", "data-pending": flow.verdict?.status !== "confirmed", children: /* @__PURE__ */ jsxRuntime.jsx(CheckGlyph5, {}) }),
|
|
4327
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-success-amt sg-mono", children: [
|
|
4328
|
+
receive,
|
|
4329
|
+
" ",
|
|
4330
|
+
to?.symbol
|
|
4331
|
+
] }),
|
|
4332
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-success-sub", children: [
|
|
4333
|
+
flow.verdict?.status === "confirmed" ? "Confirmed on-chain" : "Submitted \u2014 awaiting confirmation",
|
|
4334
|
+
props.recipient ? ` \xB7 ${shortAddress(props.recipient)}` : ""
|
|
4335
|
+
] })
|
|
4336
|
+
] }),
|
|
4337
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-cta-wrap", children: [
|
|
4338
|
+
lastTxOwned ? /* @__PURE__ */ jsxRuntime.jsx(Button, { variant: "ghost", onClick: () => setHist({ entry: flow.lastTxEntry }), children: "View transaction" }) : null,
|
|
4339
|
+
/* @__PURE__ */ jsxRuntime.jsx(Button, { variant: "ghost", onClick: flow.reload, children: "Start a new exchange" })
|
|
4340
|
+
] })
|
|
4341
|
+
] });
|
|
4342
|
+
} else {
|
|
4343
|
+
body = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
4344
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-ft", children: [
|
|
4345
|
+
mode === "onramp" ? /* @__PURE__ */ jsxRuntime.jsx(FiatTile, { label: "From", currency: fiatCurrency, onCurrency: setFiatCurrency }) : /* @__PURE__ */ jsxRuntime.jsx(TokenTile, { label: "From", pick: from, token: fromToken, disabled: submitting, btnRef: fromTileRef, onClick: () => setView("from") }),
|
|
4346
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-ft-arrow", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx(ArrowGlyph2, {}) }),
|
|
4347
|
+
mode === "offramp" ? /* @__PURE__ */ jsxRuntime.jsx(FiatTile, { label: "To", currency: fiatCurrency, onCurrency: setFiatCurrency }) : /* @__PURE__ */ jsxRuntime.jsx(TokenTile, { label: "To", pick: to, token: toToken, disabled: submitting, btnRef: toTileRef, onClick: () => setView("to") })
|
|
4348
|
+
] }),
|
|
4349
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-panel", style: { marginTop: 12 }, children: [
|
|
4350
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-label", children: mode === "onramp" ? `You pay (${fiatCurrency})` : "Send" }),
|
|
4351
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-send-row", children: [
|
|
4352
|
+
mode === "onramp" ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-fiat", children: FIAT.find((f) => f.code === fiatCurrency)?.glyph ?? "$" }) : from ? /* @__PURE__ */ jsxRuntime.jsx(TokenGlyph, { symbol: from.symbol, logoUrl: fromToken?.logoUrl, chainId: from.chainId, size: "sm" }) : null,
|
|
4353
|
+
/* @__PURE__ */ jsxRuntime.jsx(AmountInput, { value: amount, onChange: setAmount, disabled: submitting })
|
|
4354
|
+
] }),
|
|
4355
|
+
mode !== "onramp" && fromBal ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-send-bal sg-mono", children: [
|
|
4356
|
+
"Balance: ",
|
|
4357
|
+
fromBal.formatted,
|
|
4358
|
+
" ",
|
|
4359
|
+
from?.symbol
|
|
4360
|
+
] }) : null,
|
|
4361
|
+
mode !== "onramp" ? (
|
|
4362
|
+
// a11y note: <fieldset> carries UA styling that would
|
|
4363
|
+
// have to be reset on every host page; role="group" gives the same semantics.
|
|
4364
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-pct-row", role: "group", "aria-label": "Amount shortcuts", children: [25, 50, 75, 100].map((p) => /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "sg-pct", disabled: !fromBal || submitting, onClick: () => pct(p), children: p === 100 ? "MAX" : `${p}%` }, p)) })
|
|
4365
|
+
) : null
|
|
4366
|
+
] }),
|
|
4367
|
+
rampMode ? /* @__PURE__ */ jsxRuntime.jsx(StatusPanel, { children: mode === "onramp" ? "Buy supported stablecoins with card or bank transfer \u2014 coming soon. Today the widget settles crypto-to-crypto." : "Cash out supported stablecoins to your bank \u2014 coming soon. Today the widget settles crypto-to-crypto." }) : null,
|
|
4368
|
+
!rampMode && quoteError && !wide ? /* @__PURE__ */ jsxRuntime.jsx(StatusPanel, { tone: "error", children: quoteError }) : null,
|
|
4369
|
+
!rampMode && !wide && quotable && !quoteError ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-panel", style: { marginTop: 12 }, children: [
|
|
4370
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-label", children: "You receive (estimated)" }),
|
|
4371
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-anchor sg-mono", children: quoting ? "\u2026" : receive ? `${receive} ${to?.symbol}` : "\u2014" }),
|
|
4372
|
+
meta && !quoting ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-recv-sub", children: [
|
|
4373
|
+
"via ",
|
|
4374
|
+
meta.bridge,
|
|
4375
|
+
" \xB7 fee ",
|
|
4376
|
+
meta.feeBps,
|
|
4377
|
+
" bps",
|
|
4378
|
+
meta.duration ? ` \xB7 ~${meta.duration}s` : ""
|
|
4379
|
+
] }) : null
|
|
4380
|
+
] }) : null,
|
|
4381
|
+
submitting ? /* @__PURE__ */ jsxRuntime.jsx(StepList, { steps: flow.steps }) : null,
|
|
4382
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-cta-wrap", children: [
|
|
4383
|
+
!connected && !rampMode ? /* @__PURE__ */ jsxRuntime.jsx(Button, { onClick: wallet.connect, busy: wallet.connecting, children: "Connect wallet" }) : /* @__PURE__ */ jsxRuntime.jsx(Button, { onClick: rampMode ? void 0 : flow.submit, busy: submitting, disabled: rampMode || !quotable || !cryptoReady || connected && (!flow.selected || flow.insufficient || !!flow.nativeShortfall || flow.status === "loading"), children: ctaLabel }),
|
|
4384
|
+
wallet.error ? /* @__PURE__ */ jsxRuntime.jsx(StatusPanel, { tone: "error", children: wallet.error }) : null
|
|
4385
|
+
] })
|
|
4386
|
+
] });
|
|
4387
|
+
}
|
|
4388
|
+
const card = /* @__PURE__ */ jsxRuntime.jsx(WidgetShell, { title, theme: config.theme, heightPx: props.heightPx, walletSlot, children: body });
|
|
4389
|
+
if (!wide) return card;
|
|
4390
|
+
const resolved = resolveTheme(config.theme);
|
|
4391
|
+
const vars = themeToVars(resolved);
|
|
4392
|
+
let side;
|
|
4393
|
+
if (rampMode) {
|
|
4394
|
+
side = /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-noroutes", children: [
|
|
4395
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-noroutes-icon", children: /* @__PURE__ */ jsxRuntime.jsx(RouteGlyph, {}) }),
|
|
4396
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-noroutes-title", children: soonLabel }),
|
|
4397
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-noroutes-sub", children: "Fiat rails are on the roadmap. Crypto-to-crypto exchange is live today." })
|
|
4398
|
+
] });
|
|
4399
|
+
} else if (quoting) {
|
|
4400
|
+
side = /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
4401
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-skel" }),
|
|
4402
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-skel" }),
|
|
4403
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-muted", style: { fontSize: 13 }, children: [
|
|
4404
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-spinner" }),
|
|
4405
|
+
" Finding routes\u2026"
|
|
4406
|
+
] })
|
|
4407
|
+
] });
|
|
4408
|
+
} else if (quoteError) {
|
|
4409
|
+
side = /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-noroutes", children: [
|
|
4410
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-noroutes-icon", children: /* @__PURE__ */ jsxRuntime.jsx(RouteGlyph, {}) }),
|
|
4411
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-noroutes-title", children: "No routes available" }),
|
|
4412
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-noroutes-sub", children: "Reasons for that could be: low liquidity, amount selected is too low, gas costs are too high or there are no routes for the selected combination." })
|
|
4413
|
+
] });
|
|
4414
|
+
} else if (receive && quotable) {
|
|
4415
|
+
side = /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
4416
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-recv-amt sg-mono", children: [
|
|
4417
|
+
receive,
|
|
4418
|
+
" ",
|
|
4419
|
+
to?.symbol
|
|
4420
|
+
] }),
|
|
4421
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-recv-sub", children: [
|
|
4422
|
+
"on ",
|
|
4423
|
+
CHAIN_LABELS[to?.chainId ?? 0] || `Chain ${to?.chainId}`
|
|
4424
|
+
] }),
|
|
4425
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-meta", children: [
|
|
4426
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-meta-row", children: [
|
|
4427
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-meta-label", children: "You send" }),
|
|
4428
|
+
/* @__PURE__ */ jsxRuntime.jsxs("b", { className: "sg-mono", children: [
|
|
4429
|
+
normalizedAmount,
|
|
4430
|
+
" ",
|
|
4431
|
+
from?.symbol
|
|
4432
|
+
] })
|
|
4433
|
+
] }),
|
|
4434
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-meta-row", children: [
|
|
4435
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-meta-label", children: "Route" }),
|
|
4436
|
+
/* @__PURE__ */ jsxRuntime.jsx("b", { children: meta?.bridge || "ZeroDelta" })
|
|
4437
|
+
] }),
|
|
4438
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-meta-row", children: [
|
|
4439
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-meta-label", children: "Fee" }),
|
|
4440
|
+
/* @__PURE__ */ jsxRuntime.jsxs("b", { children: [
|
|
4441
|
+
meta?.feeBps ?? 0,
|
|
4442
|
+
" bps"
|
|
4443
|
+
] })
|
|
4444
|
+
] }),
|
|
4445
|
+
meta?.duration ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-meta-row", children: [
|
|
4446
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-meta-label", children: "Est. time" }),
|
|
4447
|
+
/* @__PURE__ */ jsxRuntime.jsxs("b", { children: [
|
|
4448
|
+
"~",
|
|
4449
|
+
meta.duration,
|
|
4450
|
+
"s"
|
|
4451
|
+
] })
|
|
4452
|
+
] }) : null
|
|
4453
|
+
] })
|
|
4454
|
+
] });
|
|
4455
|
+
} else {
|
|
4456
|
+
side = /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-noroutes", children: [
|
|
4457
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-noroutes-icon", children: /* @__PURE__ */ jsxRuntime.jsx(RouteGlyph, {}) }),
|
|
4458
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-noroutes-title", children: "Routes appear here" }),
|
|
4459
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-noroutes-sub", children: "Pick the tokens and enter an amount to see how ZeroDelta will route it." })
|
|
4460
|
+
] });
|
|
4461
|
+
}
|
|
4462
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-duo-wrap", "data-sg-mode": resolved.mode, style: vars, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-duo", children: [
|
|
4463
|
+
card,
|
|
4464
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-widget", "data-sg-mode": resolved.mode, style: props.heightPx ? { height: props.heightPx } : void 0, children: [
|
|
4465
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-side-title", children: "Receive" }),
|
|
4466
|
+
side
|
|
4467
|
+
] })
|
|
4468
|
+
] }) });
|
|
4469
|
+
}
|
|
4470
|
+
|
|
4471
|
+
// src/mount.ts
|
|
4472
|
+
function mount(el, config) {
|
|
4473
|
+
const root = client.createRoot(el);
|
|
4474
|
+
const variant = config.variant ?? "pay";
|
|
4475
|
+
const Comp = variant === "swap" ? StableGenieSwap : variant === "exchange" ? StableGenieExchange : StableGeniePay;
|
|
4476
|
+
const { variant: _variant, ...props } = config;
|
|
4477
|
+
root.render(react.createElement(Comp, props));
|
|
4478
|
+
return () => root.unmount();
|
|
4479
|
+
}
|
|
4480
|
+
|
|
4481
|
+
exports.mount = mount;
|