@swype-org/react-sdk 0.1.105 → 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 +81 -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 +81 -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) {
|
|
@@ -5788,25 +5832,34 @@ function SwypePaymentInner({
|
|
|
5788
5832
|
try {
|
|
5789
5833
|
const token = await getAccessToken();
|
|
5790
5834
|
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
|
|
5835
|
+
const session = await createAccountAuthorizationSession(
|
|
5836
|
+
apiBaseUrl,
|
|
5837
|
+
token,
|
|
5838
|
+
state.selectedAccountId,
|
|
5839
|
+
state.activeCredentialId
|
|
5840
|
+
);
|
|
5841
|
+
const isMobile = !shouldUseWalletConnector({
|
|
5842
|
+
useWalletConnector: useWalletConnectorProp,
|
|
5843
|
+
userAgent: typeof navigator === "undefined" ? void 0 : navigator.userAgent
|
|
5808
5844
|
});
|
|
5809
|
-
|
|
5845
|
+
if (isMobile) {
|
|
5846
|
+
handlingMobileReturnRef.current = false;
|
|
5847
|
+
mobileSetupFlowRef.current = true;
|
|
5848
|
+
setupAccountIdRef.current = state.selectedAccountId;
|
|
5849
|
+
persistMobileFlowState({
|
|
5850
|
+
accountId: state.selectedAccountId,
|
|
5851
|
+
sessionId: session.id,
|
|
5852
|
+
deeplinkUri: session.uri,
|
|
5853
|
+
providerId: null,
|
|
5854
|
+
isSetup: true
|
|
5855
|
+
});
|
|
5856
|
+
dispatch({ type: "MOBILE_DEEPLINK_READY", deeplinkUri: session.uri });
|
|
5857
|
+
triggerDeeplink(session.uri);
|
|
5858
|
+
} else {
|
|
5859
|
+
await authExecutor.executeSessionById(session.id);
|
|
5860
|
+
await reloadAccounts();
|
|
5861
|
+
dispatch({ type: "NAVIGATE", step: "deposit" });
|
|
5862
|
+
}
|
|
5810
5863
|
} catch (err) {
|
|
5811
5864
|
captureException(err);
|
|
5812
5865
|
const msg = err instanceof Error ? err.message : "Failed to increase limit";
|
|
@@ -5816,17 +5869,14 @@ function SwypePaymentInner({
|
|
|
5816
5869
|
dispatch({ type: "SET_INCREASING_LIMIT", value: false });
|
|
5817
5870
|
}
|
|
5818
5871
|
}, [
|
|
5819
|
-
|
|
5820
|
-
sourceId,
|
|
5821
|
-
sourceType,
|
|
5872
|
+
state.selectedAccountId,
|
|
5822
5873
|
state.activeCredentialId,
|
|
5823
|
-
state.accounts,
|
|
5824
5874
|
apiBaseUrl,
|
|
5825
5875
|
getAccessToken,
|
|
5826
|
-
|
|
5827
|
-
|
|
5828
|
-
|
|
5829
|
-
|
|
5876
|
+
authExecutor,
|
|
5877
|
+
useWalletConnectorProp,
|
|
5878
|
+
reloadAccounts,
|
|
5879
|
+
onError
|
|
5830
5880
|
]);
|
|
5831
5881
|
const handleConfirmSign = react.useCallback(async () => {
|
|
5832
5882
|
const t = state.transfer ?? polling.transfer;
|