@swype-org/deposit 0.3.16 → 0.3.19
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/README.md +10 -0
- package/dist/{chunk-WD6DVQHT.js → chunk-VMXCXXVN.js} +202 -23
- package/dist/chunk-VMXCXXVN.js.map +1 -0
- package/dist/index.cjs +200 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +39 -3
- package/dist/index.d.ts +39 -3
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +313 -20
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +34 -3
- package/dist/react.d.ts +34 -3
- package/dist/react.js +119 -4
- package/dist/react.js.map +1 -1
- package/dist/{types-DYsZwNXq.d.cts → types-Ds07N2zN.d.cts} +44 -1
- package/dist/{types-DYsZwNXq.d.ts → types-Ds07N2zN.d.ts} +44 -1
- package/package.json +5 -2
- package/dist/chunk-WD6DVQHT.js.map +0 -1
package/dist/react.d.cts
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
|
-
import { c as DepositConfig, D as DepositStatus, a as DepositResult, b as DepositError, d as DepositRequest } from './types-
|
|
2
|
-
export { k as getDisplayMessage } from './types-
|
|
1
|
+
import { c as DepositConfig, D as DepositStatus, a as DepositResult, b as DepositError, d as DepositRequest } from './types-Ds07N2zN.cjs';
|
|
2
|
+
export { k as getDisplayMessage } from './types-Ds07N2zN.cjs';
|
|
3
|
+
import { ReactElement } from 'react';
|
|
4
|
+
|
|
5
|
+
interface BlinkDepositButtonProps {
|
|
6
|
+
/** Fired when the user taps the button. Hosts typically call `requestDeposit()` here. */
|
|
7
|
+
onClick: () => void;
|
|
8
|
+
/** Disables interaction and dims the button. */
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
/** Non-interactive waiting state (e.g. while the signer request is in flight). Dims like disabled. */
|
|
11
|
+
loading?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Blink-branded deposit button merchants can drop onto their page instead of
|
|
15
|
+
* building their own: a black pill with a bold "Deposit stablecoins" line over
|
|
16
|
+
* an italic "In a Blink" line, and overlapping USDC/USDT coin marks on the
|
|
17
|
+
* right. Self-contained — inline styles and data-URI icons, no CSS imports.
|
|
18
|
+
*
|
|
19
|
+
* ```tsx
|
|
20
|
+
* import { BlinkDepositButton, useBlinkDeposit } from '@swype-org/deposit/react';
|
|
21
|
+
*
|
|
22
|
+
* function Checkout() {
|
|
23
|
+
* const { status, requestDeposit } = useBlinkDeposit({ signer: '/api/sign-payment' });
|
|
24
|
+
* return (
|
|
25
|
+
* <BlinkDepositButton
|
|
26
|
+
* onClick={() => requestDeposit({ amount: 50, chainId: 8453, address: '0x…', token: '0x…' })}
|
|
27
|
+
* loading={status === 'signer-loading'}
|
|
28
|
+
* />
|
|
29
|
+
* );
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
declare function BlinkDepositButton({ onClick, disabled, loading, }: BlinkDepositButtonProps): ReactElement;
|
|
3
34
|
|
|
4
35
|
interface UseBlinkDepositReturn {
|
|
5
36
|
/** Current phase of the deposit flow. */
|
|
@@ -51,4 +82,4 @@ declare const useBlinkCheckout: typeof useBlinkDeposit;
|
|
|
51
82
|
/** @deprecated Use {@link useBlinkDeposit} instead. */
|
|
52
83
|
declare const useSwypeCheckout: typeof useBlinkDeposit;
|
|
53
84
|
|
|
54
|
-
export { DepositConfig, DepositError, DepositRequest, DepositResult, DepositStatus, useBlinkCheckout, useBlinkDeposit, useSwypeCheckout };
|
|
85
|
+
export { BlinkDepositButton, type BlinkDepositButtonProps, DepositConfig, DepositError, DepositRequest, DepositResult, DepositStatus, useBlinkCheckout, useBlinkDeposit, useSwypeCheckout };
|
package/dist/react.d.ts
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
|
-
import { c as DepositConfig, D as DepositStatus, a as DepositResult, b as DepositError, d as DepositRequest } from './types-
|
|
2
|
-
export { k as getDisplayMessage } from './types-
|
|
1
|
+
import { c as DepositConfig, D as DepositStatus, a as DepositResult, b as DepositError, d as DepositRequest } from './types-Ds07N2zN.js';
|
|
2
|
+
export { k as getDisplayMessage } from './types-Ds07N2zN.js';
|
|
3
|
+
import { ReactElement } from 'react';
|
|
4
|
+
|
|
5
|
+
interface BlinkDepositButtonProps {
|
|
6
|
+
/** Fired when the user taps the button. Hosts typically call `requestDeposit()` here. */
|
|
7
|
+
onClick: () => void;
|
|
8
|
+
/** Disables interaction and dims the button. */
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
/** Non-interactive waiting state (e.g. while the signer request is in flight). Dims like disabled. */
|
|
11
|
+
loading?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Blink-branded deposit button merchants can drop onto their page instead of
|
|
15
|
+
* building their own: a black pill with a bold "Deposit stablecoins" line over
|
|
16
|
+
* an italic "In a Blink" line, and overlapping USDC/USDT coin marks on the
|
|
17
|
+
* right. Self-contained — inline styles and data-URI icons, no CSS imports.
|
|
18
|
+
*
|
|
19
|
+
* ```tsx
|
|
20
|
+
* import { BlinkDepositButton, useBlinkDeposit } from '@swype-org/deposit/react';
|
|
21
|
+
*
|
|
22
|
+
* function Checkout() {
|
|
23
|
+
* const { status, requestDeposit } = useBlinkDeposit({ signer: '/api/sign-payment' });
|
|
24
|
+
* return (
|
|
25
|
+
* <BlinkDepositButton
|
|
26
|
+
* onClick={() => requestDeposit({ amount: 50, chainId: 8453, address: '0x…', token: '0x…' })}
|
|
27
|
+
* loading={status === 'signer-loading'}
|
|
28
|
+
* />
|
|
29
|
+
* );
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
declare function BlinkDepositButton({ onClick, disabled, loading, }: BlinkDepositButtonProps): ReactElement;
|
|
3
34
|
|
|
4
35
|
interface UseBlinkDepositReturn {
|
|
5
36
|
/** Current phase of the deposit flow. */
|
|
@@ -51,4 +82,4 @@ declare const useBlinkCheckout: typeof useBlinkDeposit;
|
|
|
51
82
|
/** @deprecated Use {@link useBlinkDeposit} instead. */
|
|
52
83
|
declare const useSwypeCheckout: typeof useBlinkDeposit;
|
|
53
84
|
|
|
54
|
-
export { DepositConfig, DepositError, DepositRequest, DepositResult, DepositStatus, useBlinkCheckout, useBlinkDeposit, useSwypeCheckout };
|
|
85
|
+
export { BlinkDepositButton, type BlinkDepositButtonProps, DepositConfig, DepositError, DepositRequest, DepositResult, DepositStatus, useBlinkCheckout, useBlinkDeposit, useSwypeCheckout };
|
package/dist/react.js
CHANGED
|
@@ -1,7 +1,122 @@
|
|
|
1
|
-
import { Deposit, getDisplayMessage } from './chunk-
|
|
2
|
-
export { DepositError, getDisplayMessage } from './chunk-
|
|
3
|
-
import {
|
|
1
|
+
import { Deposit, getDisplayMessage } from './chunk-VMXCXXVN.js';
|
|
2
|
+
export { DepositError, getDisplayMessage } from './chunk-VMXCXXVN.js';
|
|
3
|
+
import { useState, createElement, useRef, useEffect, useCallback } from 'react';
|
|
4
4
|
|
|
5
|
+
function svgToDataUri(svg) {
|
|
6
|
+
return `data:image/svg+xml,${encodeURIComponent(svg)}`;
|
|
7
|
+
}
|
|
8
|
+
var USDC_SVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2000 2000">
|
|
9
|
+
<path d="M1000 2000c554.17 0 1000-445.83 1000-1000S1554.17 0 1000 0 0 445.83 0 1000s445.83 1000 1000 1000z" fill="#2775ca"/>
|
|
10
|
+
<path d="M1275 1158.33c0-145.83-87.5-195.83-262.5-216.66-125-16.67-150-50-150-108.34s41.67-95.83 125-95.83c75 0 116.67 25 137.5 87.5 4.17 12.5 16.67 20.83 29.17 20.83h66.66c16.67 0 29.17-12.5 29.17-29.16v-4.17c-16.67-91.67-91.67-162.5-187.5-170.83v-100c0-16.67-12.5-29.17-33.33-33.34h-62.5c-16.67 0-29.17 12.5-33.34 33.34v95.83c-125 16.67-204.16 100-204.16 204.17 0 137.5 83.33 191.66 258.33 212.5 116.67 20.83 154.17 45.83 154.17 112.5s-58.34 112.5-137.5 112.5c-108.34 0-145.84-45.84-158.34-108.34-4.16-16.66-16.66-25-29.16-25h-70.84c-16.66 0-29.16 12.5-29.16 29.17v4.17c16.66 104.16 83.33 179.16 220.83 200v100c0 16.66 12.5 29.16 33.33 33.33h62.5c16.67 0 29.17-12.5 33.34-33.33v-100c125-20.84 208.33-108.34 208.33-220.84z" fill="#fff"/>
|
|
11
|
+
<path d="M787.5 1595.83c-325-116.66-491.67-479.16-370.83-800 62.5-175 200-308.33 370.83-370.83 16.67-8.33 25-20.83 25-41.67V325c0-16.67-8.33-29.17-25-33.33-4.17 0-12.5 0-16.67 4.16-395.83 125-612.5 545.84-487.5 941.67 75 233.33 254.17 412.5 487.5 487.5 16.67 8.33 33.34 0 37.5-16.67 4.17-4.16 4.17-8.33 4.17-16.66v-58.34c0-12.5-12.5-29.16-25-37.5zM1229.17 295.83c-16.67-8.33-33.34 0-37.5 16.67-4.17 4.17-4.17 8.33-4.17 16.67v58.33c0 16.67 12.5 33.33 25 41.67 325 116.66 491.67 479.16 370.83 800-62.5 175-200 308.33-370.83 370.83-16.67 8.33-25 20.83-25 41.67V1700c0 16.67 8.33 29.17 25 33.33 4.17 0 12.5 0 16.67-4.16 395.83-125 612.5-545.84 487.5-941.67-75-237.5-258.34-416.67-487.5-491.67z" fill="#fff"/>
|
|
12
|
+
</svg>`;
|
|
13
|
+
var TETHER_SVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 800 800">
|
|
14
|
+
<circle fill="#009393" cx="400" cy="400" r="400"/>
|
|
15
|
+
<path fill="#fff" fill-rule="evenodd" d="M400.49,428.59c68.79,0,126.28-11.63,140.33-27.17-11.93-13.18-55.08-23.56-109.88-26.4v32.83c-9.81.51-20.01.76-30.46.76s-20.65-.25-30.48-.76v-32.83c-54.78,2.84-97.95,13.22-109.88,26.4,14.07,15.54,71.57,27.17,140.36,27.17ZM522.71,274.06v45.21h-91.77v31.35c64.46,3.35,112.83,17.13,113.19,33.62v34.38c-.36,16.49-48.73,30.24-113.19,33.6v76.94h-60.93v-76.94c-64.46-3.35-112.81-17.11-113.17-33.6v-34.38c.36-16.49,48.71-30.27,113.17-33.62v-31.35h-91.77v-45.21h244.48ZM242.15,202.11h322.16c7.7,0,14.79,4.05,18.63,10.63l93.85,161.16c4.86,8.36,3.42,18.91-3.52,25.68l-258.34,252.18c-8.38,8.17-21.84,8.17-30.2,0L126.71,399.92c-7.09-6.94-8.43-17.79-3.2-26.19l100.33-161.49c3.91-6.28,10.85-10.12,18.32-10.12Z"/>
|
|
16
|
+
</svg>`;
|
|
17
|
+
var USDC_LOGO = svgToDataUri(USDC_SVG);
|
|
18
|
+
var TETHER_LOGO = svgToDataUri(TETHER_SVG);
|
|
19
|
+
function BlinkDepositButton({
|
|
20
|
+
onClick,
|
|
21
|
+
disabled,
|
|
22
|
+
loading
|
|
23
|
+
}) {
|
|
24
|
+
const [hovered, setHovered] = useState(false);
|
|
25
|
+
const [pressed, setPressed] = useState(false);
|
|
26
|
+
const inactive = !!disabled || !!loading;
|
|
27
|
+
return createElement(
|
|
28
|
+
"button",
|
|
29
|
+
{
|
|
30
|
+
type: "button",
|
|
31
|
+
onClick,
|
|
32
|
+
disabled: inactive,
|
|
33
|
+
onMouseEnter: () => setHovered(true),
|
|
34
|
+
onMouseLeave: () => {
|
|
35
|
+
setHovered(false);
|
|
36
|
+
setPressed(false);
|
|
37
|
+
},
|
|
38
|
+
onMouseDown: () => setPressed(true),
|
|
39
|
+
onMouseUp: () => setPressed(false),
|
|
40
|
+
style: pillStyle({ hovered, pressed, inactive, loading: !!loading })
|
|
41
|
+
},
|
|
42
|
+
createElement(
|
|
43
|
+
"span",
|
|
44
|
+
{ style: labelStackStyle },
|
|
45
|
+
createElement("span", { style: titleStyle }, "Deposit stablecoins"),
|
|
46
|
+
createElement("span", { style: subtitleStyle }, "In a Blink")
|
|
47
|
+
),
|
|
48
|
+
createElement(
|
|
49
|
+
"span",
|
|
50
|
+
{ style: coinsStyle },
|
|
51
|
+
// The left (USDC) coin paints over the right one, against DOM paint order.
|
|
52
|
+
createElement("img", {
|
|
53
|
+
src: USDC_LOGO,
|
|
54
|
+
alt: "",
|
|
55
|
+
"aria-hidden": "true",
|
|
56
|
+
style: { ...coinStyle, marginRight: -8, position: "relative", zIndex: 1 }
|
|
57
|
+
}),
|
|
58
|
+
createElement("img", { src: TETHER_LOGO, alt: "", "aria-hidden": "true", style: coinStyle })
|
|
59
|
+
)
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
var pillStyle = (state) => ({
|
|
63
|
+
display: "flex",
|
|
64
|
+
alignItems: "center",
|
|
65
|
+
justifyContent: "space-between",
|
|
66
|
+
gap: 8,
|
|
67
|
+
width: "100%",
|
|
68
|
+
height: 56,
|
|
69
|
+
padding: "12px 15px 12px 22px",
|
|
70
|
+
backgroundColor: "#000000",
|
|
71
|
+
// A faint white film on hover rather than `filter: brightness()` — a
|
|
72
|
+
// brightness multiply leaves pure black unchanged.
|
|
73
|
+
backgroundImage: !state.inactive && state.hovered ? "linear-gradient(rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.12))" : void 0,
|
|
74
|
+
color: "#fafafa",
|
|
75
|
+
border: "none",
|
|
76
|
+
borderRadius: 36,
|
|
77
|
+
cursor: state.inactive ? state.loading ? "progress" : "not-allowed" : "pointer",
|
|
78
|
+
opacity: state.inactive ? 0.72 : 1,
|
|
79
|
+
boxSizing: "border-box",
|
|
80
|
+
// Explicit stack so the button is self-sufficient on any host page.
|
|
81
|
+
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
|
|
82
|
+
textAlign: "left",
|
|
83
|
+
transform: !state.inactive && state.pressed ? "scale(0.98)" : void 0,
|
|
84
|
+
transition: "background-color 0.15s ease, transform 0.15s ease, opacity 0.15s ease"
|
|
85
|
+
});
|
|
86
|
+
var labelStackStyle = {
|
|
87
|
+
display: "flex",
|
|
88
|
+
flexDirection: "column",
|
|
89
|
+
minWidth: 0
|
|
90
|
+
};
|
|
91
|
+
var titleStyle = {
|
|
92
|
+
fontSize: 16,
|
|
93
|
+
fontWeight: 700,
|
|
94
|
+
lineHeight: "normal",
|
|
95
|
+
whiteSpace: "nowrap"
|
|
96
|
+
};
|
|
97
|
+
var subtitleStyle = {
|
|
98
|
+
fontSize: 16,
|
|
99
|
+
fontWeight: 400,
|
|
100
|
+
fontStyle: "italic",
|
|
101
|
+
lineHeight: "normal",
|
|
102
|
+
whiteSpace: "nowrap"
|
|
103
|
+
};
|
|
104
|
+
var coinsStyle = {
|
|
105
|
+
display: "inline-flex",
|
|
106
|
+
alignItems: "center",
|
|
107
|
+
flexShrink: 0,
|
|
108
|
+
// Scope the front coin's z-index so it can't escape over host page layers.
|
|
109
|
+
isolation: "isolate"
|
|
110
|
+
};
|
|
111
|
+
var coinStyle = {
|
|
112
|
+
width: 29,
|
|
113
|
+
height: 29,
|
|
114
|
+
borderRadius: "50%",
|
|
115
|
+
objectFit: "cover",
|
|
116
|
+
display: "block"
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// src/react.ts
|
|
5
120
|
function useBlinkDeposit(config) {
|
|
6
121
|
const depositRef = useRef(null);
|
|
7
122
|
const [status, setStatus] = useState("idle");
|
|
@@ -43,6 +158,6 @@ function useBlinkDeposit(config) {
|
|
|
43
158
|
var useBlinkCheckout = useBlinkDeposit;
|
|
44
159
|
var useSwypeCheckout = useBlinkDeposit;
|
|
45
160
|
|
|
46
|
-
export { useBlinkCheckout, useBlinkDeposit, useSwypeCheckout };
|
|
161
|
+
export { BlinkDepositButton, useBlinkCheckout, useBlinkDeposit, useSwypeCheckout };
|
|
47
162
|
//# sourceMappingURL=react.js.map
|
|
48
163
|
//# sourceMappingURL=react.js.map
|
package/dist/react.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/react.ts"],"names":[],"mappings":";;;;AA2DO,SAAS,gBAAgB,MAAA,EAA8C;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CAAA,EAAG,EAAE,CAAA;AAEL,EAAA,MAAM,cAAA,GAAiB,WAAA;AAAA,IACrB,CAAC,OAAA,KAA4B,UAAA,CAAW,OAAA,CAAS,eAAe,OAAO,CAAA;AAAA,IACvE;AAAC,GACH;AAEA,EAAA,MAAM,KAAA,GAAQ,YAAY,MAAM;AAAA,EAAC,CAAA,EAAG,EAAE,CAAA;AACtC,EAAA,MAAM,KAAA,GAAQ,YAAY,MAAM,UAAA,CAAW,SAAS,KAAA,EAAM,EAAG,EAAE,CAAA;AAE/D,EAAA,MAAM,cAAA,GAAiB,KAAA,GAAQ,iBAAA,CAAkB,KAAK,CAAA,GAAI,IAAA;AAC1D,EAAA,MAAM,QAAA,GAAW,MAAA,KAAW,gBAAA,IAAoB,MAAA,KAAW,eAAA;AAE3D,EAAA,OAAO,EAAE,QAAQ,MAAA,EAAQ,KAAA,EAAO,gBAAgB,QAAA,EAAU,cAAA,EAAgB,OAAO,KAAA,EAAM;AACzF;AAGO,IAAM,gBAAA,GAAmB;AAGzB,IAAM,gBAAA,GAAmB","file":"react.js","sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\n\nimport { Deposit } from './checkout.ts';\nimport { DepositError, getDisplayMessage } from './errors.ts';\nimport type {\n DepositConfig,\n DepositStatus,\n DepositRequest,\n DepositResult,\n} from './types.ts';\n\nexport type { DepositConfig, DepositStatus, DepositRequest, DepositResult };\nexport { DepositError, getDisplayMessage };\n\ninterface UseBlinkDepositReturn {\n /** Current phase of the deposit flow. */\n status: DepositStatus;\n /** Last successful deposit result, or `null`. */\n result: DepositResult | null;\n /** Last deposit error, or `null`. */\n error: DepositError | null;\n /** User-friendly error message derived from the current error, or `null`. */\n displayMessage: string | null;\n /** Whether a deposit flow is currently in progress. */\n isActive: boolean;\n /** Start a deposit flow. Opens a modal iframe with the hosted deposit. */\n requestDeposit: (request: DepositRequest) => Promise<DepositResult>;\n /** No-op — retained for API compatibility. */\n focus: () => void;\n /** Close the deposit iframe and reset to idle. */\n close: () => void;\n}\n\n/**\n * React hook that wraps the {@link Deposit} class with reactive state.\n *\n * ```tsx\n * import { useBlinkDeposit } from '@swype-org/deposit/react';\n *\n * function DepositButton() {\n * const { status, result, error, displayMessage, requestDeposit } = useBlinkDeposit({\n * signer: '/api/sign-payment',\n * });\n *\n * return (\n * <>\n * <button\n * onClick={() => requestDeposit({ amount: 50, chainId: 8453, address: '0x...', token: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913' })}\n * disabled={status === 'signer-loading'}\n * >\n * {status === 'signer-loading' ? 'Preparing…' : 'Deposit'}\n * </button>\n * {error && <p>{displayMessage}</p>}\n * {result && <p>Transfer {result.transfer.id} complete!</p>}\n * </>\n * );\n * }\n * ```\n */\nexport function useBlinkDeposit(config: DepositConfig): UseBlinkDepositReturn {\n const depositRef = useRef<Deposit | null>(null);\n const [status, setStatus] = useState<DepositStatus>('idle');\n const [result, setResult] = useState<DepositResult | null>(null);\n const [error, setError] = useState<DepositError | null>(null);\n\n if (!depositRef.current) {\n depositRef.current = new Deposit(config);\n }\n\n useEffect(() => {\n const deposit = depositRef.current!;\n\n const onStatusChange = (s: DepositStatus) => setStatus(s);\n const onComplete = (r: DepositResult) => {\n setResult(r);\n setError(null);\n };\n const onError = (e: DepositError) => setError(e);\n\n deposit.on('status-change', onStatusChange);\n deposit.on('complete', onComplete);\n deposit.on('error', onError);\n\n return () => {\n deposit.off('status-change', onStatusChange);\n deposit.off('complete', onComplete);\n deposit.off('error', onError);\n deposit.destroy();\n depositRef.current = null;\n };\n }, []);\n\n const requestDeposit = useCallback(\n (request: DepositRequest) => depositRef.current!.requestDeposit(request),\n [],\n );\n\n const focus = useCallback(() => {}, []);\n const close = useCallback(() => depositRef.current?.close(), []);\n\n const displayMessage = error ? getDisplayMessage(error) : null;\n const isActive = status === 'signer-loading' || status === 'iframe-active';\n\n return { status, result, error, displayMessage, isActive, requestDeposit, focus, close };\n}\n\n/** @deprecated Use {@link useBlinkDeposit} instead. */\nexport const useBlinkCheckout = useBlinkDeposit;\n\n/** @deprecated Use {@link useBlinkDeposit} instead. */\nexport const useSwypeCheckout = useBlinkDeposit;\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/BlinkDepositButton.ts","../src/react.ts"],"names":["useState"],"mappings":";;;;AAKA,SAAS,aAAa,GAAA,EAAqB;AACzC,EAAA,OAAO,CAAA,mBAAA,EAAsB,kBAAA,CAAmB,GAAG,CAAC,CAAA,CAAA;AACtD;AAEA,IAAM,QAAA,GAAW,CAAA;AAAA;AAAA;AAAA;AAAA,MAAA,CAAA;AAMjB,IAAM,UAAA,GAAa,CAAA;AAAA;AAAA;AAAA,MAAA,CAAA;AAKnB,IAAM,SAAA,GAAY,aAAa,QAAQ,CAAA;AACvC,IAAM,WAAA,GAAc,aAAa,UAAU,CAAA;AA+BpC,SAAS,kBAAA,CAAmB;AAAA,EACjC,OAAA;AAAA,EACA,QAAA;AAAA,EACA;AACF,CAAA,EAA0C;AACxC,EAAA,MAAM,CAAC,OAAA,EAAS,UAAU,CAAA,GAAI,SAAS,KAAK,CAAA;AAC5C,EAAA,MAAM,CAAC,OAAA,EAAS,UAAU,CAAA,GAAI,SAAS,KAAK,CAAA;AAC5C,EAAA,MAAM,QAAA,GAAW,CAAC,CAAC,QAAA,IAAY,CAAC,CAAC,OAAA;AAEjC,EAAA,OAAO,aAAA;AAAA,IACL,QAAA;AAAA,IACA;AAAA,MACE,IAAA,EAAM,QAAA;AAAA,MACN,OAAA;AAAA,MACA,QAAA,EAAU,QAAA;AAAA,MACV,YAAA,EAAc,MAAM,UAAA,CAAW,IAAI,CAAA;AAAA,MACnC,cAAc,MAAM;AAClB,QAAA,UAAA,CAAW,KAAK,CAAA;AAChB,QAAA,UAAA,CAAW,KAAK,CAAA;AAAA,MAClB,CAAA;AAAA,MACA,WAAA,EAAa,MAAM,UAAA,CAAW,IAAI,CAAA;AAAA,MAClC,SAAA,EAAW,MAAM,UAAA,CAAW,KAAK,CAAA;AAAA,MACjC,KAAA,EA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AA;AAAA,EACF,CAAA,EAAG,EAAE,CAAA;AAEL,EAAA,MAAM,cAAA,GAAiB,WAAA;AAAA,IACrB,CAAC,OAAA,KAA4B,UAAA,CAAW,OAAA,CAAS,eAAe,OAAO,CAAA;AAAA,IACvE;AAAC,GACH;AAEA,EAAA,MAAM,KAAA,GAAQ,YAAY,MAAM;AAAA,EAAC,CAAA,EAAG,EAAE,CAAA;AACtC,EAAA,MAAM,KAAA,GAAQ,YAAY,MAAM,UAAA,CAAW,SAAS,KAAA,EAAM,EAAG,EAAE,CAAA;AAE/D,EAAA,MAAM,cAAA,GAAiB,KAAA,GAAQ,iBAAA,CAAkB,KAAK,CAAA,GAAI,IAAA;AAC1D,EAAA,MAAM,QAAA,GAAW,MAAA,KAAW,gBAAA,IAAoB,MAAA,KAAW,eAAA;AAE3D,EAAA,OAAO,EAAE,QAAQ,MAAA,EAAQ,KAAA,EAAO,gBAAgB,QAAA,EAAU,cAAA,EAAgB,OAAO,KAAA,EAAM;AACzF;AAGO,IAAM,gBAAA,GAAmB;AAGzB,IAAM,gBAAA,GAAmB","file":"react.js","sourcesContent":["import { createElement, useState } from 'react';\nimport type { CSSProperties, ReactElement } from 'react';\n\n// Inline data URIs (no asset pipeline) so the button stays dependency-free on\n// merchant pages. Marks mirror swype-sdk/src/assets/logos.ts.\nfunction svgToDataUri(svg: string): string {\n return `data:image/svg+xml,${encodeURIComponent(svg)}`;\n}\n\nconst USDC_SVG = `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 2000 2000\">\n<path d=\"M1000 2000c554.17 0 1000-445.83 1000-1000S1554.17 0 1000 0 0 445.83 0 1000s445.83 1000 1000 1000z\" fill=\"#2775ca\"/>\n<path d=\"M1275 1158.33c0-145.83-87.5-195.83-262.5-216.66-125-16.67-150-50-150-108.34s41.67-95.83 125-95.83c75 0 116.67 25 137.5 87.5 4.17 12.5 16.67 20.83 29.17 20.83h66.66c16.67 0 29.17-12.5 29.17-29.16v-4.17c-16.67-91.67-91.67-162.5-187.5-170.83v-100c0-16.67-12.5-29.17-33.33-33.34h-62.5c-16.67 0-29.17 12.5-33.34 33.34v95.83c-125 16.67-204.16 100-204.16 204.17 0 137.5 83.33 191.66 258.33 212.5 116.67 20.83 154.17 45.83 154.17 112.5s-58.34 112.5-137.5 112.5c-108.34 0-145.84-45.84-158.34-108.34-4.16-16.66-16.66-25-29.16-25h-70.84c-16.66 0-29.16 12.5-29.16 29.17v4.17c16.66 104.16 83.33 179.16 220.83 200v100c0 16.66 12.5 29.16 33.33 33.33h62.5c16.67 0 29.17-12.5 33.34-33.33v-100c125-20.84 208.33-108.34 208.33-220.84z\" fill=\"#fff\"/>\n<path d=\"M787.5 1595.83c-325-116.66-491.67-479.16-370.83-800 62.5-175 200-308.33 370.83-370.83 16.67-8.33 25-20.83 25-41.67V325c0-16.67-8.33-29.17-25-33.33-4.17 0-12.5 0-16.67 4.16-395.83 125-612.5 545.84-487.5 941.67 75 233.33 254.17 412.5 487.5 487.5 16.67 8.33 33.34 0 37.5-16.67 4.17-4.16 4.17-8.33 4.17-16.66v-58.34c0-12.5-12.5-29.16-25-37.5zM1229.17 295.83c-16.67-8.33-33.34 0-37.5 16.67-4.17 4.17-4.17 8.33-4.17 16.67v58.33c0 16.67 12.5 33.33 25 41.67 325 116.66 491.67 479.16 370.83 800-62.5 175-200 308.33-370.83 370.83-16.67 8.33-25 20.83-25 41.67V1700c0 16.67 8.33 29.17 25 33.33 4.17 0 12.5 0 16.67-4.16 395.83-125 612.5-545.84 487.5-941.67-75-237.5-258.34-416.67-487.5-491.67z\" fill=\"#fff\"/>\n</svg>`;\n\nconst TETHER_SVG = `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 800 800\">\n<circle fill=\"#009393\" cx=\"400\" cy=\"400\" r=\"400\"/>\n<path fill=\"#fff\" fill-rule=\"evenodd\" d=\"M400.49,428.59c68.79,0,126.28-11.63,140.33-27.17-11.93-13.18-55.08-23.56-109.88-26.4v32.83c-9.81.51-20.01.76-30.46.76s-20.65-.25-30.48-.76v-32.83c-54.78,2.84-97.95,13.22-109.88,26.4,14.07,15.54,71.57,27.17,140.36,27.17ZM522.71,274.06v45.21h-91.77v31.35c64.46,3.35,112.83,17.13,113.19,33.62v34.38c-.36,16.49-48.73,30.24-113.19,33.6v76.94h-60.93v-76.94c-64.46-3.35-112.81-17.11-113.17-33.6v-34.38c.36-16.49,48.71-30.27,113.17-33.62v-31.35h-91.77v-45.21h244.48ZM242.15,202.11h322.16c7.7,0,14.79,4.05,18.63,10.63l93.85,161.16c4.86,8.36,3.42,18.91-3.52,25.68l-258.34,252.18c-8.38,8.17-21.84,8.17-30.2,0L126.71,399.92c-7.09-6.94-8.43-17.79-3.2-26.19l100.33-161.49c3.91-6.28,10.85-10.12,18.32-10.12Z\"/>\n</svg>`;\n\nconst USDC_LOGO = svgToDataUri(USDC_SVG);\nconst TETHER_LOGO = svgToDataUri(TETHER_SVG);\n\nexport interface BlinkDepositButtonProps {\n /** Fired when the user taps the button. Hosts typically call `requestDeposit()` here. */\n onClick: () => void;\n /** Disables interaction and dims the button. */\n disabled?: boolean;\n /** Non-interactive waiting state (e.g. while the signer request is in flight). Dims like disabled. */\n loading?: boolean;\n}\n\n/**\n * Blink-branded deposit button merchants can drop onto their page instead of\n * building their own: a black pill with a bold \"Deposit stablecoins\" line over\n * an italic \"In a Blink\" line, and overlapping USDC/USDT coin marks on the\n * right. Self-contained — inline styles and data-URI icons, no CSS imports.\n *\n * ```tsx\n * import { BlinkDepositButton, useBlinkDeposit } from '@swype-org/deposit/react';\n *\n * function Checkout() {\n * const { status, requestDeposit } = useBlinkDeposit({ signer: '/api/sign-payment' });\n * return (\n * <BlinkDepositButton\n * onClick={() => requestDeposit({ amount: 50, chainId: 8453, address: '0x…', token: '0x…' })}\n * loading={status === 'signer-loading'}\n * />\n * );\n * }\n * ```\n */\nexport function BlinkDepositButton({\n onClick,\n disabled,\n loading,\n}: BlinkDepositButtonProps): ReactElement {\n const [hovered, setHovered] = useState(false);\n const [pressed, setPressed] = useState(false);\n const inactive = !!disabled || !!loading;\n\n return createElement(\n 'button',\n {\n type: 'button',\n onClick,\n disabled: inactive,\n onMouseEnter: () => setHovered(true),\n onMouseLeave: () => {\n setHovered(false);\n setPressed(false);\n },\n onMouseDown: () => setPressed(true),\n onMouseUp: () => setPressed(false),\n style: pillStyle({ hovered, pressed, inactive, loading: !!loading }),\n },\n createElement(\n 'span',\n { style: labelStackStyle },\n createElement('span', { style: titleStyle }, 'Deposit stablecoins'),\n createElement('span', { style: subtitleStyle }, 'In a Blink'),\n ),\n createElement(\n 'span',\n { style: coinsStyle },\n // The left (USDC) coin paints over the right one, against DOM paint order.\n createElement('img', {\n src: USDC_LOGO,\n alt: '',\n 'aria-hidden': 'true',\n style: { ...coinStyle, marginRight: -8, position: 'relative', zIndex: 1 },\n }),\n createElement('img', { src: TETHER_LOGO, alt: '', 'aria-hidden': 'true', style: coinStyle }),\n ),\n );\n}\n\nconst pillStyle = (state: {\n hovered: boolean;\n pressed: boolean;\n inactive: boolean;\n loading: boolean;\n}): CSSProperties => ({\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'space-between',\n gap: 8,\n width: '100%',\n height: 56,\n padding: '12px 15px 12px 22px',\n backgroundColor: '#000000',\n // A faint white film on hover rather than `filter: brightness()` — a\n // brightness multiply leaves pure black unchanged.\n backgroundImage:\n !state.inactive && state.hovered\n ? 'linear-gradient(rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.12))'\n : undefined,\n color: '#fafafa',\n border: 'none',\n borderRadius: 36,\n cursor: state.inactive ? (state.loading ? 'progress' : 'not-allowed') : 'pointer',\n opacity: state.inactive ? 0.72 : 1,\n boxSizing: 'border-box',\n // Explicit stack so the button is self-sufficient on any host page.\n fontFamily: '-apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, sans-serif',\n textAlign: 'left',\n transform: !state.inactive && state.pressed ? 'scale(0.98)' : undefined,\n transition: 'background-color 0.15s ease, transform 0.15s ease, opacity 0.15s ease',\n});\n\nconst labelStackStyle: CSSProperties = {\n display: 'flex',\n flexDirection: 'column',\n minWidth: 0,\n};\n\nconst titleStyle: CSSProperties = {\n fontSize: 16,\n fontWeight: 700,\n lineHeight: 'normal',\n whiteSpace: 'nowrap',\n};\n\nconst subtitleStyle: CSSProperties = {\n fontSize: 16,\n fontWeight: 400,\n fontStyle: 'italic',\n lineHeight: 'normal',\n whiteSpace: 'nowrap',\n};\n\nconst coinsStyle: CSSProperties = {\n display: 'inline-flex',\n alignItems: 'center',\n flexShrink: 0,\n // Scope the front coin's z-index so it can't escape over host page layers.\n isolation: 'isolate',\n};\n\nconst coinStyle: CSSProperties = {\n width: 29,\n height: 29,\n borderRadius: '50%',\n objectFit: 'cover',\n display: 'block',\n};\n","import { useCallback, useEffect, useRef, useState } from 'react';\n\nimport { Deposit } from './checkout.ts';\nimport { DepositError, getDisplayMessage } from './errors.ts';\nimport type {\n DepositConfig,\n DepositStatus,\n DepositRequest,\n DepositResult,\n} from './types.ts';\n\nexport type { DepositConfig, DepositStatus, DepositRequest, DepositResult };\nexport { DepositError, getDisplayMessage };\nexport { BlinkDepositButton } from './BlinkDepositButton.ts';\nexport type { BlinkDepositButtonProps } from './BlinkDepositButton.ts';\n\ninterface UseBlinkDepositReturn {\n /** Current phase of the deposit flow. */\n status: DepositStatus;\n /** Last successful deposit result, or `null`. */\n result: DepositResult | null;\n /** Last deposit error, or `null`. */\n error: DepositError | null;\n /** User-friendly error message derived from the current error, or `null`. */\n displayMessage: string | null;\n /** Whether a deposit flow is currently in progress. */\n isActive: boolean;\n /** Start a deposit flow. Opens a modal iframe with the hosted deposit. */\n requestDeposit: (request: DepositRequest) => Promise<DepositResult>;\n /** No-op — retained for API compatibility. */\n focus: () => void;\n /** Close the deposit iframe and reset to idle. */\n close: () => void;\n}\n\n/**\n * React hook that wraps the {@link Deposit} class with reactive state.\n *\n * ```tsx\n * import { useBlinkDeposit } from '@swype-org/deposit/react';\n *\n * function DepositButton() {\n * const { status, result, error, displayMessage, requestDeposit } = useBlinkDeposit({\n * signer: '/api/sign-payment',\n * });\n *\n * return (\n * <>\n * <button\n * onClick={() => requestDeposit({ amount: 50, chainId: 8453, address: '0x...', token: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913' })}\n * disabled={status === 'signer-loading'}\n * >\n * {status === 'signer-loading' ? 'Preparing…' : 'Deposit'}\n * </button>\n * {error && <p>{displayMessage}</p>}\n * {result && <p>Transfer {result.transfer.id} complete!</p>}\n * </>\n * );\n * }\n * ```\n */\nexport function useBlinkDeposit(config: DepositConfig): UseBlinkDepositReturn {\n const depositRef = useRef<Deposit | null>(null);\n const [status, setStatus] = useState<DepositStatus>('idle');\n const [result, setResult] = useState<DepositResult | null>(null);\n const [error, setError] = useState<DepositError | null>(null);\n\n if (!depositRef.current) {\n depositRef.current = new Deposit(config);\n }\n\n useEffect(() => {\n const deposit = depositRef.current!;\n\n const onStatusChange = (s: DepositStatus) => setStatus(s);\n const onComplete = (r: DepositResult) => {\n setResult(r);\n setError(null);\n };\n const onError = (e: DepositError) => setError(e);\n\n deposit.on('status-change', onStatusChange);\n deposit.on('complete', onComplete);\n deposit.on('error', onError);\n\n return () => {\n deposit.off('status-change', onStatusChange);\n deposit.off('complete', onComplete);\n deposit.off('error', onError);\n deposit.destroy();\n depositRef.current = null;\n };\n }, []);\n\n const requestDeposit = useCallback(\n (request: DepositRequest) => depositRef.current!.requestDeposit(request),\n [],\n );\n\n const focus = useCallback(() => {}, []);\n const close = useCallback(() => depositRef.current?.close(), []);\n\n const displayMessage = error ? getDisplayMessage(error) : null;\n const isActive = status === 'signer-loading' || status === 'iframe-active';\n\n return { status, result, error, displayMessage, isActive, requestDeposit, focus, close };\n}\n\n/** @deprecated Use {@link useBlinkDeposit} instead. */\nexport const useBlinkCheckout = useBlinkDeposit;\n\n/** @deprecated Use {@link useBlinkDeposit} instead. */\nexport const useSwypeCheckout = useBlinkDeposit;\n"]}
|
|
@@ -41,11 +41,23 @@ interface DepositConfig {
|
|
|
41
41
|
* aspect of the signing request.
|
|
42
42
|
*/
|
|
43
43
|
signer: string | SignerFunction;
|
|
44
|
+
/**
|
|
45
|
+
* Blink environment to target.
|
|
46
|
+
*
|
|
47
|
+
* `'sandbox'` points the hosted flow at the public testnet environment
|
|
48
|
+
* (`https://pay-sandbox.blink.cash`), where deposits run on test networks
|
|
49
|
+
* with separate merchant credentials. An explicit {@link webviewBaseUrl}
|
|
50
|
+
* always takes precedence over this option.
|
|
51
|
+
*
|
|
52
|
+
* @default 'production'
|
|
53
|
+
*/
|
|
54
|
+
environment?: 'production' | 'sandbox';
|
|
44
55
|
/**
|
|
45
56
|
* Base URL of the hosted payment webview app.
|
|
46
57
|
*
|
|
47
58
|
* The SDK appends `merchantId`, `payload`, and `signature` query parameters
|
|
48
|
-
* to this URL and loads the result in a modal iframe.
|
|
59
|
+
* to this URL and loads the result in a modal iframe. When set, this
|
|
60
|
+
* overrides {@link environment}.
|
|
49
61
|
*
|
|
50
62
|
* @default 'https://pay.blink.cash'
|
|
51
63
|
*/
|
|
@@ -75,6 +87,37 @@ interface DepositConfig {
|
|
|
75
87
|
* with a `FLOW_TIMEOUT` error. `undefined` means no limit.
|
|
76
88
|
*/
|
|
77
89
|
flowTimeoutMs?: number;
|
|
90
|
+
/**
|
|
91
|
+
* Whether the hosted flow may show the full widget (Deposit Options entry
|
|
92
|
+
* screen). The full widget only appears when this is enabled (default) AND
|
|
93
|
+
* the merchant's backend config has it enabled — disabling either turns it
|
|
94
|
+
* off.
|
|
95
|
+
*
|
|
96
|
+
* @default true
|
|
97
|
+
*/
|
|
98
|
+
enableFullWidget?: boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Warm up the hosted payment flow in a hidden iframe as soon as the
|
|
101
|
+
* `Deposit` instance is constructed (deferred until the host page has
|
|
102
|
+
* loaded and the main thread is idle). By the time the user starts a
|
|
103
|
+
* deposit, the flow's JS bundle and auth session are already loaded, so
|
|
104
|
+
* the payment UI appears near-instantly.
|
|
105
|
+
*
|
|
106
|
+
* Costs roughly one page load of bandwidth even if the user never
|
|
107
|
+
* deposits. Set `false` to opt out and call {@link Deposit.preload}
|
|
108
|
+
* manually (e.g. on deposit-button hover) — or not at all.
|
|
109
|
+
*
|
|
110
|
+
* @default true
|
|
111
|
+
*/
|
|
112
|
+
preload?: boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Optional merchant id, appended to the warm-up URL so the hosted flow can
|
|
115
|
+
* prefetch the merchant's config and signing public key before the signer
|
|
116
|
+
* responds. Purely a performance hint: it is never trusted for
|
|
117
|
+
* authorization, which always comes from the signed payload returned by
|
|
118
|
+
* {@link signer}.
|
|
119
|
+
*/
|
|
120
|
+
merchantId?: string;
|
|
78
121
|
/**
|
|
79
122
|
* When `true`, the SDK logs lifecycle events (signer calls, iframe state,
|
|
80
123
|
* message reception, errors) to `console.debug`. Useful during integration.
|
|
@@ -41,11 +41,23 @@ interface DepositConfig {
|
|
|
41
41
|
* aspect of the signing request.
|
|
42
42
|
*/
|
|
43
43
|
signer: string | SignerFunction;
|
|
44
|
+
/**
|
|
45
|
+
* Blink environment to target.
|
|
46
|
+
*
|
|
47
|
+
* `'sandbox'` points the hosted flow at the public testnet environment
|
|
48
|
+
* (`https://pay-sandbox.blink.cash`), where deposits run on test networks
|
|
49
|
+
* with separate merchant credentials. An explicit {@link webviewBaseUrl}
|
|
50
|
+
* always takes precedence over this option.
|
|
51
|
+
*
|
|
52
|
+
* @default 'production'
|
|
53
|
+
*/
|
|
54
|
+
environment?: 'production' | 'sandbox';
|
|
44
55
|
/**
|
|
45
56
|
* Base URL of the hosted payment webview app.
|
|
46
57
|
*
|
|
47
58
|
* The SDK appends `merchantId`, `payload`, and `signature` query parameters
|
|
48
|
-
* to this URL and loads the result in a modal iframe.
|
|
59
|
+
* to this URL and loads the result in a modal iframe. When set, this
|
|
60
|
+
* overrides {@link environment}.
|
|
49
61
|
*
|
|
50
62
|
* @default 'https://pay.blink.cash'
|
|
51
63
|
*/
|
|
@@ -75,6 +87,37 @@ interface DepositConfig {
|
|
|
75
87
|
* with a `FLOW_TIMEOUT` error. `undefined` means no limit.
|
|
76
88
|
*/
|
|
77
89
|
flowTimeoutMs?: number;
|
|
90
|
+
/**
|
|
91
|
+
* Whether the hosted flow may show the full widget (Deposit Options entry
|
|
92
|
+
* screen). The full widget only appears when this is enabled (default) AND
|
|
93
|
+
* the merchant's backend config has it enabled — disabling either turns it
|
|
94
|
+
* off.
|
|
95
|
+
*
|
|
96
|
+
* @default true
|
|
97
|
+
*/
|
|
98
|
+
enableFullWidget?: boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Warm up the hosted payment flow in a hidden iframe as soon as the
|
|
101
|
+
* `Deposit` instance is constructed (deferred until the host page has
|
|
102
|
+
* loaded and the main thread is idle). By the time the user starts a
|
|
103
|
+
* deposit, the flow's JS bundle and auth session are already loaded, so
|
|
104
|
+
* the payment UI appears near-instantly.
|
|
105
|
+
*
|
|
106
|
+
* Costs roughly one page load of bandwidth even if the user never
|
|
107
|
+
* deposits. Set `false` to opt out and call {@link Deposit.preload}
|
|
108
|
+
* manually (e.g. on deposit-button hover) — or not at all.
|
|
109
|
+
*
|
|
110
|
+
* @default true
|
|
111
|
+
*/
|
|
112
|
+
preload?: boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Optional merchant id, appended to the warm-up URL so the hosted flow can
|
|
115
|
+
* prefetch the merchant's config and signing public key before the signer
|
|
116
|
+
* responds. Purely a performance hint: it is never trusted for
|
|
117
|
+
* authorization, which always comes from the signed payload returned by
|
|
118
|
+
* {@link signer}.
|
|
119
|
+
*/
|
|
120
|
+
merchantId?: string;
|
|
78
121
|
/**
|
|
79
122
|
* When `true`, the SDK logs lifecycle events (signer calls, iframe state,
|
|
80
123
|
* message reception, errors) to `console.debug`. Useful during integration.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swype-org/deposit",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.19",
|
|
4
4
|
"description": "Lightweight merchant deposit SDK — open a hosted payment flow, handle completion, zero dependencies",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -45,7 +45,10 @@
|
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@types/react": "
|
|
48
|
+
"@types/react": "18.3.18",
|
|
49
|
+
"@types/react-dom": "18.3.5",
|
|
50
|
+
"react": "18.3.1",
|
|
51
|
+
"react-dom": "18.3.1",
|
|
49
52
|
"tsup": "^8.4.0",
|
|
50
53
|
"typescript": "5.7.3"
|
|
51
54
|
},
|