@swype-org/react-sdk 0.1.105 → 0.1.107
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 +88 -31
- 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 +88 -31
- 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,10 +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__ */ jsx("div", { style: dropdownRowRightStyle, children: active ? /* @__PURE__ */ jsx("span", { style: activeBadgeStyle(tokens), children: "Active" }) : /* @__PURE__ */ jsx("span", { style: inactiveBadgeStyle(tokens), children: "Setup incomplete" }) })
|
|
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" }) })
|
|
2681
2705
|
]
|
|
2682
2706
|
},
|
|
2683
2707
|
account.id
|
|
@@ -2865,6 +2889,25 @@ var dropdownDividerStyle = (borderColor) => ({
|
|
|
2865
2889
|
height: 0,
|
|
2866
2890
|
borderTop: `1px solid ${borderColor}`
|
|
2867
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
|
+
});
|
|
2868
2911
|
var addProviderStyle = (tokens) => ({
|
|
2869
2912
|
display: "flex",
|
|
2870
2913
|
alignItems: "center",
|
|
@@ -3997,6 +4040,7 @@ function DepositScreen({
|
|
|
3997
4040
|
verified: sourceVerified,
|
|
3998
4041
|
accounts,
|
|
3999
4042
|
selectedAccountId,
|
|
4043
|
+
depositAmount: amount,
|
|
4000
4044
|
onSelectAccount,
|
|
4001
4045
|
onAuthorizeAccount,
|
|
4002
4046
|
onAddProvider
|
|
@@ -4071,6 +4115,7 @@ function DepositScreen({
|
|
|
4071
4115
|
verified: sourceVerified,
|
|
4072
4116
|
accounts,
|
|
4073
4117
|
selectedAccountId,
|
|
4118
|
+
depositAmount: amount,
|
|
4074
4119
|
onSelectAccount,
|
|
4075
4120
|
onAuthorizeAccount,
|
|
4076
4121
|
onAddProvider
|
|
@@ -5770,9 +5815,8 @@ function SwypePaymentInner({
|
|
|
5770
5815
|
merchantAuthorization
|
|
5771
5816
|
]);
|
|
5772
5817
|
const handleIncreaseLimit = useCallback(async () => {
|
|
5773
|
-
|
|
5774
|
-
|
|
5775
|
-
dispatch({ type: "SET_ERROR", error: "No account or provider selected." });
|
|
5818
|
+
if (!state.selectedAccountId) {
|
|
5819
|
+
dispatch({ type: "SET_ERROR", error: "No account selected." });
|
|
5776
5820
|
return;
|
|
5777
5821
|
}
|
|
5778
5822
|
if (!state.activeCredentialId) {
|
|
@@ -5780,30 +5824,44 @@ function SwypePaymentInner({
|
|
|
5780
5824
|
dispatch({ type: "NAVIGATE", step: "create-passkey" });
|
|
5781
5825
|
return;
|
|
5782
5826
|
}
|
|
5827
|
+
const acct = state.accounts.find((a) => a.id === state.selectedAccountId);
|
|
5828
|
+
const matchedProvider = acct ? state.providers.find((p) => p.name === acct.name) : void 0;
|
|
5829
|
+
if (matchedProvider) {
|
|
5830
|
+
dispatch({ type: "SELECT_PROVIDER", providerId: matchedProvider.id });
|
|
5831
|
+
}
|
|
5783
5832
|
dispatch({ type: "SET_ERROR", error: null });
|
|
5784
5833
|
dispatch({ type: "SET_INCREASING_LIMIT", value: true });
|
|
5785
5834
|
try {
|
|
5786
5835
|
const token = await getAccessToken();
|
|
5787
5836
|
if (!token) throw new Error("Not authenticated");
|
|
5788
|
-
|
|
5789
|
-
|
|
5790
|
-
|
|
5791
|
-
|
|
5792
|
-
|
|
5793
|
-
|
|
5794
|
-
|
|
5795
|
-
|
|
5796
|
-
|
|
5797
|
-
}
|
|
5798
|
-
const t = await createTransfer(apiBaseUrl, token, {
|
|
5799
|
-
credentialId: state.activeCredentialId,
|
|
5800
|
-
merchantAuthorization,
|
|
5801
|
-
sourceType: effectiveSourceType,
|
|
5802
|
-
sourceId: effectiveSourceId,
|
|
5803
|
-
destination,
|
|
5804
|
-
amount: parsedAmount
|
|
5837
|
+
const session = await createAccountAuthorizationSession(
|
|
5838
|
+
apiBaseUrl,
|
|
5839
|
+
token,
|
|
5840
|
+
state.selectedAccountId,
|
|
5841
|
+
state.activeCredentialId
|
|
5842
|
+
);
|
|
5843
|
+
const isMobile = !shouldUseWalletConnector({
|
|
5844
|
+
useWalletConnector: useWalletConnectorProp,
|
|
5845
|
+
userAgent: typeof navigator === "undefined" ? void 0 : navigator.userAgent
|
|
5805
5846
|
});
|
|
5806
|
-
|
|
5847
|
+
if (isMobile) {
|
|
5848
|
+
handlingMobileReturnRef.current = false;
|
|
5849
|
+
mobileSetupFlowRef.current = true;
|
|
5850
|
+
setupAccountIdRef.current = state.selectedAccountId;
|
|
5851
|
+
persistMobileFlowState({
|
|
5852
|
+
accountId: state.selectedAccountId,
|
|
5853
|
+
sessionId: session.id,
|
|
5854
|
+
deeplinkUri: session.uri,
|
|
5855
|
+
providerId: matchedProvider?.id ?? null,
|
|
5856
|
+
isSetup: true
|
|
5857
|
+
});
|
|
5858
|
+
dispatch({ type: "MOBILE_DEEPLINK_READY", deeplinkUri: session.uri });
|
|
5859
|
+
triggerDeeplink(session.uri);
|
|
5860
|
+
} else {
|
|
5861
|
+
await authExecutor.executeSessionById(session.id);
|
|
5862
|
+
await reloadAccounts();
|
|
5863
|
+
dispatch({ type: "NAVIGATE", step: "deposit" });
|
|
5864
|
+
}
|
|
5807
5865
|
} catch (err) {
|
|
5808
5866
|
captureException(err);
|
|
5809
5867
|
const msg = err instanceof Error ? err.message : "Failed to increase limit";
|
|
@@ -5813,17 +5871,16 @@ function SwypePaymentInner({
|
|
|
5813
5871
|
dispatch({ type: "SET_INCREASING_LIMIT", value: false });
|
|
5814
5872
|
}
|
|
5815
5873
|
}, [
|
|
5816
|
-
|
|
5817
|
-
sourceId,
|
|
5818
|
-
sourceType,
|
|
5874
|
+
state.selectedAccountId,
|
|
5819
5875
|
state.activeCredentialId,
|
|
5820
5876
|
state.accounts,
|
|
5877
|
+
state.providers,
|
|
5821
5878
|
apiBaseUrl,
|
|
5822
5879
|
getAccessToken,
|
|
5823
|
-
|
|
5824
|
-
|
|
5825
|
-
|
|
5826
|
-
|
|
5880
|
+
authExecutor,
|
|
5881
|
+
useWalletConnectorProp,
|
|
5882
|
+
reloadAccounts,
|
|
5883
|
+
onError
|
|
5827
5884
|
]);
|
|
5828
5885
|
const handleConfirmSign = useCallback(async () => {
|
|
5829
5886
|
const t = state.transfer ?? polling.transfer;
|
|
@@ -6385,7 +6442,7 @@ function SwypePaymentInner({
|
|
|
6385
6442
|
initializedSelectSourceActionRef.current = pendingSelectSourceAction.id;
|
|
6386
6443
|
}, [pendingSelectSourceAction, selectSourceChoices, selectSourceRecommended]);
|
|
6387
6444
|
useEffect(() => {
|
|
6388
|
-
if (pendingSelectSourceAction && state.step === "processing") {
|
|
6445
|
+
if (pendingSelectSourceAction && (state.step === "processing" || state.step === "open-wallet")) {
|
|
6389
6446
|
preSelectSourceStepRef.current = state.step;
|
|
6390
6447
|
dispatch({ type: "NAVIGATE", step: "select-source" });
|
|
6391
6448
|
} else if (!pendingSelectSourceAction && state.step === "select-source") {
|