@futurekode/stablepay-react 0.1.0
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 +19 -0
- package/dist/index.d.mts +43 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.js +198 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +164 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +44 -0
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @futurekode/stablepay-react
|
|
2
|
+
|
|
3
|
+
A headless React wrapper for accepting USDC payments on Solana.
|
|
4
|
+
|
|
5
|
+
## Why
|
|
6
|
+
|
|
7
|
+
Crypto payments are often too complex or too opinionated.
|
|
8
|
+
|
|
9
|
+
StablePay strips it down to the essentials:
|
|
10
|
+
|
|
11
|
+
- one package
|
|
12
|
+
- one provider
|
|
13
|
+
- one wrapper
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @futurekode/stablepay-react
|
|
19
|
+
```
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
type StablePaySuccessPayload = {
|
|
5
|
+
signature: string;
|
|
6
|
+
amount: number;
|
|
7
|
+
to: string;
|
|
8
|
+
};
|
|
9
|
+
type StablePayPayArgs = {
|
|
10
|
+
amount: number;
|
|
11
|
+
to: string;
|
|
12
|
+
};
|
|
13
|
+
type StablePayProviderProps = {
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
endpoint?: string;
|
|
16
|
+
};
|
|
17
|
+
type StablePayProps = {
|
|
18
|
+
amount: number;
|
|
19
|
+
to: string;
|
|
20
|
+
children: React.ReactElement;
|
|
21
|
+
onSuccess?: (payload: StablePaySuccessPayload) => void;
|
|
22
|
+
onError?: (error: Error) => void;
|
|
23
|
+
};
|
|
24
|
+
type UseStablePayResult = {
|
|
25
|
+
pay: (args: StablePayPayArgs) => Promise<string>;
|
|
26
|
+
loading: boolean;
|
|
27
|
+
error: Error | null;
|
|
28
|
+
signature: string | null;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
declare function StablePayProvider({ children, endpoint, }: StablePayProviderProps): react_jsx_runtime.JSX.Element;
|
|
32
|
+
|
|
33
|
+
type ClickableChildProps = {
|
|
34
|
+
onClick?: (event: React.MouseEvent) => void;
|
|
35
|
+
disabled?: boolean;
|
|
36
|
+
"aria-busy"?: boolean;
|
|
37
|
+
"data-stablepay-loading"?: string;
|
|
38
|
+
};
|
|
39
|
+
declare function StablePay({ amount, to, children, onSuccess, onError, }: StablePayProps): React.ReactElement<ClickableChildProps, string | React.JSXElementConstructor<any>>;
|
|
40
|
+
|
|
41
|
+
declare function useStablePay(): UseStablePayResult;
|
|
42
|
+
|
|
43
|
+
export { StablePay, type StablePayPayArgs, type StablePayProps, StablePayProvider, type StablePayProviderProps, type StablePaySuccessPayload, type UseStablePayResult, useStablePay };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
type StablePaySuccessPayload = {
|
|
5
|
+
signature: string;
|
|
6
|
+
amount: number;
|
|
7
|
+
to: string;
|
|
8
|
+
};
|
|
9
|
+
type StablePayPayArgs = {
|
|
10
|
+
amount: number;
|
|
11
|
+
to: string;
|
|
12
|
+
};
|
|
13
|
+
type StablePayProviderProps = {
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
endpoint?: string;
|
|
16
|
+
};
|
|
17
|
+
type StablePayProps = {
|
|
18
|
+
amount: number;
|
|
19
|
+
to: string;
|
|
20
|
+
children: React.ReactElement;
|
|
21
|
+
onSuccess?: (payload: StablePaySuccessPayload) => void;
|
|
22
|
+
onError?: (error: Error) => void;
|
|
23
|
+
};
|
|
24
|
+
type UseStablePayResult = {
|
|
25
|
+
pay: (args: StablePayPayArgs) => Promise<string>;
|
|
26
|
+
loading: boolean;
|
|
27
|
+
error: Error | null;
|
|
28
|
+
signature: string | null;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
declare function StablePayProvider({ children, endpoint, }: StablePayProviderProps): react_jsx_runtime.JSX.Element;
|
|
32
|
+
|
|
33
|
+
type ClickableChildProps = {
|
|
34
|
+
onClick?: (event: React.MouseEvent) => void;
|
|
35
|
+
disabled?: boolean;
|
|
36
|
+
"aria-busy"?: boolean;
|
|
37
|
+
"data-stablepay-loading"?: string;
|
|
38
|
+
};
|
|
39
|
+
declare function StablePay({ amount, to, children, onSuccess, onError, }: StablePayProps): React.ReactElement<ClickableChildProps, string | React.JSXElementConstructor<any>>;
|
|
40
|
+
|
|
41
|
+
declare function useStablePay(): UseStablePayResult;
|
|
42
|
+
|
|
43
|
+
export { StablePay, type StablePayPayArgs, type StablePayProps, StablePayProvider, type StablePayProviderProps, type StablePaySuccessPayload, type UseStablePayResult, useStablePay };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
StablePay: () => StablePay,
|
|
34
|
+
StablePayProvider: () => StablePayProvider,
|
|
35
|
+
useStablePay: () => useStablePay
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(index_exports);
|
|
38
|
+
|
|
39
|
+
// src/provider/StablePayProvider.tsx
|
|
40
|
+
var import_react = require("react");
|
|
41
|
+
var import_wallet_adapter_react = require("@solana/wallet-adapter-react");
|
|
42
|
+
var import_wallet_adapter_react_ui = require("@solana/wallet-adapter-react-ui");
|
|
43
|
+
var import_wallet_adapter_wallets = require("@solana/wallet-adapter-wallets");
|
|
44
|
+
var import_styles = require("@solana/wallet-adapter-react-ui/styles.css");
|
|
45
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
46
|
+
function StablePayProvider({
|
|
47
|
+
children,
|
|
48
|
+
endpoint = "https://api.mainnet-beta.solana.com"
|
|
49
|
+
}) {
|
|
50
|
+
const wallets = (0, import_react.useMemo)(
|
|
51
|
+
() => [new import_wallet_adapter_wallets.PhantomWalletAdapter(), new import_wallet_adapter_wallets.SolflareWalletAdapter()],
|
|
52
|
+
[]
|
|
53
|
+
);
|
|
54
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_wallet_adapter_react.ConnectionProvider, { endpoint, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_wallet_adapter_react.WalletProvider, { wallets, autoConnect: true, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_wallet_adapter_react_ui.WalletModalProvider, { children }) }) });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// src/components/StablePay.tsx
|
|
58
|
+
var import_react3 = __toESM(require("react"));
|
|
59
|
+
|
|
60
|
+
// src/hooks/useStablePay.ts
|
|
61
|
+
var import_react2 = require("react");
|
|
62
|
+
var import_web32 = require("@solana/web3.js");
|
|
63
|
+
var import_wallet_adapter_react2 = require("@solana/wallet-adapter-react");
|
|
64
|
+
var import_wallet_adapter_react_ui2 = require("@solana/wallet-adapter-react-ui");
|
|
65
|
+
|
|
66
|
+
// src/solana/buildUsdcTransfer.ts
|
|
67
|
+
var import_web3 = require("@solana/web3.js");
|
|
68
|
+
var import_spl_token = require("@solana/spl-token");
|
|
69
|
+
|
|
70
|
+
// src/solana/constants.ts
|
|
71
|
+
var USDC_MINT = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
72
|
+
var USDC_DECIMALS = 6;
|
|
73
|
+
|
|
74
|
+
// src/solana/amount.ts
|
|
75
|
+
function toTokenBaseUnits(amount) {
|
|
76
|
+
if (!Number.isFinite(amount) || amount <= 0) {
|
|
77
|
+
throw new Error("Amount must be a positive number");
|
|
78
|
+
}
|
|
79
|
+
const multiplier = 10 ** USDC_DECIMALS;
|
|
80
|
+
return BigInt(Math.round(amount * multiplier));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// src/solana/buildUsdcTransfer.ts
|
|
84
|
+
async function buildUsdcTransfer({
|
|
85
|
+
connection,
|
|
86
|
+
fromWallet,
|
|
87
|
+
toWallet,
|
|
88
|
+
amount
|
|
89
|
+
}) {
|
|
90
|
+
const mint = new import_web3.PublicKey(USDC_MINT);
|
|
91
|
+
const fromAta = await (0, import_spl_token.getAssociatedTokenAddress)(mint, fromWallet);
|
|
92
|
+
const toAta = await (0, import_spl_token.getAssociatedTokenAddress)(mint, toWallet);
|
|
93
|
+
const tx = new import_web3.Transaction();
|
|
94
|
+
const toAtaInfo = await connection.getAccountInfo(toAta);
|
|
95
|
+
if (!toAtaInfo) {
|
|
96
|
+
tx.add(
|
|
97
|
+
(0, import_spl_token.createAssociatedTokenAccountInstruction)(fromWallet, toAta, toWallet, mint)
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
tx.add(
|
|
101
|
+
(0, import_spl_token.createTransferCheckedInstruction)(
|
|
102
|
+
fromAta,
|
|
103
|
+
mint,
|
|
104
|
+
toAta,
|
|
105
|
+
fromWallet,
|
|
106
|
+
Number(toTokenBaseUnits(amount)),
|
|
107
|
+
USDC_DECIMALS,
|
|
108
|
+
[],
|
|
109
|
+
import_spl_token.TOKEN_PROGRAM_ID
|
|
110
|
+
)
|
|
111
|
+
);
|
|
112
|
+
const latestBlockhash = await connection.getLatestBlockhash();
|
|
113
|
+
tx.feePayer = fromWallet;
|
|
114
|
+
tx.recentBlockhash = latestBlockhash.blockhash;
|
|
115
|
+
return tx;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// src/hooks/useStablePay.ts
|
|
119
|
+
function useStablePay() {
|
|
120
|
+
const { connection } = (0, import_wallet_adapter_react2.useConnection)();
|
|
121
|
+
const { connected, publicKey, sendTransaction, connect } = (0, import_wallet_adapter_react2.useWallet)();
|
|
122
|
+
const { setVisible } = (0, import_wallet_adapter_react_ui2.useWalletModal)();
|
|
123
|
+
const [loading, setLoading] = (0, import_react2.useState)(false);
|
|
124
|
+
const [signature, setSignature] = (0, import_react2.useState)(null);
|
|
125
|
+
const [error, setError] = (0, import_react2.useState)(null);
|
|
126
|
+
const pay = (0, import_react2.useCallback)(
|
|
127
|
+
async ({ amount, to }) => {
|
|
128
|
+
setLoading(true);
|
|
129
|
+
setSignature(null);
|
|
130
|
+
setError(null);
|
|
131
|
+
try {
|
|
132
|
+
if (!connected) {
|
|
133
|
+
setVisible(true);
|
|
134
|
+
await connect();
|
|
135
|
+
}
|
|
136
|
+
if (!publicKey) {
|
|
137
|
+
throw new Error("Wallet not connected");
|
|
138
|
+
}
|
|
139
|
+
const recipient = new import_web32.PublicKey(to);
|
|
140
|
+
const transaction = await buildUsdcTransfer({
|
|
141
|
+
connection,
|
|
142
|
+
fromWallet: publicKey,
|
|
143
|
+
toWallet: recipient,
|
|
144
|
+
amount
|
|
145
|
+
});
|
|
146
|
+
const sig = await sendTransaction(transaction, connection);
|
|
147
|
+
await connection.confirmTransaction(sig, "confirmed");
|
|
148
|
+
setSignature(sig);
|
|
149
|
+
return sig;
|
|
150
|
+
} catch (err) {
|
|
151
|
+
const normalized = err instanceof Error ? err : new Error("Payment failed");
|
|
152
|
+
setError(normalized);
|
|
153
|
+
throw normalized;
|
|
154
|
+
} finally {
|
|
155
|
+
setLoading(false);
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
[connected, publicKey, sendTransaction, connection, connect, setVisible]
|
|
159
|
+
);
|
|
160
|
+
return { pay, loading, error, signature };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// src/components/StablePay.tsx
|
|
164
|
+
function StablePay({
|
|
165
|
+
amount,
|
|
166
|
+
to,
|
|
167
|
+
children,
|
|
168
|
+
onSuccess,
|
|
169
|
+
onError
|
|
170
|
+
}) {
|
|
171
|
+
const { pay, loading } = useStablePay();
|
|
172
|
+
if (!import_react3.default.isValidElement(children)) {
|
|
173
|
+
throw new Error("StablePay expects a single React element child.");
|
|
174
|
+
}
|
|
175
|
+
async function handleClick(event) {
|
|
176
|
+
try {
|
|
177
|
+
children.props.onClick?.(event);
|
|
178
|
+
if (event.defaultPrevented) return;
|
|
179
|
+
const signature = await pay({ amount, to });
|
|
180
|
+
onSuccess?.({ signature, amount, to });
|
|
181
|
+
} catch (err) {
|
|
182
|
+
onError?.(err instanceof Error ? err : new Error("Payment failed"));
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return import_react3.default.cloneElement(children, {
|
|
186
|
+
onClick: handleClick,
|
|
187
|
+
disabled: Boolean(children.props.disabled) || loading,
|
|
188
|
+
"aria-busy": loading,
|
|
189
|
+
"data-stablepay-loading": loading ? "true" : "false"
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
193
|
+
0 && (module.exports = {
|
|
194
|
+
StablePay,
|
|
195
|
+
StablePayProvider,
|
|
196
|
+
useStablePay
|
|
197
|
+
});
|
|
198
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/provider/StablePayProvider.tsx","../src/components/StablePay.tsx","../src/hooks/useStablePay.ts","../src/solana/buildUsdcTransfer.ts","../src/solana/constants.ts","../src/solana/amount.ts"],"sourcesContent":["export { StablePayProvider } from \"./provider/StablePayProvider\";\nexport { StablePay } from \"./components/StablePay\";\nexport { useStablePay } from \"./hooks/useStablePay\";\nexport type {\n StablePayProps,\n StablePayProviderProps,\n StablePaySuccessPayload,\n StablePayPayArgs,\n UseStablePayResult,\n} from \"./types\";\n","import React, { useMemo } from \"react\";\nimport { ConnectionProvider, WalletProvider } from \"@solana/wallet-adapter-react\";\nimport { WalletModalProvider } from \"@solana/wallet-adapter-react-ui\";\nimport { PhantomWalletAdapter, SolflareWalletAdapter } from \"@solana/wallet-adapter-wallets\";\nimport type { StablePayProviderProps } from \"../types\";\n\nimport \"@solana/wallet-adapter-react-ui/styles.css\";\n\nexport function StablePayProvider({\n children,\n endpoint = \"https://api.mainnet-beta.solana.com\",\n}: StablePayProviderProps) {\n const wallets = useMemo(\n () => [new PhantomWalletAdapter(), new SolflareWalletAdapter()],\n []\n );\n\n return (\n <ConnectionProvider endpoint={endpoint}>\n <WalletProvider wallets={wallets} autoConnect>\n <WalletModalProvider>{children}</WalletModalProvider>\n </WalletProvider>\n </ConnectionProvider>\n );\n}\n","import React from \"react\";\nimport { useStablePay } from \"../hooks/useStablePay\";\nimport type { StablePayProps } from \"../types\";\n\ntype ClickableChildProps = {\n onClick?: (event: React.MouseEvent) => void;\n disabled?: boolean;\n \"aria-busy\"?: boolean;\n \"data-stablepay-loading\"?: string;\n};\n\nexport function StablePay({\n amount,\n to,\n children,\n onSuccess,\n onError,\n}: StablePayProps) {\n const { pay, loading } = useStablePay();\n\n if (!React.isValidElement<ClickableChildProps>(children)) {\n throw new Error(\"StablePay expects a single React element child.\");\n }\n\n async function handleClick(event: React.MouseEvent) {\n try {\n children.props.onClick?.(event);\n\n if (event.defaultPrevented) return;\n\n const signature = await pay({ amount, to });\n onSuccess?.({ signature, amount, to });\n } catch (err) {\n onError?.(err instanceof Error ? err : new Error(\"Payment failed\"));\n }\n }\n\n return React.cloneElement(children, {\n onClick: handleClick,\n disabled: Boolean(children.props.disabled) || loading,\n \"aria-busy\": loading,\n \"data-stablepay-loading\": loading ? \"true\" : \"false\",\n });\n}\n","import { useCallback, useState } from \"react\";\nimport { PublicKey } from \"@solana/web3.js\";\nimport { useConnection, useWallet } from \"@solana/wallet-adapter-react\";\nimport { useWalletModal } from \"@solana/wallet-adapter-react-ui\";\nimport { buildUsdcTransfer } from \"../solana/buildUsdcTransfer\";\nimport type { StablePayPayArgs, UseStablePayResult } from \"../types\";\n\nexport function useStablePay(): UseStablePayResult {\n const { connection } = useConnection();\n const { connected, publicKey, sendTransaction, connect } = useWallet();\n const { setVisible } = useWalletModal();\n\n const [loading, setLoading] = useState(false);\n const [signature, setSignature] = useState<string | null>(null);\n const [error, setError] = useState<Error | null>(null);\n\n const pay = useCallback(\n async ({ amount, to }: StablePayPayArgs) => {\n setLoading(true);\n setSignature(null);\n setError(null);\n\n try {\n if (!connected) {\n setVisible(true);\n await connect();\n }\n\n if (!publicKey) {\n throw new Error(\"Wallet not connected\");\n }\n\n const recipient = new PublicKey(to);\n const transaction = await buildUsdcTransfer({\n connection,\n fromWallet: publicKey,\n toWallet: recipient,\n amount,\n });\n\n const sig = await sendTransaction(transaction, connection);\n await connection.confirmTransaction(sig, \"confirmed\");\n\n setSignature(sig);\n return sig;\n } catch (err) {\n const normalized =\n err instanceof Error ? err : new Error(\"Payment failed\");\n setError(normalized);\n throw normalized;\n } finally {\n setLoading(false);\n }\n },\n [connected, publicKey, sendTransaction, connection, connect, setVisible],\n );\n\n return { pay, loading, error, signature };\n}\n","import { Connection, PublicKey, Transaction } from \"@solana/web3.js\";\nimport {\n TOKEN_PROGRAM_ID,\n createAssociatedTokenAccountInstruction,\n createTransferCheckedInstruction,\n getAssociatedTokenAddress,\n} from \"@solana/spl-token\";\nimport { toTokenBaseUnits } from \"./amount\";\nimport { USDC_DECIMALS, USDC_MINT } from \"./constants\";\n\ntype BuildUsdcTransferParams = {\n connection: Connection;\n fromWallet: PublicKey;\n toWallet: PublicKey;\n amount: number;\n};\n\nexport async function buildUsdcTransfer({\n connection,\n fromWallet,\n toWallet,\n amount,\n}: BuildUsdcTransferParams) {\n const mint = new PublicKey(USDC_MINT);\n const fromAta = await getAssociatedTokenAddress(mint, fromWallet);\n const toAta = await getAssociatedTokenAddress(mint, toWallet);\n\n const tx = new Transaction();\n const toAtaInfo = await connection.getAccountInfo(toAta);\n\n if (!toAtaInfo) {\n tx.add(\n createAssociatedTokenAccountInstruction(fromWallet, toAta, toWallet, mint)\n );\n }\n\n tx.add(\n createTransferCheckedInstruction(\n fromAta,\n mint,\n toAta,\n fromWallet,\n Number(toTokenBaseUnits(amount)),\n USDC_DECIMALS,\n [],\n TOKEN_PROGRAM_ID\n )\n );\n\n const latestBlockhash = await connection.getLatestBlockhash();\n tx.feePayer = fromWallet;\n tx.recentBlockhash = latestBlockhash.blockhash;\n\n return tx;\n}\n","export const USDC_MINT = \"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v\";\nexport const USDC_DECIMALS = 6;\n","import { USDC_DECIMALS } from \"./constants\";\n\nexport function toTokenBaseUnits(amount: number): bigint {\n if (!Number.isFinite(amount) || amount <= 0) {\n throw new Error(\"Amount must be a positive number\");\n }\n\n const multiplier = 10 ** USDC_DECIMALS;\n return BigInt(Math.round(amount * multiplier));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA+B;AAC/B,kCAAmD;AACnD,qCAAoC;AACpC,oCAA4D;AAG5D,oBAAO;AAcC;AAZD,SAAS,kBAAkB;AAAA,EAChC;AAAA,EACA,WAAW;AACb,GAA2B;AACzB,QAAM,cAAU;AAAA,IACd,MAAM,CAAC,IAAI,mDAAqB,GAAG,IAAI,oDAAsB,CAAC;AAAA,IAC9D,CAAC;AAAA,EACH;AAEA,SACE,4CAAC,kDAAmB,UAClB,sDAAC,8CAAe,SAAkB,aAAW,MAC3C,sDAAC,sDAAqB,UAAS,GACjC,GACF;AAEJ;;;ACxBA,IAAAA,gBAAkB;;;ACAlB,IAAAC,gBAAsC;AACtC,IAAAC,eAA0B;AAC1B,IAAAC,+BAAyC;AACzC,IAAAC,kCAA+B;;;ACH/B,kBAAmD;AACnD,uBAKO;;;ACNA,IAAM,YAAY;AAClB,IAAM,gBAAgB;;;ACCtB,SAAS,iBAAiB,QAAwB;AACvD,MAAI,CAAC,OAAO,SAAS,MAAM,KAAK,UAAU,GAAG;AAC3C,UAAM,IAAI,MAAM,kCAAkC;AAAA,EACpD;AAEA,QAAM,aAAa,MAAM;AACzB,SAAO,OAAO,KAAK,MAAM,SAAS,UAAU,CAAC;AAC/C;;;AFQA,eAAsB,kBAAkB;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAA4B;AAC1B,QAAM,OAAO,IAAI,sBAAU,SAAS;AACpC,QAAM,UAAU,UAAM,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A,QACF,CAAC;AAED,cAAM,MAAM,MAAM,gBAAgB,aAAa,UAAU;AACzD,cAAM,WAAW,mBAAmB,KAAK,WAAW;AAEpD,qBAAa,GAAG;AAChB,eAAO;AAAA,MACT,SAAS,KAAK;AACZ,cAAM,aACJ,eAAe,QAAQ,MAAM,IAAI,MAAM,gBAAgB;AACzD,iBAAS,UAAU;AACnB,cAAM;AAAA,MACR,UAAE;AACA,mBAAW,KAAK;AAAA,MAClB;AAAA,IACF;AAAA,IACA,CAAC,WAAW,WAAW,iBAAiB,YAAY,SAAS,UAAU;AAAA,EACzE;AAEA,SAAO,EAAE,KAAK,SAAS,OAAO,UAAU;AAC1C;;;AD/CO,SAAS,UAAU;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAmB;AACjB,QAAM,EAAE,KAAK,QAAQ,IAAI,aAAa;AAEtC,MAAI,CAAC,cAAAC,QAAM,eAAoC,QAAQ,GAAG;AACxD,UAAM,IAAI,MAAM,iDAAiD;AAAA,EACnE;AAEA,iBAAe,YAAY,OAAyB;AAClD,QAAI;AACF,eAAS,MAAM,UAAU,KAAK;AAE9B,UAAI,MAAM,iBAAkB;AAE5B,YAAM,YAAY,MAAM,IAAI,EAAE,QAAQ,GAAG,CAAC;AAC1C,kBAAY,EAAE,WAAW,QAAQ,GAAG,CAAC;AAAA,IACvC,SAAS,KAAK;AACZ,gBAAU,eAAe,QAAQ,MAAM,IAAI,MAAM,gBAAgB,CAAC;AAAA,IACpE;AAAA,EACF;AAEA,SAAO,cAAAA,QAAM,aAAa,UAAU;AAAA,IAClC,SAAS;AAAA,IACT,UAAU,QAAQ,SAAS,MAAM,QAAQ,KAAK;AAAA,IAC9C,aAAa;AAAA,IACb,0BAA0B,UAAU,SAAS;AAAA,EAC/C,CAAC;AACH;","names":["import_react","import_react","import_web3","import_wallet_adapter_react","import_wallet_adapter_react_ui","React"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// src/provider/StablePayProvider.tsx
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import { ConnectionProvider, WalletProvider } from "@solana/wallet-adapter-react";
|
|
4
|
+
import { WalletModalProvider } from "@solana/wallet-adapter-react-ui";
|
|
5
|
+
import { PhantomWalletAdapter, SolflareWalletAdapter } from "@solana/wallet-adapter-wallets";
|
|
6
|
+
import "@solana/wallet-adapter-react-ui/styles.css";
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
function StablePayProvider({
|
|
9
|
+
children,
|
|
10
|
+
endpoint = "https://api.mainnet-beta.solana.com"
|
|
11
|
+
}) {
|
|
12
|
+
const wallets = useMemo(
|
|
13
|
+
() => [new PhantomWalletAdapter(), new SolflareWalletAdapter()],
|
|
14
|
+
[]
|
|
15
|
+
);
|
|
16
|
+
return /* @__PURE__ */ jsx(ConnectionProvider, { endpoint, children: /* @__PURE__ */ jsx(WalletProvider, { wallets, autoConnect: true, children: /* @__PURE__ */ jsx(WalletModalProvider, { children }) }) });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// src/components/StablePay.tsx
|
|
20
|
+
import React2 from "react";
|
|
21
|
+
|
|
22
|
+
// src/hooks/useStablePay.ts
|
|
23
|
+
import { useCallback, useState } from "react";
|
|
24
|
+
import { PublicKey as PublicKey2 } from "@solana/web3.js";
|
|
25
|
+
import { useConnection, useWallet } from "@solana/wallet-adapter-react";
|
|
26
|
+
import { useWalletModal } from "@solana/wallet-adapter-react-ui";
|
|
27
|
+
|
|
28
|
+
// src/solana/buildUsdcTransfer.ts
|
|
29
|
+
import { PublicKey, Transaction } from "@solana/web3.js";
|
|
30
|
+
import {
|
|
31
|
+
TOKEN_PROGRAM_ID,
|
|
32
|
+
createAssociatedTokenAccountInstruction,
|
|
33
|
+
createTransferCheckedInstruction,
|
|
34
|
+
getAssociatedTokenAddress
|
|
35
|
+
} from "@solana/spl-token";
|
|
36
|
+
|
|
37
|
+
// src/solana/constants.ts
|
|
38
|
+
var USDC_MINT = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
39
|
+
var USDC_DECIMALS = 6;
|
|
40
|
+
|
|
41
|
+
// src/solana/amount.ts
|
|
42
|
+
function toTokenBaseUnits(amount) {
|
|
43
|
+
if (!Number.isFinite(amount) || amount <= 0) {
|
|
44
|
+
throw new Error("Amount must be a positive number");
|
|
45
|
+
}
|
|
46
|
+
const multiplier = 10 ** USDC_DECIMALS;
|
|
47
|
+
return BigInt(Math.round(amount * multiplier));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// src/solana/buildUsdcTransfer.ts
|
|
51
|
+
async function buildUsdcTransfer({
|
|
52
|
+
connection,
|
|
53
|
+
fromWallet,
|
|
54
|
+
toWallet,
|
|
55
|
+
amount
|
|
56
|
+
}) {
|
|
57
|
+
const mint = new PublicKey(USDC_MINT);
|
|
58
|
+
const fromAta = await getAssociatedTokenAddress(mint, fromWallet);
|
|
59
|
+
const toAta = await getAssociatedTokenAddress(mint, toWallet);
|
|
60
|
+
const tx = new Transaction();
|
|
61
|
+
const toAtaInfo = await connection.getAccountInfo(toAta);
|
|
62
|
+
if (!toAtaInfo) {
|
|
63
|
+
tx.add(
|
|
64
|
+
createAssociatedTokenAccountInstruction(fromWallet, toAta, toWallet, mint)
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
tx.add(
|
|
68
|
+
createTransferCheckedInstruction(
|
|
69
|
+
fromAta,
|
|
70
|
+
mint,
|
|
71
|
+
toAta,
|
|
72
|
+
fromWallet,
|
|
73
|
+
Number(toTokenBaseUnits(amount)),
|
|
74
|
+
USDC_DECIMALS,
|
|
75
|
+
[],
|
|
76
|
+
TOKEN_PROGRAM_ID
|
|
77
|
+
)
|
|
78
|
+
);
|
|
79
|
+
const latestBlockhash = await connection.getLatestBlockhash();
|
|
80
|
+
tx.feePayer = fromWallet;
|
|
81
|
+
tx.recentBlockhash = latestBlockhash.blockhash;
|
|
82
|
+
return tx;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// src/hooks/useStablePay.ts
|
|
86
|
+
function useStablePay() {
|
|
87
|
+
const { connection } = useConnection();
|
|
88
|
+
const { connected, publicKey, sendTransaction, connect } = useWallet();
|
|
89
|
+
const { setVisible } = useWalletModal();
|
|
90
|
+
const [loading, setLoading] = useState(false);
|
|
91
|
+
const [signature, setSignature] = useState(null);
|
|
92
|
+
const [error, setError] = useState(null);
|
|
93
|
+
const pay = useCallback(
|
|
94
|
+
async ({ amount, to }) => {
|
|
95
|
+
setLoading(true);
|
|
96
|
+
setSignature(null);
|
|
97
|
+
setError(null);
|
|
98
|
+
try {
|
|
99
|
+
if (!connected) {
|
|
100
|
+
setVisible(true);
|
|
101
|
+
await connect();
|
|
102
|
+
}
|
|
103
|
+
if (!publicKey) {
|
|
104
|
+
throw new Error("Wallet not connected");
|
|
105
|
+
}
|
|
106
|
+
const recipient = new PublicKey2(to);
|
|
107
|
+
const transaction = await buildUsdcTransfer({
|
|
108
|
+
connection,
|
|
109
|
+
fromWallet: publicKey,
|
|
110
|
+
toWallet: recipient,
|
|
111
|
+
amount
|
|
112
|
+
});
|
|
113
|
+
const sig = await sendTransaction(transaction, connection);
|
|
114
|
+
await connection.confirmTransaction(sig, "confirmed");
|
|
115
|
+
setSignature(sig);
|
|
116
|
+
return sig;
|
|
117
|
+
} catch (err) {
|
|
118
|
+
const normalized = err instanceof Error ? err : new Error("Payment failed");
|
|
119
|
+
setError(normalized);
|
|
120
|
+
throw normalized;
|
|
121
|
+
} finally {
|
|
122
|
+
setLoading(false);
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
[connected, publicKey, sendTransaction, connection, connect, setVisible]
|
|
126
|
+
);
|
|
127
|
+
return { pay, loading, error, signature };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// src/components/StablePay.tsx
|
|
131
|
+
function StablePay({
|
|
132
|
+
amount,
|
|
133
|
+
to,
|
|
134
|
+
children,
|
|
135
|
+
onSuccess,
|
|
136
|
+
onError
|
|
137
|
+
}) {
|
|
138
|
+
const { pay, loading } = useStablePay();
|
|
139
|
+
if (!React2.isValidElement(children)) {
|
|
140
|
+
throw new Error("StablePay expects a single React element child.");
|
|
141
|
+
}
|
|
142
|
+
async function handleClick(event) {
|
|
143
|
+
try {
|
|
144
|
+
children.props.onClick?.(event);
|
|
145
|
+
if (event.defaultPrevented) return;
|
|
146
|
+
const signature = await pay({ amount, to });
|
|
147
|
+
onSuccess?.({ signature, amount, to });
|
|
148
|
+
} catch (err) {
|
|
149
|
+
onError?.(err instanceof Error ? err : new Error("Payment failed"));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return React2.cloneElement(children, {
|
|
153
|
+
onClick: handleClick,
|
|
154
|
+
disabled: Boolean(children.props.disabled) || loading,
|
|
155
|
+
"aria-busy": loading,
|
|
156
|
+
"data-stablepay-loading": loading ? "true" : "false"
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
export {
|
|
160
|
+
StablePay,
|
|
161
|
+
StablePayProvider,
|
|
162
|
+
useStablePay
|
|
163
|
+
};
|
|
164
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/provider/StablePayProvider.tsx","../src/components/StablePay.tsx","../src/hooks/useStablePay.ts","../src/solana/buildUsdcTransfer.ts","../src/solana/constants.ts","../src/solana/amount.ts"],"sourcesContent":["import React, { useMemo } from \"react\";\nimport { ConnectionProvider, WalletProvider } from \"@solana/wallet-adapter-react\";\nimport { WalletModalProvider } from \"@solana/wallet-adapter-react-ui\";\nimport { PhantomWalletAdapter, SolflareWalletAdapter } from \"@solana/wallet-adapter-wallets\";\nimport type { StablePayProviderProps } from \"../types\";\n\nimport \"@solana/wallet-adapter-react-ui/styles.css\";\n\nexport function StablePayProvider({\n children,\n endpoint = \"https://api.mainnet-beta.solana.com\",\n}: StablePayProviderProps) {\n const wallets = useMemo(\n () => [new PhantomWalletAdapter(), new SolflareWalletAdapter()],\n []\n );\n\n return (\n <ConnectionProvider endpoint={endpoint}>\n <WalletProvider wallets={wallets} autoConnect>\n <WalletModalProvider>{children}</WalletModalProvider>\n </WalletProvider>\n </ConnectionProvider>\n );\n}\n","import React from \"react\";\nimport { useStablePay } from \"../hooks/useStablePay\";\nimport type { StablePayProps } from \"../types\";\n\ntype ClickableChildProps = {\n onClick?: (event: React.MouseEvent) => void;\n disabled?: boolean;\n \"aria-busy\"?: boolean;\n \"data-stablepay-loading\"?: string;\n};\n\nexport function StablePay({\n amount,\n to,\n children,\n onSuccess,\n onError,\n}: StablePayProps) {\n const { pay, loading } = useStablePay();\n\n if (!React.isValidElement<ClickableChildProps>(children)) {\n throw new Error(\"StablePay expects a single React element child.\");\n }\n\n async function handleClick(event: React.MouseEvent) {\n try {\n children.props.onClick?.(event);\n\n if (event.defaultPrevented) return;\n\n const signature = await pay({ amount, to });\n onSuccess?.({ signature, amount, to });\n } catch (err) {\n onError?.(err instanceof Error ? err : new Error(\"Payment failed\"));\n }\n }\n\n return React.cloneElement(children, {\n onClick: handleClick,\n disabled: Boolean(children.props.disabled) || loading,\n \"aria-busy\": loading,\n \"data-stablepay-loading\": loading ? \"true\" : \"false\",\n });\n}\n","import { useCallback, useState } from \"react\";\nimport { PublicKey } from \"@solana/web3.js\";\nimport { useConnection, useWallet } from \"@solana/wallet-adapter-react\";\nimport { useWalletModal } from \"@solana/wallet-adapter-react-ui\";\nimport { buildUsdcTransfer } from \"../solana/buildUsdcTransfer\";\nimport type { StablePayPayArgs, UseStablePayResult } from \"../types\";\n\nexport function useStablePay(): UseStablePayResult {\n const { connection } = useConnection();\n const { connected, publicKey, sendTransaction, connect } = useWallet();\n const { setVisible } = useWalletModal();\n\n const [loading, setLoading] = useState(false);\n const [signature, setSignature] = useState<string | null>(null);\n const [error, setError] = useState<Error | null>(null);\n\n const pay = useCallback(\n async ({ amount, to }: StablePayPayArgs) => {\n setLoading(true);\n setSignature(null);\n setError(null);\n\n try {\n if (!connected) {\n setVisible(true);\n await connect();\n }\n\n if (!publicKey) {\n throw new Error(\"Wallet not connected\");\n }\n\n const recipient = new PublicKey(to);\n const transaction = await buildUsdcTransfer({\n connection,\n fromWallet: publicKey,\n toWallet: recipient,\n amount,\n });\n\n const sig = await sendTransaction(transaction, connection);\n await connection.confirmTransaction(sig, \"confirmed\");\n\n setSignature(sig);\n return sig;\n } catch (err) {\n const normalized =\n err instanceof Error ? err : new Error(\"Payment failed\");\n setError(normalized);\n throw normalized;\n } finally {\n setLoading(false);\n }\n },\n [connected, publicKey, sendTransaction, connection, connect, setVisible],\n );\n\n return { pay, loading, error, signature };\n}\n","import { Connection, PublicKey, Transaction } from \"@solana/web3.js\";\nimport {\n TOKEN_PROGRAM_ID,\n createAssociatedTokenAccountInstruction,\n createTransferCheckedInstruction,\n getAssociatedTokenAddress,\n} from \"@solana/spl-token\";\nimport { toTokenBaseUnits } from \"./amount\";\nimport { USDC_DECIMALS, USDC_MINT } from \"./constants\";\n\ntype BuildUsdcTransferParams = {\n connection: Connection;\n fromWallet: PublicKey;\n toWallet: PublicKey;\n amount: number;\n};\n\nexport async function buildUsdcTransfer({\n connection,\n fromWallet,\n toWallet,\n amount,\n}: BuildUsdcTransferParams) {\n const mint = new PublicKey(USDC_MINT);\n const fromAta = await getAssociatedTokenAddress(mint, fromWallet);\n const toAta = await getAssociatedTokenAddress(mint, toWallet);\n\n const tx = new Transaction();\n const toAtaInfo = await connection.getAccountInfo(toAta);\n\n if (!toAtaInfo) {\n tx.add(\n createAssociatedTokenAccountInstruction(fromWallet, toAta, toWallet, mint)\n );\n }\n\n tx.add(\n createTransferCheckedInstruction(\n fromAta,\n mint,\n toAta,\n fromWallet,\n Number(toTokenBaseUnits(amount)),\n USDC_DECIMALS,\n [],\n TOKEN_PROGRAM_ID\n )\n );\n\n const latestBlockhash = await connection.getLatestBlockhash();\n tx.feePayer = fromWallet;\n tx.recentBlockhash = latestBlockhash.blockhash;\n\n return tx;\n}\n","export const USDC_MINT = \"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v\";\nexport const USDC_DECIMALS = 6;\n","import { USDC_DECIMALS } from \"./constants\";\n\nexport function toTokenBaseUnits(amount: number): bigint {\n if (!Number.isFinite(amount) || amount <= 0) {\n throw new Error(\"Amount must be a positive number\");\n }\n\n const multiplier = 10 ** USDC_DECIMALS;\n return BigInt(Math.round(amount * multiplier));\n}\n"],"mappings":";AAAA,SAAgB,eAAe;AAC/B,SAAS,oBAAoB,sBAAsB;AACnD,SAAS,2BAA2B;AACpC,SAAS,sBAAsB,6BAA6B;AAG5D,OAAO;AAcC;AAZD,SAAS,kBAAkB;AAAA,EAChC;AAAA,EACA,WAAW;AACb,GAA2B;AACzB,QAAM,UAAU;AAAA,IACd,MAAM,CAAC,IAAI,qBAAqB,GAAG,IAAI,sBAAsB,CAAC;AAAA,IAC9D,CAAC;AAAA,EACH;AAEA,SACE,oBAAC,sBAAmB,UAClB,8BAAC,kBAAe,SAAkB,aAAW,MAC3C,8BAAC,uBAAqB,UAAS,GACjC,GACF;AAEJ;;;ACxBA,OAAOA,YAAW;;;ACAlB,SAAS,aAAa,gBAAgB;AACtC,SAAS,aAAAC,kBAAiB;AAC1B,SAAS,eAAe,iBAAiB;AACzC,SAAS,sBAAsB;;;ACH/B,SAAqB,WAAW,mBAAmB;AACnD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACNA,IAAM,YAAY;AAClB,IAAM,gBAAgB;;;ACCtB,SAAS,iBAAiB,QAAwB;AACvD,MAAI,CAAC,OAAO,SAAS,MAAM,KAAK,UAAU,GAAG;AAC3C,UAAM,IAAI,MAAM,kCAAkC;AAAA,EACpD;AAEA,QAAM,aAAa,MAAM;AACzB,SAAO,OAAO,KAAK,MAAM,SAAS,UAAU,CAAC;AAC/C;;;AFQA,eAAsB,kBAAkB;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAC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1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@futurekode/stablepay-react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Headless React wrapper for USDC payments on Solana",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsup",
|
|
21
|
+
"dev": "tsup --watch",
|
|
22
|
+
"lint": "tsc --noEmit"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@solana/spl-token": "^0.4.14",
|
|
26
|
+
"@solana/wallet-adapter-base": "^0.9.27",
|
|
27
|
+
"@solana/wallet-adapter-react": "^0.15.39",
|
|
28
|
+
"@solana/wallet-adapter-react-ui": "^0.9.39",
|
|
29
|
+
"@solana/wallet-adapter-wallets": "^0.19.37",
|
|
30
|
+
"@solana/web3.js": "^1.98.4"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
34
|
+
"react-dom": "^18.0.0 || ^19.0.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"react": "18.3.1",
|
|
38
|
+
"react-dom": "18.3.1",
|
|
39
|
+
"@types/react": "^18.3.18",
|
|
40
|
+
"@types/react-dom": "^18.3.5",
|
|
41
|
+
"tsup": "^8.5.0",
|
|
42
|
+
"typescript": "^5.8.3"
|
|
43
|
+
}
|
|
44
|
+
}
|