@swype-org/react-sdk 0.1.97 → 0.1.100
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 +99 -120
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -4
- package/dist/index.d.ts +10 -4
- package/dist/index.js +100 -121
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -121,7 +121,6 @@ interface Transfer {
|
|
|
121
121
|
amount: Amount;
|
|
122
122
|
createDate: string;
|
|
123
123
|
updateDate: string;
|
|
124
|
-
authorizationSessions: AuthorizationSession[];
|
|
125
124
|
signPayload?: TransferSignPayload | null;
|
|
126
125
|
}
|
|
127
126
|
/** Standard API error shape */
|
|
@@ -143,7 +142,7 @@ interface ActionExecutionResult {
|
|
|
143
142
|
data?: unknown;
|
|
144
143
|
}
|
|
145
144
|
/** Source type discriminator for transfer creation */
|
|
146
|
-
type SourceType = '
|
|
145
|
+
type SourceType = 'accountId' | 'walletId' | 'tokenId';
|
|
147
146
|
/** A chain+token option from the SELECT_SOURCE action metadata. */
|
|
148
147
|
interface SourceOption {
|
|
149
148
|
chainName: string;
|
|
@@ -298,6 +297,12 @@ declare function useSwypeDepositAmount(): {
|
|
|
298
297
|
declare function fetchProviders(apiBaseUrl: string, token: string): Promise<Provider[]>;
|
|
299
298
|
declare function fetchChains(apiBaseUrl: string, token: string): Promise<Chain[]>;
|
|
300
299
|
declare function fetchAccounts(apiBaseUrl: string, token: string, credentialId: string): Promise<Account[]>;
|
|
300
|
+
interface CreateAccountParams {
|
|
301
|
+
name: string;
|
|
302
|
+
credentialId: string;
|
|
303
|
+
providerId: string;
|
|
304
|
+
}
|
|
305
|
+
declare function createAccount(apiBaseUrl: string, token: string, params: CreateAccountParams): Promise<Account>;
|
|
301
306
|
interface CreateTransferParams {
|
|
302
307
|
/** Caller-supplied UUID v4 for idempotency. If omitted, a random UUID is generated. */
|
|
303
308
|
id?: string;
|
|
@@ -353,7 +358,9 @@ declare function updateUserConfigBySession(apiBaseUrl: string, sessionId: string
|
|
|
353
358
|
}): Promise<void>;
|
|
354
359
|
declare function reportActionCompletion(apiBaseUrl: string, actionId: string, result: Record<string, unknown>): Promise<AuthorizationSessionDetail>;
|
|
355
360
|
|
|
361
|
+
type api_CreateAccountParams = CreateAccountParams;
|
|
356
362
|
type api_CreateTransferParams = CreateTransferParams;
|
|
363
|
+
declare const api_createAccount: typeof createAccount;
|
|
357
364
|
declare const api_createTransfer: typeof createTransfer;
|
|
358
365
|
declare const api_fetchAccounts: typeof fetchAccounts;
|
|
359
366
|
declare const api_fetchAuthorizationSession: typeof fetchAuthorizationSession;
|
|
@@ -369,7 +376,7 @@ declare const api_signTransfer: typeof signTransfer;
|
|
|
369
376
|
declare const api_updateUserConfig: typeof updateUserConfig;
|
|
370
377
|
declare const api_updateUserConfigBySession: typeof updateUserConfigBySession;
|
|
371
378
|
declare namespace api {
|
|
372
|
-
export { type api_CreateTransferParams as CreateTransferParams, api_createTransfer as createTransfer, api_fetchAccounts as fetchAccounts, api_fetchAuthorizationSession as fetchAuthorizationSession, api_fetchChains as fetchChains, api_fetchMerchantPublicKey as fetchMerchantPublicKey, api_fetchProviders as fetchProviders, api_fetchTransfer as fetchTransfer, api_fetchUserConfig as fetchUserConfig, api_registerPasskey as registerPasskey, api_reportActionCompletion as reportActionCompletion, api_reportPasskeyActivity as reportPasskeyActivity, api_signTransfer as signTransfer, api_updateUserConfig as updateUserConfig, api_updateUserConfigBySession as updateUserConfigBySession };
|
|
379
|
+
export { type api_CreateAccountParams as CreateAccountParams, type api_CreateTransferParams as CreateTransferParams, api_createAccount as createAccount, api_createTransfer as createTransfer, api_fetchAccounts as fetchAccounts, api_fetchAuthorizationSession as fetchAuthorizationSession, api_fetchChains as fetchChains, api_fetchMerchantPublicKey as fetchMerchantPublicKey, api_fetchProviders as fetchProviders, api_fetchTransfer as fetchTransfer, api_fetchUserConfig as fetchUserConfig, api_registerPasskey as registerPasskey, api_reportActionCompletion as reportActionCompletion, api_reportPasskeyActivity as reportPasskeyActivity, api_signTransfer as signTransfer, api_updateUserConfig as updateUserConfig, api_updateUserConfigBySession as updateUserConfigBySession };
|
|
373
380
|
}
|
|
374
381
|
|
|
375
382
|
interface SwypePaymentProps {
|
|
@@ -554,7 +561,6 @@ interface UseAuthorizationExecutorResult {
|
|
|
554
561
|
resolveSelectSource: (selection: SourceSelection) => void;
|
|
555
562
|
/** Execute authorization by session id. */
|
|
556
563
|
executeSessionById: (sessionId: string) => Promise<void>;
|
|
557
|
-
executeSession: (transfer: Transfer) => Promise<void>;
|
|
558
564
|
}
|
|
559
565
|
interface UseAuthorizationExecutorOptions {
|
|
560
566
|
/** Optional API base URL override when used outside SwypeProvider. */
|
package/dist/index.d.ts
CHANGED
|
@@ -121,7 +121,6 @@ interface Transfer {
|
|
|
121
121
|
amount: Amount;
|
|
122
122
|
createDate: string;
|
|
123
123
|
updateDate: string;
|
|
124
|
-
authorizationSessions: AuthorizationSession[];
|
|
125
124
|
signPayload?: TransferSignPayload | null;
|
|
126
125
|
}
|
|
127
126
|
/** Standard API error shape */
|
|
@@ -143,7 +142,7 @@ interface ActionExecutionResult {
|
|
|
143
142
|
data?: unknown;
|
|
144
143
|
}
|
|
145
144
|
/** Source type discriminator for transfer creation */
|
|
146
|
-
type SourceType = '
|
|
145
|
+
type SourceType = 'accountId' | 'walletId' | 'tokenId';
|
|
147
146
|
/** A chain+token option from the SELECT_SOURCE action metadata. */
|
|
148
147
|
interface SourceOption {
|
|
149
148
|
chainName: string;
|
|
@@ -298,6 +297,12 @@ declare function useSwypeDepositAmount(): {
|
|
|
298
297
|
declare function fetchProviders(apiBaseUrl: string, token: string): Promise<Provider[]>;
|
|
299
298
|
declare function fetchChains(apiBaseUrl: string, token: string): Promise<Chain[]>;
|
|
300
299
|
declare function fetchAccounts(apiBaseUrl: string, token: string, credentialId: string): Promise<Account[]>;
|
|
300
|
+
interface CreateAccountParams {
|
|
301
|
+
name: string;
|
|
302
|
+
credentialId: string;
|
|
303
|
+
providerId: string;
|
|
304
|
+
}
|
|
305
|
+
declare function createAccount(apiBaseUrl: string, token: string, params: CreateAccountParams): Promise<Account>;
|
|
301
306
|
interface CreateTransferParams {
|
|
302
307
|
/** Caller-supplied UUID v4 for idempotency. If omitted, a random UUID is generated. */
|
|
303
308
|
id?: string;
|
|
@@ -353,7 +358,9 @@ declare function updateUserConfigBySession(apiBaseUrl: string, sessionId: string
|
|
|
353
358
|
}): Promise<void>;
|
|
354
359
|
declare function reportActionCompletion(apiBaseUrl: string, actionId: string, result: Record<string, unknown>): Promise<AuthorizationSessionDetail>;
|
|
355
360
|
|
|
361
|
+
type api_CreateAccountParams = CreateAccountParams;
|
|
356
362
|
type api_CreateTransferParams = CreateTransferParams;
|
|
363
|
+
declare const api_createAccount: typeof createAccount;
|
|
357
364
|
declare const api_createTransfer: typeof createTransfer;
|
|
358
365
|
declare const api_fetchAccounts: typeof fetchAccounts;
|
|
359
366
|
declare const api_fetchAuthorizationSession: typeof fetchAuthorizationSession;
|
|
@@ -369,7 +376,7 @@ declare const api_signTransfer: typeof signTransfer;
|
|
|
369
376
|
declare const api_updateUserConfig: typeof updateUserConfig;
|
|
370
377
|
declare const api_updateUserConfigBySession: typeof updateUserConfigBySession;
|
|
371
378
|
declare namespace api {
|
|
372
|
-
export { type api_CreateTransferParams as CreateTransferParams, api_createTransfer as createTransfer, api_fetchAccounts as fetchAccounts, api_fetchAuthorizationSession as fetchAuthorizationSession, api_fetchChains as fetchChains, api_fetchMerchantPublicKey as fetchMerchantPublicKey, api_fetchProviders as fetchProviders, api_fetchTransfer as fetchTransfer, api_fetchUserConfig as fetchUserConfig, api_registerPasskey as registerPasskey, api_reportActionCompletion as reportActionCompletion, api_reportPasskeyActivity as reportPasskeyActivity, api_signTransfer as signTransfer, api_updateUserConfig as updateUserConfig, api_updateUserConfigBySession as updateUserConfigBySession };
|
|
379
|
+
export { type api_CreateAccountParams as CreateAccountParams, type api_CreateTransferParams as CreateTransferParams, api_createAccount as createAccount, api_createTransfer as createTransfer, api_fetchAccounts as fetchAccounts, api_fetchAuthorizationSession as fetchAuthorizationSession, api_fetchChains as fetchChains, api_fetchMerchantPublicKey as fetchMerchantPublicKey, api_fetchProviders as fetchProviders, api_fetchTransfer as fetchTransfer, api_fetchUserConfig as fetchUserConfig, api_registerPasskey as registerPasskey, api_reportActionCompletion as reportActionCompletion, api_reportPasskeyActivity as reportPasskeyActivity, api_signTransfer as signTransfer, api_updateUserConfig as updateUserConfig, api_updateUserConfigBySession as updateUserConfigBySession };
|
|
373
380
|
}
|
|
374
381
|
|
|
375
382
|
interface SwypePaymentProps {
|
|
@@ -554,7 +561,6 @@ interface UseAuthorizationExecutorResult {
|
|
|
554
561
|
resolveSelectSource: (selection: SourceSelection) => void;
|
|
555
562
|
/** Execute authorization by session id. */
|
|
556
563
|
executeSessionById: (sessionId: string) => Promise<void>;
|
|
557
|
-
executeSession: (transfer: Transfer) => Promise<void>;
|
|
558
564
|
}
|
|
559
565
|
interface UseAuthorizationExecutorOptions {
|
|
560
566
|
/** Optional API base URL override when used outside SwypeProvider. */
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createContext, useRef, useState, useCallback, useMemo, useContext, useEffect, useReducer, Component } from 'react';
|
|
2
2
|
import { PrivyProvider, usePrivy, useLoginWithEmail, useLoginWithSms, useLoginWithOAuth } from '@privy-io/react-auth';
|
|
3
3
|
import { createConfig, http, WagmiProvider, useConfig, useConnect, useSwitchChain } from 'wagmi';
|
|
4
|
-
import { mainnet, arbitrum, base } from 'wagmi/chains';
|
|
4
|
+
import { mainnet, arbitrum, base, polygon, bsc } from 'wagmi/chains';
|
|
5
5
|
import { injected } from 'wagmi/connectors';
|
|
6
6
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
7
7
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
@@ -74,12 +74,14 @@ function getTheme(mode) {
|
|
|
74
74
|
}
|
|
75
75
|
var SWYPE_PRIVY_APP_ID = "cmlil87uv004n0ck0blwumwek";
|
|
76
76
|
var wagmiConfig = createConfig({
|
|
77
|
-
chains: [mainnet, arbitrum, base],
|
|
77
|
+
chains: [mainnet, arbitrum, base, polygon, bsc],
|
|
78
78
|
connectors: [injected({ shimDisconnect: true, unstable_shimAsyncInject: 2e3 })],
|
|
79
79
|
transports: {
|
|
80
80
|
[mainnet.id]: http(),
|
|
81
81
|
[arbitrum.id]: http(),
|
|
82
|
-
[base.id]: http()
|
|
82
|
+
[base.id]: http(),
|
|
83
|
+
[polygon.id]: http(),
|
|
84
|
+
[bsc.id]: http()
|
|
83
85
|
}
|
|
84
86
|
});
|
|
85
87
|
var SwypeContext = createContext(null);
|
|
@@ -154,6 +156,7 @@ function useSwypeDepositAmount() {
|
|
|
154
156
|
// src/api.ts
|
|
155
157
|
var api_exports = {};
|
|
156
158
|
__export(api_exports, {
|
|
159
|
+
createAccount: () => createAccount,
|
|
157
160
|
createTransfer: () => createTransfer,
|
|
158
161
|
fetchAccounts: () => fetchAccounts,
|
|
159
162
|
fetchAuthorizationSession: () => fetchAuthorizationSession,
|
|
@@ -201,6 +204,18 @@ async function fetchAccounts(apiBaseUrl, token, credentialId) {
|
|
|
201
204
|
const data = await res.json();
|
|
202
205
|
return data.items;
|
|
203
206
|
}
|
|
207
|
+
async function createAccount(apiBaseUrl, token, params) {
|
|
208
|
+
const res = await fetch(`${apiBaseUrl}/v1/accounts`, {
|
|
209
|
+
method: "POST",
|
|
210
|
+
headers: {
|
|
211
|
+
"Content-Type": "application/json",
|
|
212
|
+
Authorization: `Bearer ${token}`
|
|
213
|
+
},
|
|
214
|
+
body: JSON.stringify(params)
|
|
215
|
+
});
|
|
216
|
+
if (!res.ok) await throwApiError(res);
|
|
217
|
+
return await res.json();
|
|
218
|
+
}
|
|
204
219
|
async function createTransfer(apiBaseUrl, token, params) {
|
|
205
220
|
if (!params.merchantAuthorization) {
|
|
206
221
|
throw new Error("merchantAuthorization is required for transfer creation.");
|
|
@@ -1465,15 +1480,6 @@ function useAuthorizationExecutor(options) {
|
|
|
1465
1480
|
},
|
|
1466
1481
|
[apiBaseUrl, dispatchAction]
|
|
1467
1482
|
);
|
|
1468
|
-
const executeSession = useCallback(
|
|
1469
|
-
async (transfer) => {
|
|
1470
|
-
if (!transfer.authorizationSessions?.length) {
|
|
1471
|
-
throw new Error("No authorization sessions available.");
|
|
1472
|
-
}
|
|
1473
|
-
await executeSessionById(transfer.authorizationSessions[0].id);
|
|
1474
|
-
},
|
|
1475
|
-
[executeSessionById]
|
|
1476
|
-
);
|
|
1477
1483
|
return {
|
|
1478
1484
|
executing,
|
|
1479
1485
|
results,
|
|
@@ -1481,8 +1487,7 @@ function useAuthorizationExecutor(options) {
|
|
|
1481
1487
|
currentAction,
|
|
1482
1488
|
pendingSelectSource,
|
|
1483
1489
|
resolveSelectSource,
|
|
1484
|
-
executeSessionById
|
|
1485
|
-
executeSession
|
|
1490
|
+
executeSessionById
|
|
1486
1491
|
};
|
|
1487
1492
|
}
|
|
1488
1493
|
function useTransferSigning(pollIntervalMs = 2e3, options) {
|
|
@@ -1840,16 +1845,13 @@ function buildSelectSourceChoices(options) {
|
|
|
1840
1845
|
|
|
1841
1846
|
// src/paymentReducer.ts
|
|
1842
1847
|
function deriveSourceTypeAndId(state) {
|
|
1843
|
-
if (state.connectingNewAccount) {
|
|
1844
|
-
return { sourceType: "providerId", sourceId: state.selectedProviderId ?? "" };
|
|
1845
|
-
}
|
|
1846
1848
|
if (state.selectedWalletId) {
|
|
1847
1849
|
return { sourceType: "walletId", sourceId: state.selectedWalletId };
|
|
1848
1850
|
}
|
|
1849
1851
|
if (state.selectedAccountId) {
|
|
1850
1852
|
return { sourceType: "accountId", sourceId: state.selectedAccountId };
|
|
1851
1853
|
}
|
|
1852
|
-
return { sourceType: "
|
|
1854
|
+
return { sourceType: "accountId", sourceId: "" };
|
|
1853
1855
|
}
|
|
1854
1856
|
function createInitialState(config) {
|
|
1855
1857
|
return {
|
|
@@ -1861,8 +1863,6 @@ function createInitialState(config) {
|
|
|
1861
1863
|
loadingData: false,
|
|
1862
1864
|
selectedAccountId: null,
|
|
1863
1865
|
selectedWalletId: null,
|
|
1864
|
-
selectedProviderId: null,
|
|
1865
|
-
connectingNewAccount: false,
|
|
1866
1866
|
amount: config.depositAmount != null ? config.depositAmount.toString() : "",
|
|
1867
1867
|
transfer: null,
|
|
1868
1868
|
creatingTransfer: false,
|
|
@@ -1927,8 +1927,6 @@ function paymentReducer(state, action) {
|
|
|
1927
1927
|
if (action.defaults) {
|
|
1928
1928
|
next.selectedAccountId = action.defaults.accountId;
|
|
1929
1929
|
next.selectedWalletId = action.defaults.walletId;
|
|
1930
|
-
} else if (action.fallbackProviderId && !state.connectingNewAccount) {
|
|
1931
|
-
next.selectedProviderId = action.fallbackProviderId;
|
|
1932
1930
|
}
|
|
1933
1931
|
if (action.clearMobileState) {
|
|
1934
1932
|
next.mobileFlow = false;
|
|
@@ -1950,7 +1948,6 @@ function paymentReducer(state, action) {
|
|
|
1950
1948
|
if (action.defaults) {
|
|
1951
1949
|
next.selectedAccountId = action.defaults.accountId;
|
|
1952
1950
|
next.selectedWalletId = action.defaults.walletId;
|
|
1953
|
-
next.connectingNewAccount = false;
|
|
1954
1951
|
}
|
|
1955
1952
|
return next;
|
|
1956
1953
|
}
|
|
@@ -1958,16 +1955,13 @@ function paymentReducer(state, action) {
|
|
|
1958
1955
|
case "SELECT_PROVIDER":
|
|
1959
1956
|
return {
|
|
1960
1957
|
...state,
|
|
1961
|
-
|
|
1962
|
-
selectedAccountId: null,
|
|
1963
|
-
connectingNewAccount: true
|
|
1958
|
+
selectedAccountId: null
|
|
1964
1959
|
};
|
|
1965
1960
|
case "SELECT_ACCOUNT":
|
|
1966
1961
|
return {
|
|
1967
1962
|
...state,
|
|
1968
1963
|
selectedAccountId: action.accountId,
|
|
1969
1964
|
selectedWalletId: action.walletId,
|
|
1970
|
-
connectingNewAccount: false,
|
|
1971
1965
|
step: "deposit"
|
|
1972
1966
|
};
|
|
1973
1967
|
// ── Transfer lifecycle ───────────────────────────────────────
|
|
@@ -2052,7 +2046,6 @@ function paymentReducer(state, action) {
|
|
|
2052
2046
|
...state,
|
|
2053
2047
|
mobileFlow: true,
|
|
2054
2048
|
deeplinkUri: action.deeplinkUri,
|
|
2055
|
-
selectedProviderId: action.providerId,
|
|
2056
2049
|
error: action.error ?? null,
|
|
2057
2050
|
step: "open-wallet"
|
|
2058
2051
|
};
|
|
@@ -2108,7 +2101,6 @@ function paymentReducer(state, action) {
|
|
|
2108
2101
|
amount: action.depositAmount != null ? action.depositAmount.toString() : "",
|
|
2109
2102
|
mobileFlow: false,
|
|
2110
2103
|
deeplinkUri: null,
|
|
2111
|
-
connectingNewAccount: false,
|
|
2112
2104
|
selectedWalletId: null,
|
|
2113
2105
|
selectedAccountId: action.firstAccountId
|
|
2114
2106
|
};
|
|
@@ -5258,11 +5250,11 @@ function SwypePaymentInner({
|
|
|
5258
5250
|
accounts: state.accounts,
|
|
5259
5251
|
persistedMobileFlow: loadMobileFlowState(),
|
|
5260
5252
|
mobileSetupInProgress: mobileSetupFlowRef.current,
|
|
5261
|
-
connectingNewAccount:
|
|
5253
|
+
connectingNewAccount: false
|
|
5262
5254
|
});
|
|
5263
5255
|
if (resolved.clearPersistedFlow) clearMobileFlowState();
|
|
5264
5256
|
dispatch({ type: "NAVIGATE", step: resolved.step });
|
|
5265
|
-
}, [getAccessToken, apiBaseUrl, state.accounts
|
|
5257
|
+
}, [getAccessToken, apiBaseUrl, state.accounts]);
|
|
5266
5258
|
const handleRegisterPasskey = useCallback(async () => {
|
|
5267
5259
|
dispatch({ type: "SET_REGISTERING_PASSKEY", value: true });
|
|
5268
5260
|
dispatch({ type: "SET_ERROR", error: null });
|
|
@@ -5307,7 +5299,7 @@ function SwypePaymentInner({
|
|
|
5307
5299
|
accounts: state.accounts,
|
|
5308
5300
|
persistedMobileFlow: loadMobileFlowState(),
|
|
5309
5301
|
mobileSetupInProgress: mobileSetupFlowRef.current,
|
|
5310
|
-
connectingNewAccount:
|
|
5302
|
+
connectingNewAccount: false
|
|
5311
5303
|
});
|
|
5312
5304
|
if (resolved.clearPersistedFlow) clearMobileFlowState();
|
|
5313
5305
|
dispatch({ type: "NAVIGATE", step: resolved.step });
|
|
@@ -5320,7 +5312,7 @@ function SwypePaymentInner({
|
|
|
5320
5312
|
} finally {
|
|
5321
5313
|
dispatch({ type: "SET_REGISTERING_PASSKEY", value: false });
|
|
5322
5314
|
}
|
|
5323
|
-
}, [user, getAccessToken, apiBaseUrl, state.accounts
|
|
5315
|
+
}, [user, getAccessToken, apiBaseUrl, state.accounts]);
|
|
5324
5316
|
const handleVerifyPasskeyViaPopup = useCallback(async () => {
|
|
5325
5317
|
dispatch({ type: "SET_VERIFYING_PASSKEY", value: true });
|
|
5326
5318
|
dispatch({ type: "SET_ERROR", error: null });
|
|
@@ -5344,7 +5336,7 @@ function SwypePaymentInner({
|
|
|
5344
5336
|
accounts: state.accounts,
|
|
5345
5337
|
persistedMobileFlow: loadMobileFlowState(),
|
|
5346
5338
|
mobileSetupInProgress: mobileSetupFlowRef.current,
|
|
5347
|
-
connectingNewAccount:
|
|
5339
|
+
connectingNewAccount: false
|
|
5348
5340
|
});
|
|
5349
5341
|
if (resolved.clearPersistedFlow) clearMobileFlowState();
|
|
5350
5342
|
dispatch({ type: "NAVIGATE", step: resolved.step });
|
|
@@ -5363,7 +5355,7 @@ function SwypePaymentInner({
|
|
|
5363
5355
|
} finally {
|
|
5364
5356
|
dispatch({ type: "SET_VERIFYING_PASSKEY", value: false });
|
|
5365
5357
|
}
|
|
5366
|
-
}, [state.knownCredentialIds, getAccessToken, apiBaseUrl, state.accounts
|
|
5358
|
+
}, [state.knownCredentialIds, getAccessToken, apiBaseUrl, state.accounts]);
|
|
5367
5359
|
const reloadAccounts = useCallback(async () => {
|
|
5368
5360
|
const token = await getAccessToken();
|
|
5369
5361
|
if (!token || !state.activeCredentialId) return;
|
|
@@ -5415,8 +5407,7 @@ function SwypePaymentInner({
|
|
|
5415
5407
|
dispatch({ type: "NAVIGATE", step: "create-passkey" });
|
|
5416
5408
|
return;
|
|
5417
5409
|
}
|
|
5418
|
-
|
|
5419
|
-
dispatch({ type: "PAY_STARTED", isSetupRedirect });
|
|
5410
|
+
dispatch({ type: "PAY_STARTED", isSetupRedirect: false });
|
|
5420
5411
|
processingStartedAtRef.current = Date.now();
|
|
5421
5412
|
try {
|
|
5422
5413
|
if (state.transfer?.status === "AUTHORIZED") {
|
|
@@ -5437,23 +5428,6 @@ function SwypePaymentInner({
|
|
|
5437
5428
|
effectiveSourceId = activeWallet.id;
|
|
5438
5429
|
}
|
|
5439
5430
|
}
|
|
5440
|
-
const isActiveWallet = effectiveSourceType === "walletId" && state.accounts.some(
|
|
5441
|
-
(a) => a.wallets.some((w) => w.id === effectiveSourceId && w.status === "ACTIVE")
|
|
5442
|
-
);
|
|
5443
|
-
if (!isActiveWallet && !isSetupRedirect) {
|
|
5444
|
-
let found = false;
|
|
5445
|
-
for (const acct of state.accounts) {
|
|
5446
|
-
for (const wallet of acct.wallets) {
|
|
5447
|
-
if (wallet.status === "ACTIVE" && wallet.sources.some((s) => s.balance.available.amount >= payAmount)) {
|
|
5448
|
-
effectiveSourceType = "walletId";
|
|
5449
|
-
effectiveSourceId = wallet.id;
|
|
5450
|
-
found = true;
|
|
5451
|
-
break;
|
|
5452
|
-
}
|
|
5453
|
-
}
|
|
5454
|
-
if (found) break;
|
|
5455
|
-
}
|
|
5456
|
-
}
|
|
5457
5431
|
const t = await createTransfer(apiBaseUrl, token, {
|
|
5458
5432
|
id: idempotencyKey,
|
|
5459
5433
|
credentialId: state.activeCredentialId,
|
|
@@ -5464,28 +5438,6 @@ function SwypePaymentInner({
|
|
|
5464
5438
|
amount: payAmount
|
|
5465
5439
|
});
|
|
5466
5440
|
dispatch({ type: "TRANSFER_CREATED", transfer: t });
|
|
5467
|
-
if (t.authorizationSessions && t.authorizationSessions.length > 0) {
|
|
5468
|
-
const useConnector = shouldUseWalletConnector({
|
|
5469
|
-
useWalletConnector: useWalletConnectorProp,
|
|
5470
|
-
userAgent: typeof navigator === "undefined" ? void 0 : navigator.userAgent
|
|
5471
|
-
});
|
|
5472
|
-
if (!useConnector) {
|
|
5473
|
-
const uri = t.authorizationSessions[0].uri;
|
|
5474
|
-
pollingTransferIdRef.current = t.id;
|
|
5475
|
-
polling.startPolling(t.id);
|
|
5476
|
-
dispatch({ type: "MOBILE_DEEPLINK_READY", deeplinkUri: uri });
|
|
5477
|
-
persistMobileFlowState({
|
|
5478
|
-
transferId: t.id,
|
|
5479
|
-
deeplinkUri: uri,
|
|
5480
|
-
providerId: sourceOverrides?.sourceType === "providerId" ? sourceOverrides.sourceId : state.selectedProviderId,
|
|
5481
|
-
isSetup: mobileSetupFlowRef.current
|
|
5482
|
-
});
|
|
5483
|
-
triggerDeeplink(uri);
|
|
5484
|
-
return;
|
|
5485
|
-
} else {
|
|
5486
|
-
await authExecutor.executeSession(t);
|
|
5487
|
-
}
|
|
5488
|
-
}
|
|
5489
5441
|
const signedTransfer = await transferSigning.signTransfer(t.id);
|
|
5490
5442
|
dispatch({ type: "TRANSFER_SIGNED", transfer: signedTransfer });
|
|
5491
5443
|
polling.startPolling(t.id);
|
|
@@ -5495,7 +5447,7 @@ function SwypePaymentInner({
|
|
|
5495
5447
|
dispatch({
|
|
5496
5448
|
type: "PAY_ERROR",
|
|
5497
5449
|
error: msg,
|
|
5498
|
-
fallbackStep:
|
|
5450
|
+
fallbackStep: "deposit"
|
|
5499
5451
|
});
|
|
5500
5452
|
onError?.(msg);
|
|
5501
5453
|
} finally {
|
|
@@ -5507,15 +5459,12 @@ function SwypePaymentInner({
|
|
|
5507
5459
|
state.activeCredentialId,
|
|
5508
5460
|
state.transfer,
|
|
5509
5461
|
state.accounts,
|
|
5510
|
-
state.selectedProviderId,
|
|
5511
5462
|
destination,
|
|
5512
5463
|
apiBaseUrl,
|
|
5513
5464
|
getAccessToken,
|
|
5514
|
-
authExecutor,
|
|
5515
5465
|
transferSigning,
|
|
5516
5466
|
polling,
|
|
5517
5467
|
onError,
|
|
5518
|
-
useWalletConnectorProp,
|
|
5519
5468
|
idempotencyKey,
|
|
5520
5469
|
merchantAuthorization
|
|
5521
5470
|
]);
|
|
@@ -5554,23 +5503,7 @@ function SwypePaymentInner({
|
|
|
5554
5503
|
destination,
|
|
5555
5504
|
amount: parsedAmount
|
|
5556
5505
|
});
|
|
5557
|
-
|
|
5558
|
-
const uri = t.authorizationSessions[0].uri;
|
|
5559
|
-
pollingTransferIdRef.current = t.id;
|
|
5560
|
-
mobileSetupFlowRef.current = true;
|
|
5561
|
-
handlingMobileReturnRef.current = false;
|
|
5562
|
-
polling.startPolling(t.id);
|
|
5563
|
-
dispatch({ type: "INCREASE_LIMIT_DEEPLINK", transfer: t, deeplinkUri: uri });
|
|
5564
|
-
persistMobileFlowState({
|
|
5565
|
-
transferId: t.id,
|
|
5566
|
-
deeplinkUri: uri,
|
|
5567
|
-
providerId: state.selectedProviderId,
|
|
5568
|
-
isSetup: true
|
|
5569
|
-
});
|
|
5570
|
-
triggerDeeplink(uri);
|
|
5571
|
-
} else {
|
|
5572
|
-
dispatch({ type: "TRANSFER_CREATED", transfer: t });
|
|
5573
|
-
}
|
|
5506
|
+
dispatch({ type: "TRANSFER_CREATED", transfer: t });
|
|
5574
5507
|
} catch (err) {
|
|
5575
5508
|
captureException(err);
|
|
5576
5509
|
const msg = err instanceof Error ? err.message : "Failed to increase limit";
|
|
@@ -5585,7 +5518,6 @@ function SwypePaymentInner({
|
|
|
5585
5518
|
sourceType,
|
|
5586
5519
|
state.activeCredentialId,
|
|
5587
5520
|
state.accounts,
|
|
5588
|
-
state.selectedProviderId,
|
|
5589
5521
|
apiBaseUrl,
|
|
5590
5522
|
getAccessToken,
|
|
5591
5523
|
polling,
|
|
@@ -5622,21 +5554,65 @@ function SwypePaymentInner({
|
|
|
5622
5554
|
polling.startPolling(transferIdToResume);
|
|
5623
5555
|
}
|
|
5624
5556
|
}, [handleAuthorizedMobileReturn, polling, state.transfer]);
|
|
5625
|
-
const handleSelectProvider = useCallback((providerId) => {
|
|
5557
|
+
const handleSelectProvider = useCallback(async (providerId) => {
|
|
5626
5558
|
dispatch({ type: "SELECT_PROVIDER", providerId });
|
|
5627
|
-
|
|
5628
|
-
|
|
5629
|
-
|
|
5630
|
-
|
|
5631
|
-
|
|
5632
|
-
|
|
5633
|
-
|
|
5634
|
-
|
|
5635
|
-
|
|
5636
|
-
|
|
5637
|
-
|
|
5559
|
+
if (!state.activeCredentialId) {
|
|
5560
|
+
dispatch({ type: "SET_ERROR", error: "Create a passkey on this device before continuing." });
|
|
5561
|
+
dispatch({ type: "NAVIGATE", step: "create-passkey" });
|
|
5562
|
+
return;
|
|
5563
|
+
}
|
|
5564
|
+
const provider = state.providers.find((p) => p.id === providerId);
|
|
5565
|
+
const providerName = provider?.name ?? "Wallet";
|
|
5566
|
+
dispatch({ type: "PAY_STARTED", isSetupRedirect: true });
|
|
5567
|
+
try {
|
|
5568
|
+
const token = await getAccessToken();
|
|
5569
|
+
if (!token) throw new Error("Not authenticated");
|
|
5570
|
+
const account = await createAccount(apiBaseUrl, token, {
|
|
5571
|
+
name: providerName,
|
|
5572
|
+
credentialId: state.activeCredentialId,
|
|
5573
|
+
providerId
|
|
5574
|
+
});
|
|
5575
|
+
const session = account.authorizationSessions?.[0];
|
|
5576
|
+
if (!session) throw new Error("No authorization session returned.");
|
|
5577
|
+
const isMobile = !shouldUseWalletConnector({
|
|
5578
|
+
useWalletConnector: useWalletConnectorProp,
|
|
5579
|
+
userAgent: typeof navigator === "undefined" ? void 0 : navigator.userAgent
|
|
5580
|
+
});
|
|
5581
|
+
if (isMobile) {
|
|
5582
|
+
handlingMobileReturnRef.current = false;
|
|
5583
|
+
mobileSetupFlowRef.current = true;
|
|
5584
|
+
persistMobileFlowState({
|
|
5585
|
+
accountId: account.id,
|
|
5586
|
+
sessionId: session.id,
|
|
5587
|
+
deeplinkUri: session.uri,
|
|
5588
|
+
providerId,
|
|
5589
|
+
isSetup: true
|
|
5590
|
+
});
|
|
5591
|
+
dispatch({ type: "MOBILE_DEEPLINK_READY", deeplinkUri: session.uri });
|
|
5592
|
+
triggerDeeplink(session.uri);
|
|
5593
|
+
} else {
|
|
5594
|
+
await authExecutor.executeSessionById(session.id);
|
|
5595
|
+
await reloadAccounts();
|
|
5596
|
+
dispatch({ type: "NAVIGATE", step: "deposit" });
|
|
5597
|
+
}
|
|
5598
|
+
} catch (err) {
|
|
5599
|
+
captureException(err);
|
|
5600
|
+
const msg = err instanceof Error ? err.message : "Failed to set up wallet";
|
|
5601
|
+
dispatch({ type: "PAY_ERROR", error: msg, fallbackStep: "wallet-picker" });
|
|
5602
|
+
onError?.(msg);
|
|
5603
|
+
} finally {
|
|
5604
|
+
dispatch({ type: "PAY_ENDED" });
|
|
5638
5605
|
}
|
|
5639
|
-
}, [
|
|
5606
|
+
}, [
|
|
5607
|
+
state.activeCredentialId,
|
|
5608
|
+
state.providers,
|
|
5609
|
+
apiBaseUrl,
|
|
5610
|
+
getAccessToken,
|
|
5611
|
+
authExecutor,
|
|
5612
|
+
useWalletConnectorProp,
|
|
5613
|
+
reloadAccounts,
|
|
5614
|
+
onError
|
|
5615
|
+
]);
|
|
5640
5616
|
const handleContinueConnection = useCallback(
|
|
5641
5617
|
(accountId) => {
|
|
5642
5618
|
const acct = state.accounts.find((a) => a.id === accountId);
|
|
@@ -5746,7 +5722,7 @@ function SwypePaymentInner({
|
|
|
5746
5722
|
connectingNewAccount: false
|
|
5747
5723
|
});
|
|
5748
5724
|
if (resolved.clearPersistedFlow) clearMobileFlowState();
|
|
5749
|
-
if (resolved.step === "deposit" && persisted && persisted.isSetup) {
|
|
5725
|
+
if (resolved.step === "deposit" && persisted && persisted.isSetup && persisted.transferId) {
|
|
5750
5726
|
try {
|
|
5751
5727
|
const existingTransfer = await fetchTransfer(apiBaseUrl, token, persisted.transferId);
|
|
5752
5728
|
if (cancelled) return;
|
|
@@ -5757,7 +5733,12 @@ function SwypePaymentInner({
|
|
|
5757
5733
|
} catch {
|
|
5758
5734
|
}
|
|
5759
5735
|
}
|
|
5760
|
-
if (resolved.step === "open-wallet" && persisted) {
|
|
5736
|
+
if (resolved.step === "open-wallet" && persisted && persisted.accountId && !persisted.transferId) {
|
|
5737
|
+
clearMobileFlowState();
|
|
5738
|
+
dispatch({ type: "NAVIGATE", step: "deposit" });
|
|
5739
|
+
return;
|
|
5740
|
+
}
|
|
5741
|
+
if (resolved.step === "open-wallet" && persisted && persisted.transferId) {
|
|
5761
5742
|
try {
|
|
5762
5743
|
const existingTransfer = await fetchTransfer(apiBaseUrl, token, persisted.transferId);
|
|
5763
5744
|
if (cancelled) return;
|
|
@@ -5803,9 +5784,9 @@ function SwypePaymentInner({
|
|
|
5803
5784
|
providerId: persisted.providerId,
|
|
5804
5785
|
error: err instanceof Error ? err.message : "Unable to refresh wallet authorization status."
|
|
5805
5786
|
});
|
|
5806
|
-
pollingTransferIdRef.current = persisted.transferId;
|
|
5787
|
+
pollingTransferIdRef.current = persisted.transferId ?? null;
|
|
5807
5788
|
mobileSetupFlowRef.current = persisted.isSetup;
|
|
5808
|
-
pollingRef.current.startPolling(persisted.transferId);
|
|
5789
|
+
if (persisted.transferId) pollingRef.current.startPolling(persisted.transferId);
|
|
5809
5790
|
return;
|
|
5810
5791
|
}
|
|
5811
5792
|
dispatch({
|
|
@@ -5813,9 +5794,9 @@ function SwypePaymentInner({
|
|
|
5813
5794
|
deeplinkUri: persisted.deeplinkUri,
|
|
5814
5795
|
providerId: persisted.providerId
|
|
5815
5796
|
});
|
|
5816
|
-
pollingTransferIdRef.current = persisted.transferId;
|
|
5797
|
+
pollingTransferIdRef.current = persisted.transferId ?? null;
|
|
5817
5798
|
mobileSetupFlowRef.current = persisted.isSetup;
|
|
5818
|
-
pollingRef.current.startPolling(persisted.transferId);
|
|
5799
|
+
if (persisted.transferId) pollingRef.current.startPolling(persisted.transferId);
|
|
5819
5800
|
return;
|
|
5820
5801
|
}
|
|
5821
5802
|
dispatch({ type: "NAVIGATE", step: resolved.step });
|
|
@@ -5922,7 +5903,7 @@ function SwypePaymentInner({
|
|
|
5922
5903
|
accounts: accts,
|
|
5923
5904
|
persistedMobileFlow: persisted,
|
|
5924
5905
|
mobileSetupInProgress: mobileSetupFlowRef.current,
|
|
5925
|
-
connectingNewAccount:
|
|
5906
|
+
connectingNewAccount: false
|
|
5926
5907
|
});
|
|
5927
5908
|
const correctableSteps = ["deposit", "wallet-picker", "open-wallet"];
|
|
5928
5909
|
dispatch({
|
|
@@ -5931,7 +5912,6 @@ function SwypePaymentInner({
|
|
|
5931
5912
|
accounts: accts,
|
|
5932
5913
|
chains: chn,
|
|
5933
5914
|
defaults,
|
|
5934
|
-
fallbackProviderId: !defaults && prov.length > 0 ? prov[0].id : null,
|
|
5935
5915
|
resolvedStep: correctableSteps.includes(state.step) ? resolved.step : void 0,
|
|
5936
5916
|
clearMobileState: resolved.clearPersistedFlow
|
|
5937
5917
|
});
|
|
@@ -5963,8 +5943,7 @@ function SwypePaymentInner({
|
|
|
5963
5943
|
apiBaseUrl,
|
|
5964
5944
|
getAccessToken,
|
|
5965
5945
|
state.activeCredentialId,
|
|
5966
|
-
depositAmount
|
|
5967
|
-
state.connectingNewAccount
|
|
5946
|
+
depositAmount
|
|
5968
5947
|
]);
|
|
5969
5948
|
useEffect(() => {
|
|
5970
5949
|
if (!polling.transfer) return;
|