@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.cjs
CHANGED
|
@@ -160,6 +160,7 @@ function useSwypeDepositAmount() {
|
|
|
160
160
|
var api_exports = {};
|
|
161
161
|
__export(api_exports, {
|
|
162
162
|
createAccount: () => createAccount,
|
|
163
|
+
createAccountAuthorizationSession: () => createAccountAuthorizationSession,
|
|
163
164
|
createTransfer: () => createTransfer,
|
|
164
165
|
fetchAccount: () => fetchAccount,
|
|
165
166
|
fetchAccounts: () => fetchAccounts,
|
|
@@ -237,6 +238,21 @@ async function createAccount(apiBaseUrl, token, params) {
|
|
|
237
238
|
if (!res.ok) await throwApiError(res);
|
|
238
239
|
return await res.json();
|
|
239
240
|
}
|
|
241
|
+
async function createAccountAuthorizationSession(apiBaseUrl, token, accountId, credentialId) {
|
|
242
|
+
const res = await fetch(
|
|
243
|
+
`${apiBaseUrl}/v1/accounts/${accountId}/authorization-sessions`,
|
|
244
|
+
{
|
|
245
|
+
method: "POST",
|
|
246
|
+
headers: {
|
|
247
|
+
"Content-Type": "application/json",
|
|
248
|
+
Authorization: `Bearer ${token}`
|
|
249
|
+
},
|
|
250
|
+
body: JSON.stringify({ credentialId })
|
|
251
|
+
}
|
|
252
|
+
);
|
|
253
|
+
if (!res.ok) await throwApiError(res);
|
|
254
|
+
return await res.json();
|
|
255
|
+
}
|
|
240
256
|
async function createTransfer(apiBaseUrl, token, params) {
|
|
241
257
|
if (!params.merchantAuthorization) {
|
|
242
258
|
throw new Error("merchantAuthorization is required for transfer creation.");
|
|
@@ -2567,6 +2583,7 @@ function SourceCard({
|
|
|
2567
2583
|
verified,
|
|
2568
2584
|
accounts,
|
|
2569
2585
|
selectedAccountId,
|
|
2586
|
+
depositAmount,
|
|
2570
2587
|
onSelectAccount,
|
|
2571
2588
|
onAuthorizeAccount,
|
|
2572
2589
|
onAddProvider
|
|
@@ -2652,6 +2669,8 @@ function SourceCard({
|
|
|
2652
2669
|
const isSelected = account.id === selectedAccountId;
|
|
2653
2670
|
const displayName = account.nickname ?? account.name;
|
|
2654
2671
|
const walletAddress = account.wallets[0]?.name;
|
|
2672
|
+
const hasAllowance = active && account.remainingAllowance != null;
|
|
2673
|
+
const exceedsLimit = hasAllowance && depositAmount != null && depositAmount > account.remainingAllowance;
|
|
2655
2674
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2656
2675
|
"button",
|
|
2657
2676
|
{
|
|
@@ -2677,10 +2696,15 @@ function SourceCard({
|
|
|
2677
2696
|
) : /* @__PURE__ */ jsxRuntime.jsx("div", { style: dropdownFallbackIconStyle(active ? tokens.textMuted : tokens.border), children: account.name.charAt(0) }),
|
|
2678
2697
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: dropdownNameColumnStyle, children: [
|
|
2679
2698
|
/* @__PURE__ */ jsxRuntime.jsx("span", { style: dropdownNameStyle(active ? tokens.text : tokens.textMuted), children: displayName }),
|
|
2680
|
-
walletAddress && /* @__PURE__ */ jsxRuntime.jsx("span", { style: dropdownAddressStyle(active ? tokens.textMuted : tokens.border), children: walletAddress })
|
|
2699
|
+
walletAddress && /* @__PURE__ */ jsxRuntime.jsx("span", { style: dropdownAddressStyle(active ? tokens.textMuted : tokens.border), children: walletAddress }),
|
|
2700
|
+
hasAllowance && /* @__PURE__ */ jsxRuntime.jsxs("span", { style: remainingAllowanceStyle(exceedsLimit ? tokens.warning : tokens.textMuted), children: [
|
|
2701
|
+
"$",
|
|
2702
|
+
account.remainingAllowance.toFixed(2),
|
|
2703
|
+
" remaining"
|
|
2704
|
+
] })
|
|
2681
2705
|
] })
|
|
2682
2706
|
] }),
|
|
2683
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { style: dropdownRowRightStyle, children: active ? /* @__PURE__ */ jsxRuntime.jsx("span", { style: activeBadgeStyle(tokens), children: "Active" }) : /* @__PURE__ */ jsxRuntime.jsx("span", { style: inactiveBadgeStyle(tokens), children: "Setup incomplete" }) })
|
|
2707
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: dropdownRowRightStyle, children: active ? exceedsLimit ? /* @__PURE__ */ jsxRuntime.jsx("span", { style: exceedsLimitBadgeStyle(tokens), children: "Exceeds limit" }) : /* @__PURE__ */ jsxRuntime.jsx("span", { style: activeBadgeStyle(tokens), children: "Active" }) : /* @__PURE__ */ jsxRuntime.jsx("span", { style: inactiveBadgeStyle(tokens), children: "Setup incomplete" }) })
|
|
2684
2708
|
]
|
|
2685
2709
|
},
|
|
2686
2710
|
account.id
|
|
@@ -2868,6 +2892,25 @@ var dropdownDividerStyle = (borderColor) => ({
|
|
|
2868
2892
|
height: 0,
|
|
2869
2893
|
borderTop: `1px solid ${borderColor}`
|
|
2870
2894
|
});
|
|
2895
|
+
var remainingAllowanceStyle = (color) => ({
|
|
2896
|
+
fontSize: "0.68rem",
|
|
2897
|
+
color,
|
|
2898
|
+
fontWeight: 500,
|
|
2899
|
+
whiteSpace: "nowrap",
|
|
2900
|
+
overflow: "hidden",
|
|
2901
|
+
textOverflow: "ellipsis"
|
|
2902
|
+
});
|
|
2903
|
+
var exceedsLimitBadgeStyle = (tokens) => ({
|
|
2904
|
+
fontSize: "0.6rem",
|
|
2905
|
+
fontWeight: 600,
|
|
2906
|
+
color: tokens.warning,
|
|
2907
|
+
background: tokens.warningBg ?? `${tokens.warning}1a`,
|
|
2908
|
+
padding: "2px 7px",
|
|
2909
|
+
borderRadius: 999,
|
|
2910
|
+
textTransform: "uppercase",
|
|
2911
|
+
letterSpacing: "0.03em",
|
|
2912
|
+
whiteSpace: "nowrap"
|
|
2913
|
+
});
|
|
2871
2914
|
var addProviderStyle = (tokens) => ({
|
|
2872
2915
|
display: "flex",
|
|
2873
2916
|
alignItems: "center",
|
|
@@ -4000,6 +4043,7 @@ function DepositScreen({
|
|
|
4000
4043
|
verified: sourceVerified,
|
|
4001
4044
|
accounts,
|
|
4002
4045
|
selectedAccountId,
|
|
4046
|
+
depositAmount: amount,
|
|
4003
4047
|
onSelectAccount,
|
|
4004
4048
|
onAuthorizeAccount,
|
|
4005
4049
|
onAddProvider
|
|
@@ -4074,6 +4118,7 @@ function DepositScreen({
|
|
|
4074
4118
|
verified: sourceVerified,
|
|
4075
4119
|
accounts,
|
|
4076
4120
|
selectedAccountId,
|
|
4121
|
+
depositAmount: amount,
|
|
4077
4122
|
onSelectAccount,
|
|
4078
4123
|
onAuthorizeAccount,
|
|
4079
4124
|
onAddProvider
|
|
@@ -5773,9 +5818,8 @@ function SwypePaymentInner({
|
|
|
5773
5818
|
merchantAuthorization
|
|
5774
5819
|
]);
|
|
5775
5820
|
const handleIncreaseLimit = react.useCallback(async () => {
|
|
5776
|
-
|
|
5777
|
-
|
|
5778
|
-
dispatch({ type: "SET_ERROR", error: "No account or provider selected." });
|
|
5821
|
+
if (!state.selectedAccountId) {
|
|
5822
|
+
dispatch({ type: "SET_ERROR", error: "No account selected." });
|
|
5779
5823
|
return;
|
|
5780
5824
|
}
|
|
5781
5825
|
if (!state.activeCredentialId) {
|
|
@@ -5783,30 +5827,44 @@ function SwypePaymentInner({
|
|
|
5783
5827
|
dispatch({ type: "NAVIGATE", step: "create-passkey" });
|
|
5784
5828
|
return;
|
|
5785
5829
|
}
|
|
5830
|
+
const acct = state.accounts.find((a) => a.id === state.selectedAccountId);
|
|
5831
|
+
const matchedProvider = acct ? state.providers.find((p) => p.name === acct.name) : void 0;
|
|
5832
|
+
if (matchedProvider) {
|
|
5833
|
+
dispatch({ type: "SELECT_PROVIDER", providerId: matchedProvider.id });
|
|
5834
|
+
}
|
|
5786
5835
|
dispatch({ type: "SET_ERROR", error: null });
|
|
5787
5836
|
dispatch({ type: "SET_INCREASING_LIMIT", value: true });
|
|
5788
5837
|
try {
|
|
5789
5838
|
const token = await getAccessToken();
|
|
5790
5839
|
if (!token) throw new Error("Not authenticated");
|
|
5791
|
-
|
|
5792
|
-
|
|
5793
|
-
|
|
5794
|
-
|
|
5795
|
-
|
|
5796
|
-
|
|
5797
|
-
|
|
5798
|
-
|
|
5799
|
-
|
|
5800
|
-
}
|
|
5801
|
-
const t = await createTransfer(apiBaseUrl, token, {
|
|
5802
|
-
credentialId: state.activeCredentialId,
|
|
5803
|
-
merchantAuthorization,
|
|
5804
|
-
sourceType: effectiveSourceType,
|
|
5805
|
-
sourceId: effectiveSourceId,
|
|
5806
|
-
destination,
|
|
5807
|
-
amount: parsedAmount
|
|
5840
|
+
const session = await createAccountAuthorizationSession(
|
|
5841
|
+
apiBaseUrl,
|
|
5842
|
+
token,
|
|
5843
|
+
state.selectedAccountId,
|
|
5844
|
+
state.activeCredentialId
|
|
5845
|
+
);
|
|
5846
|
+
const isMobile = !shouldUseWalletConnector({
|
|
5847
|
+
useWalletConnector: useWalletConnectorProp,
|
|
5848
|
+
userAgent: typeof navigator === "undefined" ? void 0 : navigator.userAgent
|
|
5808
5849
|
});
|
|
5809
|
-
|
|
5850
|
+
if (isMobile) {
|
|
5851
|
+
handlingMobileReturnRef.current = false;
|
|
5852
|
+
mobileSetupFlowRef.current = true;
|
|
5853
|
+
setupAccountIdRef.current = state.selectedAccountId;
|
|
5854
|
+
persistMobileFlowState({
|
|
5855
|
+
accountId: state.selectedAccountId,
|
|
5856
|
+
sessionId: session.id,
|
|
5857
|
+
deeplinkUri: session.uri,
|
|
5858
|
+
providerId: matchedProvider?.id ?? null,
|
|
5859
|
+
isSetup: true
|
|
5860
|
+
});
|
|
5861
|
+
dispatch({ type: "MOBILE_DEEPLINK_READY", deeplinkUri: session.uri });
|
|
5862
|
+
triggerDeeplink(session.uri);
|
|
5863
|
+
} else {
|
|
5864
|
+
await authExecutor.executeSessionById(session.id);
|
|
5865
|
+
await reloadAccounts();
|
|
5866
|
+
dispatch({ type: "NAVIGATE", step: "deposit" });
|
|
5867
|
+
}
|
|
5810
5868
|
} catch (err) {
|
|
5811
5869
|
captureException(err);
|
|
5812
5870
|
const msg = err instanceof Error ? err.message : "Failed to increase limit";
|
|
@@ -5816,17 +5874,16 @@ function SwypePaymentInner({
|
|
|
5816
5874
|
dispatch({ type: "SET_INCREASING_LIMIT", value: false });
|
|
5817
5875
|
}
|
|
5818
5876
|
}, [
|
|
5819
|
-
|
|
5820
|
-
sourceId,
|
|
5821
|
-
sourceType,
|
|
5877
|
+
state.selectedAccountId,
|
|
5822
5878
|
state.activeCredentialId,
|
|
5823
5879
|
state.accounts,
|
|
5880
|
+
state.providers,
|
|
5824
5881
|
apiBaseUrl,
|
|
5825
5882
|
getAccessToken,
|
|
5826
|
-
|
|
5827
|
-
|
|
5828
|
-
|
|
5829
|
-
|
|
5883
|
+
authExecutor,
|
|
5884
|
+
useWalletConnectorProp,
|
|
5885
|
+
reloadAccounts,
|
|
5886
|
+
onError
|
|
5830
5887
|
]);
|
|
5831
5888
|
const handleConfirmSign = react.useCallback(async () => {
|
|
5832
5889
|
const t = state.transfer ?? polling.transfer;
|
|
@@ -6388,7 +6445,7 @@ function SwypePaymentInner({
|
|
|
6388
6445
|
initializedSelectSourceActionRef.current = pendingSelectSourceAction.id;
|
|
6389
6446
|
}, [pendingSelectSourceAction, selectSourceChoices, selectSourceRecommended]);
|
|
6390
6447
|
react.useEffect(() => {
|
|
6391
|
-
if (pendingSelectSourceAction && state.step === "processing") {
|
|
6448
|
+
if (pendingSelectSourceAction && (state.step === "processing" || state.step === "open-wallet")) {
|
|
6392
6449
|
preSelectSourceStepRef.current = state.step;
|
|
6393
6450
|
dispatch({ type: "NAVIGATE", step: "select-source" });
|
|
6394
6451
|
} else if (!pendingSelectSourceAction && state.step === "select-source") {
|