@swype-org/react-sdk 0.1.104 → 0.1.106
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 +82 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +82 -41
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -310,6 +310,11 @@ interface CreateAccountParams {
|
|
|
310
310
|
nickname?: string;
|
|
311
311
|
}
|
|
312
312
|
declare function createAccount(apiBaseUrl: string, token: string, params: CreateAccountParams): Promise<Account>;
|
|
313
|
+
declare function createAccountAuthorizationSession(apiBaseUrl: string, token: string, accountId: string, credentialId: string): Promise<{
|
|
314
|
+
id: string;
|
|
315
|
+
status: string;
|
|
316
|
+
uri: string;
|
|
317
|
+
}>;
|
|
313
318
|
interface CreateTransferParams {
|
|
314
319
|
/** Caller-supplied UUID v4 for idempotency. If omitted, a random UUID is generated. */
|
|
315
320
|
id?: string;
|
|
@@ -368,6 +373,7 @@ declare function reportActionCompletion(apiBaseUrl: string, actionId: string, re
|
|
|
368
373
|
type api_CreateAccountParams = CreateAccountParams;
|
|
369
374
|
type api_CreateTransferParams = CreateTransferParams;
|
|
370
375
|
declare const api_createAccount: typeof createAccount;
|
|
376
|
+
declare const api_createAccountAuthorizationSession: typeof createAccountAuthorizationSession;
|
|
371
377
|
declare const api_createTransfer: typeof createTransfer;
|
|
372
378
|
declare const api_fetchAccount: typeof fetchAccount;
|
|
373
379
|
declare const api_fetchAccounts: typeof fetchAccounts;
|
|
@@ -384,7 +390,7 @@ declare const api_signTransfer: typeof signTransfer;
|
|
|
384
390
|
declare const api_updateUserConfig: typeof updateUserConfig;
|
|
385
391
|
declare const api_updateUserConfigBySession: typeof updateUserConfigBySession;
|
|
386
392
|
declare namespace api {
|
|
387
|
-
export { type api_CreateAccountParams as CreateAccountParams, type api_CreateTransferParams as CreateTransferParams, api_createAccount as createAccount, api_createTransfer as createTransfer, api_fetchAccount as fetchAccount, 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 };
|
|
393
|
+
export { type api_CreateAccountParams as CreateAccountParams, type api_CreateTransferParams as CreateTransferParams, api_createAccount as createAccount, api_createAccountAuthorizationSession as createAccountAuthorizationSession, api_createTransfer as createTransfer, api_fetchAccount as fetchAccount, 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 };
|
|
388
394
|
}
|
|
389
395
|
|
|
390
396
|
interface SwypePaymentProps {
|
package/dist/index.d.ts
CHANGED
|
@@ -310,6 +310,11 @@ interface CreateAccountParams {
|
|
|
310
310
|
nickname?: string;
|
|
311
311
|
}
|
|
312
312
|
declare function createAccount(apiBaseUrl: string, token: string, params: CreateAccountParams): Promise<Account>;
|
|
313
|
+
declare function createAccountAuthorizationSession(apiBaseUrl: string, token: string, accountId: string, credentialId: string): Promise<{
|
|
314
|
+
id: string;
|
|
315
|
+
status: string;
|
|
316
|
+
uri: string;
|
|
317
|
+
}>;
|
|
313
318
|
interface CreateTransferParams {
|
|
314
319
|
/** Caller-supplied UUID v4 for idempotency. If omitted, a random UUID is generated. */
|
|
315
320
|
id?: string;
|
|
@@ -368,6 +373,7 @@ declare function reportActionCompletion(apiBaseUrl: string, actionId: string, re
|
|
|
368
373
|
type api_CreateAccountParams = CreateAccountParams;
|
|
369
374
|
type api_CreateTransferParams = CreateTransferParams;
|
|
370
375
|
declare const api_createAccount: typeof createAccount;
|
|
376
|
+
declare const api_createAccountAuthorizationSession: typeof createAccountAuthorizationSession;
|
|
371
377
|
declare const api_createTransfer: typeof createTransfer;
|
|
372
378
|
declare const api_fetchAccount: typeof fetchAccount;
|
|
373
379
|
declare const api_fetchAccounts: typeof fetchAccounts;
|
|
@@ -384,7 +390,7 @@ declare const api_signTransfer: typeof signTransfer;
|
|
|
384
390
|
declare const api_updateUserConfig: typeof updateUserConfig;
|
|
385
391
|
declare const api_updateUserConfigBySession: typeof updateUserConfigBySession;
|
|
386
392
|
declare namespace api {
|
|
387
|
-
export { type api_CreateAccountParams as CreateAccountParams, type api_CreateTransferParams as CreateTransferParams, api_createAccount as createAccount, api_createTransfer as createTransfer, api_fetchAccount as fetchAccount, 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 };
|
|
393
|
+
export { type api_CreateAccountParams as CreateAccountParams, type api_CreateTransferParams as CreateTransferParams, api_createAccount as createAccount, api_createAccountAuthorizationSession as createAccountAuthorizationSession, api_createTransfer as createTransfer, api_fetchAccount as fetchAccount, 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 };
|
|
388
394
|
}
|
|
389
395
|
|
|
390
396
|
interface SwypePaymentProps {
|
package/dist/index.js
CHANGED
|
@@ -157,6 +157,7 @@ function useSwypeDepositAmount() {
|
|
|
157
157
|
var api_exports = {};
|
|
158
158
|
__export(api_exports, {
|
|
159
159
|
createAccount: () => createAccount,
|
|
160
|
+
createAccountAuthorizationSession: () => createAccountAuthorizationSession,
|
|
160
161
|
createTransfer: () => createTransfer,
|
|
161
162
|
fetchAccount: () => fetchAccount,
|
|
162
163
|
fetchAccounts: () => fetchAccounts,
|
|
@@ -234,6 +235,21 @@ async function createAccount(apiBaseUrl, token, params) {
|
|
|
234
235
|
if (!res.ok) await throwApiError(res);
|
|
235
236
|
return await res.json();
|
|
236
237
|
}
|
|
238
|
+
async function createAccountAuthorizationSession(apiBaseUrl, token, accountId, credentialId) {
|
|
239
|
+
const res = await fetch(
|
|
240
|
+
`${apiBaseUrl}/v1/accounts/${accountId}/authorization-sessions`,
|
|
241
|
+
{
|
|
242
|
+
method: "POST",
|
|
243
|
+
headers: {
|
|
244
|
+
"Content-Type": "application/json",
|
|
245
|
+
Authorization: `Bearer ${token}`
|
|
246
|
+
},
|
|
247
|
+
body: JSON.stringify({ credentialId })
|
|
248
|
+
}
|
|
249
|
+
);
|
|
250
|
+
if (!res.ok) await throwApiError(res);
|
|
251
|
+
return await res.json();
|
|
252
|
+
}
|
|
237
253
|
async function createTransfer(apiBaseUrl, token, params) {
|
|
238
254
|
if (!params.merchantAuthorization) {
|
|
239
255
|
throw new Error("merchantAuthorization is required for transfer creation.");
|
|
@@ -2564,6 +2580,7 @@ function SourceCard({
|
|
|
2564
2580
|
verified,
|
|
2565
2581
|
accounts,
|
|
2566
2582
|
selectedAccountId,
|
|
2583
|
+
depositAmount,
|
|
2567
2584
|
onSelectAccount,
|
|
2568
2585
|
onAuthorizeAccount,
|
|
2569
2586
|
onAddProvider
|
|
@@ -2649,6 +2666,8 @@ function SourceCard({
|
|
|
2649
2666
|
const isSelected = account.id === selectedAccountId;
|
|
2650
2667
|
const displayName = account.nickname ?? account.name;
|
|
2651
2668
|
const walletAddress = account.wallets[0]?.name;
|
|
2669
|
+
const hasAllowance = active && account.remainingAllowance != null;
|
|
2670
|
+
const exceedsLimit = hasAllowance && depositAmount != null && depositAmount > account.remainingAllowance;
|
|
2652
2671
|
return /* @__PURE__ */ jsxs(
|
|
2653
2672
|
"button",
|
|
2654
2673
|
{
|
|
@@ -2674,19 +2693,15 @@ function SourceCard({
|
|
|
2674
2693
|
) : /* @__PURE__ */ jsx("div", { style: dropdownFallbackIconStyle(active ? tokens.textMuted : tokens.border), children: account.name.charAt(0) }),
|
|
2675
2694
|
/* @__PURE__ */ jsxs("div", { style: dropdownNameColumnStyle, children: [
|
|
2676
2695
|
/* @__PURE__ */ jsx("span", { style: dropdownNameStyle(active ? tokens.text : tokens.textMuted), children: displayName }),
|
|
2677
|
-
walletAddress && /* @__PURE__ */ jsx("span", { style: dropdownAddressStyle(active ? tokens.textMuted : tokens.border), children: walletAddress })
|
|
2696
|
+
walletAddress && /* @__PURE__ */ jsx("span", { style: dropdownAddressStyle(active ? tokens.textMuted : tokens.border), children: walletAddress }),
|
|
2697
|
+
hasAllowance && /* @__PURE__ */ jsxs("span", { style: remainingAllowanceStyle(exceedsLimit ? tokens.warning : tokens.textMuted), children: [
|
|
2698
|
+
"$",
|
|
2699
|
+
account.remainingAllowance.toFixed(2),
|
|
2700
|
+
" remaining"
|
|
2701
|
+
] })
|
|
2678
2702
|
] })
|
|
2679
2703
|
] }),
|
|
2680
|
-
/* @__PURE__ */
|
|
2681
|
-
active ? /* @__PURE__ */ jsx("span", { style: activeBadgeStyle(tokens), children: "Active" }) : /* @__PURE__ */ jsx("span", { style: inactiveBadgeStyle(tokens), children: "Setup incomplete" }),
|
|
2682
|
-
isSelected && /* @__PURE__ */ jsx("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ jsx(
|
|
2683
|
-
"path",
|
|
2684
|
-
{
|
|
2685
|
-
d: "M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z",
|
|
2686
|
-
fill: tokens.accent
|
|
2687
|
-
}
|
|
2688
|
-
) })
|
|
2689
|
-
] })
|
|
2704
|
+
/* @__PURE__ */ jsx("div", { style: dropdownRowRightStyle, children: active ? exceedsLimit ? /* @__PURE__ */ jsx("span", { style: exceedsLimitBadgeStyle(tokens), children: "Exceeds limit" }) : /* @__PURE__ */ jsx("span", { style: activeBadgeStyle(tokens), children: "Active" }) : /* @__PURE__ */ jsx("span", { style: inactiveBadgeStyle(tokens), children: "Setup incomplete" }) })
|
|
2690
2705
|
]
|
|
2691
2706
|
},
|
|
2692
2707
|
account.id
|
|
@@ -2874,6 +2889,25 @@ var dropdownDividerStyle = (borderColor) => ({
|
|
|
2874
2889
|
height: 0,
|
|
2875
2890
|
borderTop: `1px solid ${borderColor}`
|
|
2876
2891
|
});
|
|
2892
|
+
var remainingAllowanceStyle = (color) => ({
|
|
2893
|
+
fontSize: "0.68rem",
|
|
2894
|
+
color,
|
|
2895
|
+
fontWeight: 500,
|
|
2896
|
+
whiteSpace: "nowrap",
|
|
2897
|
+
overflow: "hidden",
|
|
2898
|
+
textOverflow: "ellipsis"
|
|
2899
|
+
});
|
|
2900
|
+
var exceedsLimitBadgeStyle = (tokens) => ({
|
|
2901
|
+
fontSize: "0.6rem",
|
|
2902
|
+
fontWeight: 600,
|
|
2903
|
+
color: tokens.warning,
|
|
2904
|
+
background: tokens.warningBg ?? `${tokens.warning}1a`,
|
|
2905
|
+
padding: "2px 7px",
|
|
2906
|
+
borderRadius: 999,
|
|
2907
|
+
textTransform: "uppercase",
|
|
2908
|
+
letterSpacing: "0.03em",
|
|
2909
|
+
whiteSpace: "nowrap"
|
|
2910
|
+
});
|
|
2877
2911
|
var addProviderStyle = (tokens) => ({
|
|
2878
2912
|
display: "flex",
|
|
2879
2913
|
alignItems: "center",
|
|
@@ -4006,6 +4040,7 @@ function DepositScreen({
|
|
|
4006
4040
|
verified: sourceVerified,
|
|
4007
4041
|
accounts,
|
|
4008
4042
|
selectedAccountId,
|
|
4043
|
+
depositAmount: amount,
|
|
4009
4044
|
onSelectAccount,
|
|
4010
4045
|
onAuthorizeAccount,
|
|
4011
4046
|
onAddProvider
|
|
@@ -4080,6 +4115,7 @@ function DepositScreen({
|
|
|
4080
4115
|
verified: sourceVerified,
|
|
4081
4116
|
accounts,
|
|
4082
4117
|
selectedAccountId,
|
|
4118
|
+
depositAmount: amount,
|
|
4083
4119
|
onSelectAccount,
|
|
4084
4120
|
onAuthorizeAccount,
|
|
4085
4121
|
onAddProvider
|
|
@@ -5208,7 +5244,7 @@ function StepRenderer({
|
|
|
5208
5244
|
sourceName,
|
|
5209
5245
|
sourceAddress,
|
|
5210
5246
|
sourceVerified,
|
|
5211
|
-
availableBalance: maxSourceBalance,
|
|
5247
|
+
availableBalance: selectedAccount ? selectedAccount.wallets.reduce((sum, w) => sum + w.balance.available.amount, 0) : maxSourceBalance,
|
|
5212
5248
|
remainingLimit: selectedAccount?.remainingAllowance ?? state.oneTapLimit,
|
|
5213
5249
|
tokenCount,
|
|
5214
5250
|
initialAmount: parsedAmt,
|
|
@@ -5779,9 +5815,8 @@ function SwypePaymentInner({
|
|
|
5779
5815
|
merchantAuthorization
|
|
5780
5816
|
]);
|
|
5781
5817
|
const handleIncreaseLimit = useCallback(async () => {
|
|
5782
|
-
|
|
5783
|
-
|
|
5784
|
-
dispatch({ type: "SET_ERROR", error: "No account or provider selected." });
|
|
5818
|
+
if (!state.selectedAccountId) {
|
|
5819
|
+
dispatch({ type: "SET_ERROR", error: "No account selected." });
|
|
5785
5820
|
return;
|
|
5786
5821
|
}
|
|
5787
5822
|
if (!state.activeCredentialId) {
|
|
@@ -5794,25 +5829,34 @@ function SwypePaymentInner({
|
|
|
5794
5829
|
try {
|
|
5795
5830
|
const token = await getAccessToken();
|
|
5796
5831
|
if (!token) throw new Error("Not authenticated");
|
|
5797
|
-
|
|
5798
|
-
|
|
5799
|
-
|
|
5800
|
-
|
|
5801
|
-
|
|
5802
|
-
|
|
5803
|
-
|
|
5804
|
-
|
|
5805
|
-
|
|
5806
|
-
}
|
|
5807
|
-
const t = await createTransfer(apiBaseUrl, token, {
|
|
5808
|
-
credentialId: state.activeCredentialId,
|
|
5809
|
-
merchantAuthorization,
|
|
5810
|
-
sourceType: effectiveSourceType,
|
|
5811
|
-
sourceId: effectiveSourceId,
|
|
5812
|
-
destination,
|
|
5813
|
-
amount: parsedAmount
|
|
5832
|
+
const session = await createAccountAuthorizationSession(
|
|
5833
|
+
apiBaseUrl,
|
|
5834
|
+
token,
|
|
5835
|
+
state.selectedAccountId,
|
|
5836
|
+
state.activeCredentialId
|
|
5837
|
+
);
|
|
5838
|
+
const isMobile = !shouldUseWalletConnector({
|
|
5839
|
+
useWalletConnector: useWalletConnectorProp,
|
|
5840
|
+
userAgent: typeof navigator === "undefined" ? void 0 : navigator.userAgent
|
|
5814
5841
|
});
|
|
5815
|
-
|
|
5842
|
+
if (isMobile) {
|
|
5843
|
+
handlingMobileReturnRef.current = false;
|
|
5844
|
+
mobileSetupFlowRef.current = true;
|
|
5845
|
+
setupAccountIdRef.current = state.selectedAccountId;
|
|
5846
|
+
persistMobileFlowState({
|
|
5847
|
+
accountId: state.selectedAccountId,
|
|
5848
|
+
sessionId: session.id,
|
|
5849
|
+
deeplinkUri: session.uri,
|
|
5850
|
+
providerId: null,
|
|
5851
|
+
isSetup: true
|
|
5852
|
+
});
|
|
5853
|
+
dispatch({ type: "MOBILE_DEEPLINK_READY", deeplinkUri: session.uri });
|
|
5854
|
+
triggerDeeplink(session.uri);
|
|
5855
|
+
} else {
|
|
5856
|
+
await authExecutor.executeSessionById(session.id);
|
|
5857
|
+
await reloadAccounts();
|
|
5858
|
+
dispatch({ type: "NAVIGATE", step: "deposit" });
|
|
5859
|
+
}
|
|
5816
5860
|
} catch (err) {
|
|
5817
5861
|
captureException(err);
|
|
5818
5862
|
const msg = err instanceof Error ? err.message : "Failed to increase limit";
|
|
@@ -5822,17 +5866,14 @@ function SwypePaymentInner({
|
|
|
5822
5866
|
dispatch({ type: "SET_INCREASING_LIMIT", value: false });
|
|
5823
5867
|
}
|
|
5824
5868
|
}, [
|
|
5825
|
-
|
|
5826
|
-
sourceId,
|
|
5827
|
-
sourceType,
|
|
5869
|
+
state.selectedAccountId,
|
|
5828
5870
|
state.activeCredentialId,
|
|
5829
|
-
state.accounts,
|
|
5830
5871
|
apiBaseUrl,
|
|
5831
5872
|
getAccessToken,
|
|
5832
|
-
|
|
5833
|
-
|
|
5834
|
-
|
|
5835
|
-
|
|
5873
|
+
authExecutor,
|
|
5874
|
+
useWalletConnectorProp,
|
|
5875
|
+
reloadAccounts,
|
|
5876
|
+
onError
|
|
5836
5877
|
]);
|
|
5837
5878
|
const handleConfirmSign = useCallback(async () => {
|
|
5838
5879
|
const t = state.transfer ?? polling.transfer;
|