@swype-org/react-sdk 0.1.112 → 0.1.115
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +403 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -3
- package/dist/index.d.ts +25 -3
- package/dist/index.js +403 -22
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -235,7 +235,10 @@ async function createAccount(apiBaseUrl, token, params) {
|
|
|
235
235
|
if (!res.ok) await throwApiError(res);
|
|
236
236
|
return await res.json();
|
|
237
237
|
}
|
|
238
|
-
async function createAccountAuthorizationSession(apiBaseUrl, token, accountId, credentialId) {
|
|
238
|
+
async function createAccountAuthorizationSession(apiBaseUrl, token, accountId, credentialId, options) {
|
|
239
|
+
const body = { credentialId };
|
|
240
|
+
if (options?.tokenAddress) body.tokenAddress = options.tokenAddress;
|
|
241
|
+
if (options?.chainId != null) body.chainId = options.chainId;
|
|
239
242
|
const res = await fetch(
|
|
240
243
|
`${apiBaseUrl}/v1/accounts/${accountId}/authorization-sessions`,
|
|
241
244
|
{
|
|
@@ -244,7 +247,7 @@ async function createAccountAuthorizationSession(apiBaseUrl, token, accountId, c
|
|
|
244
247
|
"Content-Type": "application/json",
|
|
245
248
|
Authorization: `Bearer ${token}`
|
|
246
249
|
},
|
|
247
|
-
body: JSON.stringify(
|
|
250
|
+
body: JSON.stringify(body)
|
|
248
251
|
}
|
|
249
252
|
);
|
|
250
253
|
if (!res.ok) await throwApiError(res);
|
|
@@ -1926,6 +1929,7 @@ function createInitialState(config) {
|
|
|
1926
1929
|
selectedProviderId: null,
|
|
1927
1930
|
selectedAccountId: null,
|
|
1928
1931
|
selectedWalletId: null,
|
|
1932
|
+
selectedTokenSymbol: null,
|
|
1929
1933
|
amount: config.depositAmount != null ? config.depositAmount.toString() : "",
|
|
1930
1934
|
transfer: null,
|
|
1931
1935
|
creatingTransfer: false,
|
|
@@ -2020,7 +2024,8 @@ function paymentReducer(state, action) {
|
|
|
2020
2024
|
...state,
|
|
2021
2025
|
selectedProviderId: action.providerId,
|
|
2022
2026
|
selectedAccountId: null,
|
|
2023
|
-
selectedWalletId: null
|
|
2027
|
+
selectedWalletId: null,
|
|
2028
|
+
selectedTokenSymbol: null
|
|
2024
2029
|
};
|
|
2025
2030
|
case "SELECT_ACCOUNT":
|
|
2026
2031
|
return {
|
|
@@ -2029,6 +2034,13 @@ function paymentReducer(state, action) {
|
|
|
2029
2034
|
selectedWalletId: action.walletId,
|
|
2030
2035
|
step: "deposit"
|
|
2031
2036
|
};
|
|
2037
|
+
case "SELECT_TOKEN":
|
|
2038
|
+
return {
|
|
2039
|
+
...state,
|
|
2040
|
+
selectedWalletId: action.walletId,
|
|
2041
|
+
selectedTokenSymbol: action.tokenSymbol,
|
|
2042
|
+
step: "deposit"
|
|
2043
|
+
};
|
|
2032
2044
|
// ── Transfer lifecycle ───────────────────────────────────────
|
|
2033
2045
|
case "PAY_STARTED":
|
|
2034
2046
|
return {
|
|
@@ -4202,7 +4214,8 @@ function DepositScreen({
|
|
|
4202
4214
|
selectedAccountId,
|
|
4203
4215
|
onSelectAccount,
|
|
4204
4216
|
onAuthorizeAccount,
|
|
4205
|
-
onAddProvider
|
|
4217
|
+
onAddProvider,
|
|
4218
|
+
onSelectToken
|
|
4206
4219
|
}) {
|
|
4207
4220
|
const { tokens } = useSwypeConfig();
|
|
4208
4221
|
const amount = initialAmount;
|
|
@@ -4332,12 +4345,20 @@ function DepositScreen({
|
|
|
4332
4345
|
] })
|
|
4333
4346
|
] })
|
|
4334
4347
|
] }),
|
|
4335
|
-
tokenCount > 0 && /* @__PURE__ */ jsxs(
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4348
|
+
tokenCount > 0 && /* @__PURE__ */ jsxs(
|
|
4349
|
+
"button",
|
|
4350
|
+
{
|
|
4351
|
+
type: "button",
|
|
4352
|
+
onClick: onSelectToken,
|
|
4353
|
+
style: tokenBadgeButtonStyle2(tokens, !!onSelectToken),
|
|
4354
|
+
children: [
|
|
4355
|
+
/* @__PURE__ */ jsx("span", { style: tokenDotStyle2(tokens.accent) }),
|
|
4356
|
+
tokenCount,
|
|
4357
|
+
" ",
|
|
4358
|
+
/* @__PURE__ */ jsx("span", { style: chevronInlineStyle, children: ">" })
|
|
4359
|
+
]
|
|
4360
|
+
}
|
|
4361
|
+
)
|
|
4341
4362
|
] }),
|
|
4342
4363
|
/* @__PURE__ */ jsxs("div", { style: detailsStyle, children: [
|
|
4343
4364
|
/* @__PURE__ */ jsxs("div", { style: detailRowStyle(tokens.textMuted), children: [
|
|
@@ -4395,7 +4416,7 @@ var balanceAmountStyle = {
|
|
|
4395
4416
|
fontSize: "1rem",
|
|
4396
4417
|
fontWeight: 700
|
|
4397
4418
|
};
|
|
4398
|
-
var
|
|
4419
|
+
var tokenBadgeButtonStyle2 = (tokens, clickable) => ({
|
|
4399
4420
|
display: "flex",
|
|
4400
4421
|
alignItems: "center",
|
|
4401
4422
|
gap: 4,
|
|
@@ -4403,7 +4424,10 @@ var tokenBadgeStyle = (tokens) => ({
|
|
|
4403
4424
|
color: tokens.textMuted,
|
|
4404
4425
|
border: `1px solid ${tokens.border}`,
|
|
4405
4426
|
borderRadius: 999,
|
|
4406
|
-
padding: "4px 10px"
|
|
4427
|
+
padding: "4px 10px",
|
|
4428
|
+
background: "transparent",
|
|
4429
|
+
fontFamily: "inherit",
|
|
4430
|
+
cursor: clickable ? "pointer" : "default"
|
|
4407
4431
|
});
|
|
4408
4432
|
var tokenDotStyle2 = (color) => ({
|
|
4409
4433
|
width: 8,
|
|
@@ -4412,7 +4436,7 @@ var tokenDotStyle2 = (color) => ({
|
|
|
4412
4436
|
background: color,
|
|
4413
4437
|
display: "inline-block"
|
|
4414
4438
|
});
|
|
4415
|
-
var
|
|
4439
|
+
var chevronInlineStyle = { fontSize: "0.68rem", marginLeft: 2 };
|
|
4416
4440
|
var detailsStyle = {
|
|
4417
4441
|
textAlign: "center",
|
|
4418
4442
|
marginTop: 12,
|
|
@@ -5301,6 +5325,236 @@ var errorStyle2 = (color) => ({
|
|
|
5301
5325
|
color: "#ef4444",
|
|
5302
5326
|
margin: "8px 0 0"
|
|
5303
5327
|
});
|
|
5328
|
+
function TokenPickerScreen({
|
|
5329
|
+
account,
|
|
5330
|
+
chains,
|
|
5331
|
+
onSelectAuthorized,
|
|
5332
|
+
onAuthorizeToken,
|
|
5333
|
+
onBack
|
|
5334
|
+
}) {
|
|
5335
|
+
const { tokens: themeTokens } = useSwypeConfig();
|
|
5336
|
+
const [selectedIndex, setSelectedIndex] = useState(null);
|
|
5337
|
+
const entries = [];
|
|
5338
|
+
for (const wallet of account.wallets) {
|
|
5339
|
+
for (const source of wallet.sources) {
|
|
5340
|
+
entries.push({
|
|
5341
|
+
walletId: wallet.id,
|
|
5342
|
+
chainName: wallet.chain.name,
|
|
5343
|
+
tokenSymbol: source.token.symbol,
|
|
5344
|
+
tokenAddress: source.address,
|
|
5345
|
+
balance: source.balance.total.amount,
|
|
5346
|
+
status: source.token.status
|
|
5347
|
+
});
|
|
5348
|
+
}
|
|
5349
|
+
}
|
|
5350
|
+
const selected = selectedIndex != null ? entries[selectedIndex] : null;
|
|
5351
|
+
const isAuthorized = selected?.status === "AUTHORIZED";
|
|
5352
|
+
const handleConfirm = () => {
|
|
5353
|
+
if (!selected) return;
|
|
5354
|
+
if (isAuthorized) {
|
|
5355
|
+
onSelectAuthorized(selected.walletId, selected.tokenSymbol);
|
|
5356
|
+
} else {
|
|
5357
|
+
const chain = chains.find((c) => c.name === selected.chainName);
|
|
5358
|
+
const evmChainId = chain?.commonId;
|
|
5359
|
+
if (evmChainId == null) return;
|
|
5360
|
+
onAuthorizeToken(selected.walletId, selected.tokenAddress, evmChainId, selected.tokenSymbol);
|
|
5361
|
+
}
|
|
5362
|
+
};
|
|
5363
|
+
const chainGroups = /* @__PURE__ */ new Map();
|
|
5364
|
+
for (const entry of entries) {
|
|
5365
|
+
const group = chainGroups.get(entry.chainName);
|
|
5366
|
+
if (group) {
|
|
5367
|
+
group.push(entry);
|
|
5368
|
+
} else {
|
|
5369
|
+
chainGroups.set(entry.chainName, [entry]);
|
|
5370
|
+
}
|
|
5371
|
+
}
|
|
5372
|
+
const [expandedChain, setExpandedChain] = useState(
|
|
5373
|
+
entries.length > 0 ? entries[0].chainName : null
|
|
5374
|
+
);
|
|
5375
|
+
return /* @__PURE__ */ jsxs(
|
|
5376
|
+
ScreenLayout,
|
|
5377
|
+
{
|
|
5378
|
+
footer: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
5379
|
+
/* @__PURE__ */ jsx(
|
|
5380
|
+
PrimaryButton,
|
|
5381
|
+
{
|
|
5382
|
+
onClick: handleConfirm,
|
|
5383
|
+
disabled: selected == null,
|
|
5384
|
+
children: selected == null ? "Select a token" : isAuthorized ? "Select Source" : "Authorize Token"
|
|
5385
|
+
}
|
|
5386
|
+
),
|
|
5387
|
+
/* @__PURE__ */ jsx(PoweredByFooter, {})
|
|
5388
|
+
] }),
|
|
5389
|
+
children: [
|
|
5390
|
+
/* @__PURE__ */ jsx(ScreenHeader, { title: "Select Token", onBack }),
|
|
5391
|
+
/* @__PURE__ */ jsx("p", { style: subtitleStyle11(themeTokens.textSecondary), children: "Choose a token to deposit with. Tokens that haven't been authorized yet will require a one-time wallet approval." }),
|
|
5392
|
+
/* @__PURE__ */ jsx("div", { style: chainListStyle2, children: [...chainGroups.entries()].map(([chainName, chainEntries]) => {
|
|
5393
|
+
const isExpanded = expandedChain === chainName;
|
|
5394
|
+
const chainTotal = chainEntries.reduce((sum, e) => sum + e.balance, 0);
|
|
5395
|
+
return /* @__PURE__ */ jsxs("div", { style: chainCardStyle2(themeTokens), children: [
|
|
5396
|
+
/* @__PURE__ */ jsxs(
|
|
5397
|
+
"button",
|
|
5398
|
+
{
|
|
5399
|
+
type: "button",
|
|
5400
|
+
onClick: () => setExpandedChain((prev) => prev === chainName ? null : chainName),
|
|
5401
|
+
style: chainHeaderStyle2(themeTokens),
|
|
5402
|
+
children: [
|
|
5403
|
+
/* @__PURE__ */ jsxs("div", { style: chainHeaderLeftStyle2, children: [
|
|
5404
|
+
/* @__PURE__ */ jsx("span", { style: chainNameStyle2(themeTokens.text), children: chainName }),
|
|
5405
|
+
/* @__PURE__ */ jsxs("span", { style: chainBalanceStyle2(themeTokens.textMuted), children: [
|
|
5406
|
+
"$",
|
|
5407
|
+
chainTotal.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 })
|
|
5408
|
+
] })
|
|
5409
|
+
] }),
|
|
5410
|
+
/* @__PURE__ */ jsx("span", { style: chevronStyle2(themeTokens.textMuted), children: isExpanded ? "\u25BE" : "\u25B8" })
|
|
5411
|
+
]
|
|
5412
|
+
}
|
|
5413
|
+
),
|
|
5414
|
+
isExpanded && /* @__PURE__ */ jsx("div", { style: tokenListStyle2, children: chainEntries.map((entry) => {
|
|
5415
|
+
const globalIdx = entries.indexOf(entry);
|
|
5416
|
+
const isSelected = selectedIndex === globalIdx;
|
|
5417
|
+
const authorized = entry.status === "AUTHORIZED";
|
|
5418
|
+
return /* @__PURE__ */ jsxs(
|
|
5419
|
+
"button",
|
|
5420
|
+
{
|
|
5421
|
+
type: "button",
|
|
5422
|
+
onClick: () => setSelectedIndex(globalIdx),
|
|
5423
|
+
style: tokenRowStyle2(themeTokens, isSelected),
|
|
5424
|
+
children: [
|
|
5425
|
+
/* @__PURE__ */ jsxs("div", { style: tokenInfoStyle2, children: [
|
|
5426
|
+
/* @__PURE__ */ jsxs("div", { style: tokenHeaderRowStyle, children: [
|
|
5427
|
+
/* @__PURE__ */ jsx("span", { style: tokenSymbolStyle2(themeTokens.text), children: entry.tokenSymbol }),
|
|
5428
|
+
authorized ? /* @__PURE__ */ jsx("span", { style: statusBadgeStyle(themeTokens.success), children: "Authorized" }) : /* @__PURE__ */ jsx("span", { style: statusBadgeStyle(themeTokens.textMuted), children: "Not authorized" })
|
|
5429
|
+
] }),
|
|
5430
|
+
/* @__PURE__ */ jsxs("span", { style: tokenBalStyle2(themeTokens.textMuted), children: [
|
|
5431
|
+
"$",
|
|
5432
|
+
entry.balance.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 })
|
|
5433
|
+
] })
|
|
5434
|
+
] }),
|
|
5435
|
+
/* @__PURE__ */ jsx("div", { style: radioStyle3(themeTokens, isSelected), children: isSelected && /* @__PURE__ */ jsx("div", { style: radioDotStyle3(themeTokens.accent) }) })
|
|
5436
|
+
]
|
|
5437
|
+
},
|
|
5438
|
+
`${entry.walletId}-${entry.tokenSymbol}`
|
|
5439
|
+
);
|
|
5440
|
+
}) })
|
|
5441
|
+
] }, chainName);
|
|
5442
|
+
}) })
|
|
5443
|
+
]
|
|
5444
|
+
}
|
|
5445
|
+
);
|
|
5446
|
+
}
|
|
5447
|
+
var subtitleStyle11 = (color) => ({
|
|
5448
|
+
fontSize: "0.86rem",
|
|
5449
|
+
color,
|
|
5450
|
+
margin: "0 0 20px",
|
|
5451
|
+
lineHeight: 1.5
|
|
5452
|
+
});
|
|
5453
|
+
var chainListStyle2 = {
|
|
5454
|
+
display: "flex",
|
|
5455
|
+
flexDirection: "column",
|
|
5456
|
+
gap: 10
|
|
5457
|
+
};
|
|
5458
|
+
var chainCardStyle2 = (tokens) => ({
|
|
5459
|
+
border: `1px solid ${tokens.border}`,
|
|
5460
|
+
borderRadius: 14,
|
|
5461
|
+
overflow: "hidden",
|
|
5462
|
+
background: tokens.bgInput
|
|
5463
|
+
});
|
|
5464
|
+
var chainHeaderStyle2 = (tokens) => ({
|
|
5465
|
+
display: "flex",
|
|
5466
|
+
alignItems: "center",
|
|
5467
|
+
justifyContent: "space-between",
|
|
5468
|
+
width: "100%",
|
|
5469
|
+
padding: "14px 16px",
|
|
5470
|
+
background: tokens.bgInput,
|
|
5471
|
+
border: "none",
|
|
5472
|
+
cursor: "pointer",
|
|
5473
|
+
fontFamily: "inherit",
|
|
5474
|
+
textAlign: "left"
|
|
5475
|
+
});
|
|
5476
|
+
var chainHeaderLeftStyle2 = {
|
|
5477
|
+
display: "flex",
|
|
5478
|
+
flexDirection: "column",
|
|
5479
|
+
gap: 2
|
|
5480
|
+
};
|
|
5481
|
+
var chainNameStyle2 = (color) => ({
|
|
5482
|
+
fontSize: "0.92rem",
|
|
5483
|
+
fontWeight: 600,
|
|
5484
|
+
color
|
|
5485
|
+
});
|
|
5486
|
+
var chainBalanceStyle2 = (color) => ({
|
|
5487
|
+
fontSize: "0.76rem",
|
|
5488
|
+
color
|
|
5489
|
+
});
|
|
5490
|
+
var chevronStyle2 = (color) => ({
|
|
5491
|
+
fontSize: "0.9rem",
|
|
5492
|
+
color
|
|
5493
|
+
});
|
|
5494
|
+
var tokenListStyle2 = {
|
|
5495
|
+
padding: "0 12px 12px",
|
|
5496
|
+
display: "flex",
|
|
5497
|
+
flexDirection: "column",
|
|
5498
|
+
gap: 6
|
|
5499
|
+
};
|
|
5500
|
+
var tokenRowStyle2 = (tokens, selected) => ({
|
|
5501
|
+
display: "flex",
|
|
5502
|
+
alignItems: "center",
|
|
5503
|
+
justifyContent: "space-between",
|
|
5504
|
+
padding: "12px 14px",
|
|
5505
|
+
background: tokens.bgCard,
|
|
5506
|
+
border: `1.5px solid ${selected ? tokens.accent : tokens.border}`,
|
|
5507
|
+
borderRadius: 10,
|
|
5508
|
+
cursor: "pointer",
|
|
5509
|
+
fontFamily: "inherit",
|
|
5510
|
+
textAlign: "left",
|
|
5511
|
+
transition: "border-color 0.15s ease"
|
|
5512
|
+
});
|
|
5513
|
+
var tokenInfoStyle2 = {
|
|
5514
|
+
display: "flex",
|
|
5515
|
+
flexDirection: "column",
|
|
5516
|
+
gap: 4,
|
|
5517
|
+
flex: 1
|
|
5518
|
+
};
|
|
5519
|
+
var tokenHeaderRowStyle = {
|
|
5520
|
+
display: "flex",
|
|
5521
|
+
alignItems: "center",
|
|
5522
|
+
gap: 8
|
|
5523
|
+
};
|
|
5524
|
+
var tokenSymbolStyle2 = (color) => ({
|
|
5525
|
+
fontSize: "0.88rem",
|
|
5526
|
+
fontWeight: 600,
|
|
5527
|
+
color
|
|
5528
|
+
});
|
|
5529
|
+
var statusBadgeStyle = (color) => ({
|
|
5530
|
+
fontSize: "0.65rem",
|
|
5531
|
+
fontWeight: 600,
|
|
5532
|
+
color,
|
|
5533
|
+
border: `1px solid ${color}44`,
|
|
5534
|
+
borderRadius: 999,
|
|
5535
|
+
padding: "1px 7px",
|
|
5536
|
+
letterSpacing: "0.02em"
|
|
5537
|
+
});
|
|
5538
|
+
var tokenBalStyle2 = (color) => ({
|
|
5539
|
+
fontSize: "0.74rem",
|
|
5540
|
+
color
|
|
5541
|
+
});
|
|
5542
|
+
var radioStyle3 = (tokens, selected) => ({
|
|
5543
|
+
width: 20,
|
|
5544
|
+
height: 20,
|
|
5545
|
+
borderRadius: "50%",
|
|
5546
|
+
border: `2px solid ${selected ? tokens.accent : tokens.border}`,
|
|
5547
|
+
display: "flex",
|
|
5548
|
+
alignItems: "center",
|
|
5549
|
+
justifyContent: "center",
|
|
5550
|
+
flexShrink: 0
|
|
5551
|
+
});
|
|
5552
|
+
var radioDotStyle3 = (color) => ({
|
|
5553
|
+
width: 10,
|
|
5554
|
+
height: 10,
|
|
5555
|
+
borderRadius: "50%",
|
|
5556
|
+
background: color
|
|
5557
|
+
});
|
|
5304
5558
|
function StepRenderer({
|
|
5305
5559
|
state,
|
|
5306
5560
|
ready,
|
|
@@ -5319,6 +5573,7 @@ function StepRenderer({
|
|
|
5319
5573
|
maxSourceBalance,
|
|
5320
5574
|
tokenCount,
|
|
5321
5575
|
selectedAccount,
|
|
5576
|
+
selectedSource,
|
|
5322
5577
|
selectSourceChoices,
|
|
5323
5578
|
selectSourceRecommended,
|
|
5324
5579
|
authInput,
|
|
@@ -5428,7 +5683,7 @@ function StepRenderer({
|
|
|
5428
5683
|
return /* @__PURE__ */ jsx(
|
|
5429
5684
|
SetupScreen,
|
|
5430
5685
|
{
|
|
5431
|
-
availableBalance: selectedAccount ? selectedAccount.wallets.reduce((sum, w) => sum + w.balance.available.amount, 0) : maxSourceBalance,
|
|
5686
|
+
availableBalance: selectedSource ? selectedSource.balance.available.amount : selectedAccount ? selectedAccount.wallets.reduce((sum, w) => sum + w.balance.available.amount, 0) : maxSourceBalance,
|
|
5432
5687
|
tokenCount,
|
|
5433
5688
|
sourceName,
|
|
5434
5689
|
onSetupOneTap: handlers.onSetupOneTap,
|
|
@@ -5464,8 +5719,8 @@ function StepRenderer({
|
|
|
5464
5719
|
sourceName,
|
|
5465
5720
|
sourceAddress,
|
|
5466
5721
|
sourceVerified,
|
|
5467
|
-
availableBalance: selectedAccount ? selectedAccount.wallets.reduce((sum, w) => sum + w.balance.available.amount, 0) : maxSourceBalance,
|
|
5468
|
-
remainingLimit: selectedAccount?.remainingAllowance ?? state.oneTapLimit,
|
|
5722
|
+
availableBalance: selectedSource ? selectedSource.balance.available.amount : selectedAccount ? selectedAccount.wallets.reduce((sum, w) => sum + w.balance.available.amount, 0) : maxSourceBalance,
|
|
5723
|
+
remainingLimit: selectedSource?.remainingAllowance ?? selectedAccount?.remainingAllowance ?? state.oneTapLimit,
|
|
5469
5724
|
tokenCount,
|
|
5470
5725
|
initialAmount: parsedAmt,
|
|
5471
5726
|
processing: state.creatingTransfer,
|
|
@@ -5480,7 +5735,23 @@ function StepRenderer({
|
|
|
5480
5735
|
selectedAccountId: state.selectedAccountId,
|
|
5481
5736
|
onSelectAccount: handlers.onSelectAccount,
|
|
5482
5737
|
onAuthorizeAccount: handlers.onContinueConnection,
|
|
5483
|
-
onAddProvider: () => handlers.onNavigate("wallet-picker")
|
|
5738
|
+
onAddProvider: () => handlers.onNavigate("wallet-picker"),
|
|
5739
|
+
onSelectToken: handlers.onSelectToken
|
|
5740
|
+
}
|
|
5741
|
+
);
|
|
5742
|
+
}
|
|
5743
|
+
if (step === "token-picker") {
|
|
5744
|
+
if (!selectedAccount) {
|
|
5745
|
+
return /* @__PURE__ */ jsx(SwypeLoadingScreen, {});
|
|
5746
|
+
}
|
|
5747
|
+
return /* @__PURE__ */ jsx(
|
|
5748
|
+
TokenPickerScreen,
|
|
5749
|
+
{
|
|
5750
|
+
account: selectedAccount,
|
|
5751
|
+
chains: state.chains,
|
|
5752
|
+
onSelectAuthorized: handlers.onSelectAuthorizedToken,
|
|
5753
|
+
onAuthorizeToken: handlers.onAuthorizeToken,
|
|
5754
|
+
onBack: () => handlers.onNavigate("deposit")
|
|
5484
5755
|
}
|
|
5485
5756
|
);
|
|
5486
5757
|
}
|
|
@@ -5525,7 +5796,7 @@ function StepRenderer({
|
|
|
5525
5796
|
merchantName,
|
|
5526
5797
|
sourceName,
|
|
5527
5798
|
remainingLimit: succeeded ? (() => {
|
|
5528
|
-
const limit = selectedAccount?.remainingAllowance ?? state.oneTapLimit;
|
|
5799
|
+
const limit = selectedSource?.remainingAllowance ?? selectedAccount?.remainingAllowance ?? state.oneTapLimit;
|
|
5529
5800
|
return limit > displayAmount ? limit - displayAmount : 0;
|
|
5530
5801
|
})() : void 0,
|
|
5531
5802
|
onDone: onDismiss ?? handlers.onNewPayment,
|
|
@@ -5543,7 +5814,7 @@ function StepRenderer({
|
|
|
5543
5814
|
sourceAddress,
|
|
5544
5815
|
sourceVerified,
|
|
5545
5816
|
availableBalance: 0,
|
|
5546
|
-
remainingLimit: selectedAccount?.remainingAllowance ?? state.oneTapLimit,
|
|
5817
|
+
remainingLimit: selectedSource?.remainingAllowance ?? selectedAccount?.remainingAllowance ?? state.oneTapLimit,
|
|
5547
5818
|
tokenCount,
|
|
5548
5819
|
initialAmount: depositAmount ?? 5,
|
|
5549
5820
|
processing: false,
|
|
@@ -5679,6 +5950,7 @@ function SwypePaymentInner({
|
|
|
5679
5950
|
const processingStartedAtRef = useRef(null);
|
|
5680
5951
|
const initializedSelectSourceActionRef = useRef(null);
|
|
5681
5952
|
const preSelectSourceStepRef = useRef(null);
|
|
5953
|
+
const pendingTokenAuthRef = useRef(null);
|
|
5682
5954
|
const checkingPasskeyRef = useRef(false);
|
|
5683
5955
|
const onCompleteRef = useRef(onComplete);
|
|
5684
5956
|
onCompleteRef.current = onComplete;
|
|
@@ -5701,6 +5973,15 @@ function SwypePaymentInner({
|
|
|
5701
5973
|
const selectedWallet = selectedAccount?.wallets.find(
|
|
5702
5974
|
(w) => w.id === state.selectedWalletId
|
|
5703
5975
|
);
|
|
5976
|
+
const selectedSource = useMemo(() => {
|
|
5977
|
+
if (!selectedWallet) return null;
|
|
5978
|
+
if (state.selectedTokenSymbol) {
|
|
5979
|
+
return selectedWallet.sources.find(
|
|
5980
|
+
(s) => s.token.symbol === state.selectedTokenSymbol
|
|
5981
|
+
) ?? null;
|
|
5982
|
+
}
|
|
5983
|
+
return selectedWallet.sources.find((s) => s.token.status === "AUTHORIZED") ?? selectedWallet.sources[0] ?? null;
|
|
5984
|
+
}, [selectedWallet, state.selectedTokenSymbol]);
|
|
5704
5985
|
const sourceName = selectedAccount?.name ?? selectedWallet?.chain.name ?? "Wallet";
|
|
5705
5986
|
const sourceAddress = selectedWallet ? `${selectedWallet.name.slice(0, 6)}...${selectedWallet.name.slice(-4)}` : void 0;
|
|
5706
5987
|
const sourceVerified = selectedWallet?.status === "ACTIVE";
|
|
@@ -6106,6 +6387,84 @@ function SwypePaymentInner({
|
|
|
6106
6387
|
reloadAccounts,
|
|
6107
6388
|
onError
|
|
6108
6389
|
]);
|
|
6390
|
+
const handleNavigateToTokenPicker = useCallback(() => {
|
|
6391
|
+
dispatch({ type: "NAVIGATE", step: "token-picker" });
|
|
6392
|
+
}, []);
|
|
6393
|
+
const handleSelectAuthorizedToken = useCallback((walletId, tokenSymbol) => {
|
|
6394
|
+
dispatch({ type: "SELECT_TOKEN", walletId, tokenSymbol });
|
|
6395
|
+
}, []);
|
|
6396
|
+
const handleAuthorizeToken = useCallback(async (_walletId, tokenAddress, chainId, tokenSymbol) => {
|
|
6397
|
+
if (!state.selectedAccountId) {
|
|
6398
|
+
dispatch({ type: "SET_ERROR", error: "No account selected." });
|
|
6399
|
+
return;
|
|
6400
|
+
}
|
|
6401
|
+
if (!state.activeCredentialId) {
|
|
6402
|
+
dispatch({ type: "SET_ERROR", error: "Create a passkey on this device before continuing." });
|
|
6403
|
+
dispatch({ type: "NAVIGATE", step: "create-passkey" });
|
|
6404
|
+
return;
|
|
6405
|
+
}
|
|
6406
|
+
const acct = state.accounts.find((a) => a.id === state.selectedAccountId);
|
|
6407
|
+
const matchedProvider = acct ? state.providers.find((p) => p.name === acct.name) : void 0;
|
|
6408
|
+
if (matchedProvider) {
|
|
6409
|
+
dispatch({ type: "SELECT_PROVIDER", providerId: matchedProvider.id });
|
|
6410
|
+
}
|
|
6411
|
+
dispatch({ type: "SET_ERROR", error: null });
|
|
6412
|
+
dispatch({ type: "SET_INCREASING_LIMIT", value: true });
|
|
6413
|
+
pendingTokenAuthRef.current = { tokenAddress, chainId, tokenSymbol, walletId: _walletId };
|
|
6414
|
+
try {
|
|
6415
|
+
const token = await getAccessToken();
|
|
6416
|
+
if (!token) throw new Error("Not authenticated");
|
|
6417
|
+
const session = await createAccountAuthorizationSession(
|
|
6418
|
+
apiBaseUrl,
|
|
6419
|
+
token,
|
|
6420
|
+
state.selectedAccountId,
|
|
6421
|
+
state.activeCredentialId,
|
|
6422
|
+
{ tokenAddress, chainId }
|
|
6423
|
+
);
|
|
6424
|
+
const isMobile = !shouldUseWalletConnector({
|
|
6425
|
+
useWalletConnector: useWalletConnectorProp,
|
|
6426
|
+
userAgent: typeof navigator === "undefined" ? void 0 : navigator.userAgent
|
|
6427
|
+
});
|
|
6428
|
+
if (isMobile) {
|
|
6429
|
+
handlingMobileReturnRef.current = false;
|
|
6430
|
+
mobileSetupFlowRef.current = true;
|
|
6431
|
+
setupAccountIdRef.current = state.selectedAccountId;
|
|
6432
|
+
persistMobileFlowState({
|
|
6433
|
+
accountId: state.selectedAccountId,
|
|
6434
|
+
sessionId: session.id,
|
|
6435
|
+
deeplinkUri: session.uri,
|
|
6436
|
+
providerId: matchedProvider?.id ?? null,
|
|
6437
|
+
isSetup: true
|
|
6438
|
+
});
|
|
6439
|
+
dispatch({ type: "MOBILE_DEEPLINK_READY", deeplinkUri: session.uri });
|
|
6440
|
+
triggerDeeplink(session.uri);
|
|
6441
|
+
} else {
|
|
6442
|
+
dispatch({ type: "NAVIGATE", step: "setup-status" });
|
|
6443
|
+
await authExecutor.executeSessionById(session.id);
|
|
6444
|
+
await reloadAccounts();
|
|
6445
|
+
dispatch({ type: "SELECT_TOKEN", walletId: _walletId, tokenSymbol });
|
|
6446
|
+
}
|
|
6447
|
+
} catch (err) {
|
|
6448
|
+
captureException(err);
|
|
6449
|
+
const msg = err instanceof Error ? err.message : "Failed to authorize token";
|
|
6450
|
+
dispatch({ type: "SET_ERROR", error: msg });
|
|
6451
|
+
onError?.(msg);
|
|
6452
|
+
} finally {
|
|
6453
|
+
pendingTokenAuthRef.current = null;
|
|
6454
|
+
dispatch({ type: "SET_INCREASING_LIMIT", value: false });
|
|
6455
|
+
}
|
|
6456
|
+
}, [
|
|
6457
|
+
state.selectedAccountId,
|
|
6458
|
+
state.activeCredentialId,
|
|
6459
|
+
state.accounts,
|
|
6460
|
+
state.providers,
|
|
6461
|
+
apiBaseUrl,
|
|
6462
|
+
getAccessToken,
|
|
6463
|
+
authExecutor,
|
|
6464
|
+
useWalletConnectorProp,
|
|
6465
|
+
reloadAccounts,
|
|
6466
|
+
onError
|
|
6467
|
+
]);
|
|
6109
6468
|
const handleConfirmSign = useCallback(async () => {
|
|
6110
6469
|
const t = state.transfer ?? polling.transfer;
|
|
6111
6470
|
if (!t) return;
|
|
@@ -6695,6 +7054,21 @@ function SwypePaymentInner({
|
|
|
6695
7054
|
preSelectSourceStepRef.current = null;
|
|
6696
7055
|
}
|
|
6697
7056
|
}, [pendingSelectSourceAction, state.step]);
|
|
7057
|
+
useEffect(() => {
|
|
7058
|
+
if (!pendingSelectSourceAction || !pendingTokenAuthRef.current) return;
|
|
7059
|
+
const { tokenAddress, chainId } = pendingTokenAuthRef.current;
|
|
7060
|
+
const chainIdHex = `0x${chainId.toString(16)}`;
|
|
7061
|
+
const options = pendingSelectSourceAction.metadata?.options ?? [];
|
|
7062
|
+
const match = options.find(
|
|
7063
|
+
(opt) => opt.tokenAddress.toLowerCase() === tokenAddress.toLowerCase() && opt.chainId.toLowerCase() === chainIdHex.toLowerCase()
|
|
7064
|
+
);
|
|
7065
|
+
if (match) {
|
|
7066
|
+
authExecutor.resolveSelectSource({
|
|
7067
|
+
chainName: match.chainName,
|
|
7068
|
+
tokenSymbol: match.tokenSymbol
|
|
7069
|
+
});
|
|
7070
|
+
}
|
|
7071
|
+
}, [pendingSelectSourceAction, authExecutor]);
|
|
6698
7072
|
const handlers = useMemo(() => ({
|
|
6699
7073
|
onSendLoginCode: handleSendLoginCode,
|
|
6700
7074
|
onVerifyLoginCode: handleVerifyLoginCode,
|
|
@@ -6724,7 +7098,10 @@ function SwypePaymentInner({
|
|
|
6724
7098
|
onSelectSourceChainChange: handleSelectSourceChainChange,
|
|
6725
7099
|
onSetSelectSourceTokenSymbol: setSelectSourceTokenSymbol,
|
|
6726
7100
|
onConfirmSelectSource: handleConfirmSelectSource,
|
|
6727
|
-
onSetupOneTap: handleSetupOneTap
|
|
7101
|
+
onSetupOneTap: handleSetupOneTap,
|
|
7102
|
+
onSelectToken: handleNavigateToTokenPicker,
|
|
7103
|
+
onSelectAuthorizedToken: handleSelectAuthorizedToken,
|
|
7104
|
+
onAuthorizeToken: handleAuthorizeToken
|
|
6728
7105
|
}), [
|
|
6729
7106
|
handleSendLoginCode,
|
|
6730
7107
|
handleVerifyLoginCode,
|
|
@@ -6743,7 +7120,10 @@ function SwypePaymentInner({
|
|
|
6743
7120
|
handleNewPayment,
|
|
6744
7121
|
handleSelectSourceChainChange,
|
|
6745
7122
|
handleConfirmSelectSource,
|
|
6746
|
-
handleSetupOneTap
|
|
7123
|
+
handleSetupOneTap,
|
|
7124
|
+
handleNavigateToTokenPicker,
|
|
7125
|
+
handleSelectAuthorizedToken,
|
|
7126
|
+
handleAuthorizeToken
|
|
6747
7127
|
]);
|
|
6748
7128
|
return /* @__PURE__ */ jsx(
|
|
6749
7129
|
StepRenderer,
|
|
@@ -6765,6 +7145,7 @@ function SwypePaymentInner({
|
|
|
6765
7145
|
maxSourceBalance,
|
|
6766
7146
|
tokenCount,
|
|
6767
7147
|
selectedAccount,
|
|
7148
|
+
selectedSource,
|
|
6768
7149
|
selectSourceChoices,
|
|
6769
7150
|
selectSourceRecommended,
|
|
6770
7151
|
authInput,
|
|
@@ -6781,6 +7162,6 @@ function SwypePaymentInner({
|
|
|
6781
7162
|
);
|
|
6782
7163
|
}
|
|
6783
7164
|
|
|
6784
|
-
export { AdvancedSourceScreen, CreatePasskeyScreen, IconCircle, InfoBanner, OutlineButton, PasskeyIframeBlockedError, PoweredByFooter, PrimaryButton, ScreenHeader, ScreenLayout, SelectSourceScreen, SettingsMenu, SetupScreen, Spinner, StepList, SwypeLoadingScreen, SwypePayment, SwypeProvider, buildPasskeyPopupOptions, createPasskeyCredential, createPasskeyViaPopup, darkTheme, deviceHasPasskey, findDevicePasskey, findDevicePasskeyViaPopup, getTheme, lightTheme, resolvePasskeyRpId, api_exports as swypeApi, useAuthorizationExecutor, useSwypeConfig, useSwypeDepositAmount, useTransferPolling, useTransferSigning };
|
|
7165
|
+
export { AdvancedSourceScreen, CreatePasskeyScreen, IconCircle, InfoBanner, OutlineButton, PasskeyIframeBlockedError, PoweredByFooter, PrimaryButton, ScreenHeader, ScreenLayout, SelectSourceScreen, SettingsMenu, SetupScreen, Spinner, StepList, SwypeLoadingScreen, SwypePayment, SwypeProvider, TokenPickerScreen, buildPasskeyPopupOptions, createPasskeyCredential, createPasskeyViaPopup, darkTheme, deviceHasPasskey, findDevicePasskey, findDevicePasskeyViaPopup, getTheme, lightTheme, resolvePasskeyRpId, api_exports as swypeApi, useAuthorizationExecutor, useSwypeConfig, useSwypeDepositAmount, useTransferPolling, useTransferSigning };
|
|
6785
7166
|
//# sourceMappingURL=index.js.map
|
|
6786
7167
|
//# sourceMappingURL=index.js.map
|