@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.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,19 +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.
|
|
2684
|
-
active ? /* @__PURE__ */ jsxRuntime.jsx("span", { style: activeBadgeStyle(tokens), children: "Active" }) : /* @__PURE__ */ jsxRuntime.jsx("span", { style: inactiveBadgeStyle(tokens), children: "Setup incomplete" }),
|
|
2685
|
-
isSelected && /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2686
|
-
"path",
|
|
2687
|
-
{
|
|
2688
|
-
d: "M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z",
|
|
2689
|
-
fill: tokens.accent
|
|
2690
|
-
}
|
|
2691
|
-
) })
|
|
2692
|
-
] })
|
|
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" }) })
|
|
2693
2708
|
]
|
|
2694
2709
|
},
|
|
2695
2710
|
account.id
|
|
@@ -2877,6 +2892,25 @@ var dropdownDividerStyle = (borderColor) => ({
|
|
|
2877
2892
|
height: 0,
|
|
2878
2893
|
borderTop: `1px solid ${borderColor}`
|
|
2879
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
|
+
});
|
|
2880
2914
|
var addProviderStyle = (tokens) => ({
|
|
2881
2915
|
display: "flex",
|
|
2882
2916
|
alignItems: "center",
|
|
@@ -4009,6 +4043,7 @@ function DepositScreen({
|
|
|
4009
4043
|
verified: sourceVerified,
|
|
4010
4044
|
accounts,
|
|
4011
4045
|
selectedAccountId,
|
|
4046
|
+
depositAmount: amount,
|
|
4012
4047
|
onSelectAccount,
|
|
4013
4048
|
onAuthorizeAccount,
|
|
4014
4049
|
onAddProvider
|
|
@@ -4083,6 +4118,7 @@ function DepositScreen({
|
|
|
4083
4118
|
verified: sourceVerified,
|
|
4084
4119
|
accounts,
|
|
4085
4120
|
selectedAccountId,
|
|
4121
|
+
depositAmount: amount,
|
|
4086
4122
|
onSelectAccount,
|
|
4087
4123
|
onAuthorizeAccount,
|
|
4088
4124
|
onAddProvider
|
|
@@ -5211,7 +5247,7 @@ function StepRenderer({
|
|
|
5211
5247
|
sourceName,
|
|
5212
5248
|
sourceAddress,
|
|
5213
5249
|
sourceVerified,
|
|
5214
|
-
availableBalance: maxSourceBalance,
|
|
5250
|
+
availableBalance: selectedAccount ? selectedAccount.wallets.reduce((sum, w) => sum + w.balance.available.amount, 0) : maxSourceBalance,
|
|
5215
5251
|
remainingLimit: selectedAccount?.remainingAllowance ?? state.oneTapLimit,
|
|
5216
5252
|
tokenCount,
|
|
5217
5253
|
initialAmount: parsedAmt,
|
|
@@ -5782,9 +5818,8 @@ function SwypePaymentInner({
|
|
|
5782
5818
|
merchantAuthorization
|
|
5783
5819
|
]);
|
|
5784
5820
|
const handleIncreaseLimit = react.useCallback(async () => {
|
|
5785
|
-
|
|
5786
|
-
|
|
5787
|
-
dispatch({ type: "SET_ERROR", error: "No account or provider selected." });
|
|
5821
|
+
if (!state.selectedAccountId) {
|
|
5822
|
+
dispatch({ type: "SET_ERROR", error: "No account selected." });
|
|
5788
5823
|
return;
|
|
5789
5824
|
}
|
|
5790
5825
|
if (!state.activeCredentialId) {
|
|
@@ -5797,25 +5832,34 @@ function SwypePaymentInner({
|
|
|
5797
5832
|
try {
|
|
5798
5833
|
const token = await getAccessToken();
|
|
5799
5834
|
if (!token) throw new Error("Not authenticated");
|
|
5800
|
-
|
|
5801
|
-
|
|
5802
|
-
|
|
5803
|
-
|
|
5804
|
-
|
|
5805
|
-
|
|
5806
|
-
|
|
5807
|
-
|
|
5808
|
-
|
|
5809
|
-
}
|
|
5810
|
-
const t = await createTransfer(apiBaseUrl, token, {
|
|
5811
|
-
credentialId: state.activeCredentialId,
|
|
5812
|
-
merchantAuthorization,
|
|
5813
|
-
sourceType: effectiveSourceType,
|
|
5814
|
-
sourceId: effectiveSourceId,
|
|
5815
|
-
destination,
|
|
5816
|
-
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
|
|
5817
5844
|
});
|
|
5818
|
-
|
|
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
|
+
}
|
|
5819
5863
|
} catch (err) {
|
|
5820
5864
|
captureException(err);
|
|
5821
5865
|
const msg = err instanceof Error ? err.message : "Failed to increase limit";
|
|
@@ -5825,17 +5869,14 @@ function SwypePaymentInner({
|
|
|
5825
5869
|
dispatch({ type: "SET_INCREASING_LIMIT", value: false });
|
|
5826
5870
|
}
|
|
5827
5871
|
}, [
|
|
5828
|
-
|
|
5829
|
-
sourceId,
|
|
5830
|
-
sourceType,
|
|
5872
|
+
state.selectedAccountId,
|
|
5831
5873
|
state.activeCredentialId,
|
|
5832
|
-
state.accounts,
|
|
5833
5874
|
apiBaseUrl,
|
|
5834
5875
|
getAccessToken,
|
|
5835
|
-
|
|
5836
|
-
|
|
5837
|
-
|
|
5838
|
-
|
|
5876
|
+
authExecutor,
|
|
5877
|
+
useWalletConnectorProp,
|
|
5878
|
+
reloadAccounts,
|
|
5879
|
+
onError
|
|
5839
5880
|
]);
|
|
5840
5881
|
const handleConfirmSign = react.useCallback(async () => {
|
|
5841
5882
|
const t = state.transfer ?? polling.transfer;
|