@coinflowlabs/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 +35 -0
- package/build/cjs/CoinflowIFrame.d.ts +11 -0
- package/build/cjs/CoinflowIFrame.js +23 -0
- package/build/cjs/CoinflowIFrame.js.map +1 -0
- package/build/cjs/CoinflowPurchase.d.ts +14 -0
- package/build/cjs/CoinflowPurchase.js +16 -0
- package/build/cjs/CoinflowPurchase.js.map +1 -0
- package/build/cjs/CoinflowWithdraw.d.ts +14 -0
- package/build/cjs/CoinflowWithdraw.js +16 -0
- package/build/cjs/CoinflowWithdraw.js.map +1 -0
- package/build/cjs/IFrameWalletConnector.d.ts +17 -0
- package/build/cjs/IFrameWalletConnector.js +135 -0
- package/build/cjs/IFrameWalletConnector.js.map +1 -0
- package/build/cjs/index.d.ts +2 -0
- package/build/cjs/index.js +6 -0
- package/build/cjs/index.js.map +1 -0
- package/build/esm/CoinflowIFrame.d.ts +11 -0
- package/build/esm/CoinflowIFrame.js +19 -0
- package/build/esm/CoinflowIFrame.js.map +1 -0
- package/build/esm/CoinflowPurchase.d.ts +14 -0
- package/build/esm/CoinflowPurchase.js +11 -0
- package/build/esm/CoinflowPurchase.js.map +1 -0
- package/build/esm/CoinflowWithdraw.d.ts +14 -0
- package/build/esm/CoinflowWithdraw.js +11 -0
- package/build/esm/CoinflowWithdraw.js.map +1 -0
- package/build/esm/IFrameWalletConnector.d.ts +17 -0
- package/build/esm/IFrameWalletConnector.js +131 -0
- package/build/esm/IFrameWalletConnector.js.map +1 -0
- package/build/esm/index.d.ts +2 -0
- package/build/esm/index.js +3 -0
- package/build/esm/index.js.map +1 -0
- package/package.json +57 -0
package/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Coinflow React
|
|
2
|
+
|
|
3
|
+
## Withdraw Usage
|
|
4
|
+
```
|
|
5
|
+
import {useWallet} from '@solana/wallet-adapter-react';
|
|
6
|
+
const wallet = useWallet();
|
|
7
|
+
const connection = useConnection();
|
|
8
|
+
|
|
9
|
+
<CoinflowWithdraw wallet={wallet} merchantId='<YOUR MERCHANT ID>' env='prod|sandbox|staging' connection={connection} />;
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Props:
|
|
13
|
+
* `wallet`: The Solana Wallet Adapter Wallet
|
|
14
|
+
* `merchantId`: Your Merchant ID (Contact Coinflow support for this)
|
|
15
|
+
* `connection`: Solana Connection
|
|
16
|
+
* `env` (optional): This defaults to `prod`
|
|
17
|
+
- For testing set to `staging`
|
|
18
|
+
* `onSuccess` (optional): function to run when the withdrawal process is successful
|
|
19
|
+
|
|
20
|
+
## Purchase Usage
|
|
21
|
+
```
|
|
22
|
+
import {useWallet} from '@solana/wallet-adapter-react';
|
|
23
|
+
const wallet = useWallet();
|
|
24
|
+
const connection = useConnection();
|
|
25
|
+
|
|
26
|
+
<CoinflowPurchase wallet={wallet} merchantId='<YOUR MERCHANT ID>' env='prod|sandbox|staging' connection={connection} />;
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Props:
|
|
30
|
+
* `wallet`: The Solana Wallet Adapter Wallet
|
|
31
|
+
* `merchantId`: Your Merchant ID (Contact Coinflow support for this)
|
|
32
|
+
* `connection`: Solana Connection
|
|
33
|
+
* `env` (optional): This defaults to `prod`
|
|
34
|
+
- For testing set to `staging`
|
|
35
|
+
* `onSuccess` (optional): function to run when the purchase process is successful
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export type CoinflowEnvs = 'prod' | 'staging' | 'sandbox' | 'local';
|
|
3
|
+
type CoinflowIFrameProps = {
|
|
4
|
+
publicKey: string;
|
|
5
|
+
IFrameRef: React.RefObject<HTMLIFrameElement>;
|
|
6
|
+
env?: CoinflowEnvs;
|
|
7
|
+
route: string;
|
|
8
|
+
};
|
|
9
|
+
declare function CoinflowIFrame({ publicKey, IFrameRef, env, route, }: CoinflowIFrameProps): JSX.Element;
|
|
10
|
+
export declare const CoinflowIframe: React.MemoExoticComponent<typeof CoinflowIFrame>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
exports.CoinflowIframe = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var react_1 = tslib_1.__importDefault(require("react"));
|
|
6
|
+
function getCoinflowUrl(env) {
|
|
7
|
+
if (!env || env === 'prod')
|
|
8
|
+
return 'https://coinflow.cash';
|
|
9
|
+
if (env === 'local')
|
|
10
|
+
return 'http://localhost:3000';
|
|
11
|
+
return "https://".concat(env, ".coinflow.cash");
|
|
12
|
+
}
|
|
13
|
+
function CoinflowIFrame(_a) {
|
|
14
|
+
var publicKey = _a.publicKey, IFrameRef = _a.IFrameRef, env = _a.env, route = _a.route;
|
|
15
|
+
var url = new URL(route, getCoinflowUrl(env));
|
|
16
|
+
url.searchParams.append('pubkey', publicKey);
|
|
17
|
+
return (react_1["default"].createElement("iframe", { ref: IFrameRef, style: {
|
|
18
|
+
width: '100%',
|
|
19
|
+
height: '100%'
|
|
20
|
+
}, title: "withdraw", frameBorder: "0", src: url.toString() }));
|
|
21
|
+
}
|
|
22
|
+
exports.CoinflowIframe = react_1["default"].memo(CoinflowIFrame);
|
|
23
|
+
//# sourceMappingURL=CoinflowIFrame.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CoinflowIFrame.js","sourceRoot":"","sources":["../../src/CoinflowIFrame.tsx"],"names":[],"mappings":";;;;AAAA,wDAA0B;AAW1B,SAAS,cAAc,CAAC,GAAkB;IACxC,IAAI,CAAC,GAAG,IAAI,GAAG,KAAK,MAAM;QAAE,OAAO,uBAAuB,CAAC;IAC3D,IAAI,GAAG,KAAK,OAAO;QAAE,OAAO,uBAAuB,CAAC;IAEpD,OAAO,kBAAW,GAAG,mBAAgB,CAAC;AACxC,CAAC;AAED,SAAS,cAAc,CAAC,EAKF;QAJpB,SAAS,eAAA,EACT,SAAS,eAAA,EACT,GAAG,SAAA,EACH,KAAK,WAAA;IAEL,IAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC;IAChD,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IAE7C,OAAO,CACL,6CACE,GAAG,EAAE,SAAS,EACd,KAAK,EAAE;YACL,KAAK,EAAE,MAAM;YACb,MAAM,EAAE,MAAM;SACf,EACD,KAAK,EAAC,UAAU,EAChB,WAAW,EAAC,GAAG,EACf,GAAG,EAAE,GAAG,CAAC,QAAQ,EAAE,GACnB,CACH,CAAC;AACJ,CAAC;AAEY,QAAA,cAAc,GAAG,kBAAK,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { WalletContextState } from '@solana/wallet-adapter-react';
|
|
3
|
+
import { Connection } from '@solana/web3.js';
|
|
4
|
+
import { CoinflowEnvs } from './CoinflowIFrame';
|
|
5
|
+
import { OnSuccessMethod } from './IFrameWalletConnector';
|
|
6
|
+
type Props = {
|
|
7
|
+
wallet: WalletContextState;
|
|
8
|
+
merchantId: string;
|
|
9
|
+
connection: Connection;
|
|
10
|
+
env?: CoinflowEnvs;
|
|
11
|
+
onSuccess?: OnSuccessMethod;
|
|
12
|
+
};
|
|
13
|
+
export declare function CoinflowPurchase({ wallet, merchantId, env, connection, onSuccess, }: Props): JSX.Element | null;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
exports.CoinflowPurchase = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var react_1 = tslib_1.__importDefault(require("react"));
|
|
6
|
+
var CoinflowIFrame_1 = require("./CoinflowIFrame");
|
|
7
|
+
var IFrameWalletConnector_1 = require("./IFrameWalletConnector");
|
|
8
|
+
function CoinflowPurchase(_a) {
|
|
9
|
+
var wallet = _a.wallet, merchantId = _a.merchantId, env = _a.env, connection = _a.connection, onSuccess = _a.onSuccess;
|
|
10
|
+
var IFrameRef = (0, IFrameWalletConnector_1.useIframeWallet)({ wallet: wallet, connection: connection, onSuccess: onSuccess }).IFrameRef;
|
|
11
|
+
if (!wallet.publicKey || !wallet.connected)
|
|
12
|
+
return null;
|
|
13
|
+
return (react_1["default"].createElement(CoinflowIFrame_1.CoinflowIframe, { publicKey: wallet.publicKey.toString(), IFrameRef: IFrameRef, route: "/purchase/".concat(merchantId), env: env }));
|
|
14
|
+
}
|
|
15
|
+
exports.CoinflowPurchase = CoinflowPurchase;
|
|
16
|
+
//# sourceMappingURL=CoinflowPurchase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CoinflowPurchase.js","sourceRoot":"","sources":["../../src/CoinflowPurchase.tsx"],"names":[],"mappings":";;;;AACA,wDAA0B;AAE1B,mDAA8D;AAC9D,iEAAyE;AAUzE,SAAgB,gBAAgB,CAAC,EAMzB;QALN,MAAM,YAAA,EACN,UAAU,gBAAA,EACV,GAAG,SAAA,EACH,UAAU,gBAAA,EACV,SAAS,eAAA;IAEF,IAAA,SAAS,GAAI,IAAA,uCAAe,EAAC,EAAC,MAAM,QAAA,EAAE,UAAU,YAAA,EAAE,SAAS,WAAA,EAAC,CAAC,UAApD,CAAqD;IAErE,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,MAAM,CAAC,SAAS;QAAE,OAAO,IAAI,CAAC;IAExD,OAAO,CACL,iCAAC,+BAAc,IACb,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,EACtC,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,oBAAa,UAAU,CAAE,EAChC,GAAG,EAAE,GAAG,GACR,CACH,CAAC;AACJ,CAAC;AAnBD,4CAmBC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { WalletContextState } from '@solana/wallet-adapter-react';
|
|
3
|
+
import { Connection } from '@solana/web3.js';
|
|
4
|
+
import { CoinflowEnvs } from './CoinflowIFrame';
|
|
5
|
+
import { OnSuccessMethod } from './IFrameWalletConnector';
|
|
6
|
+
type Props = {
|
|
7
|
+
wallet: WalletContextState;
|
|
8
|
+
merchantId: string;
|
|
9
|
+
connection: Connection;
|
|
10
|
+
env?: CoinflowEnvs;
|
|
11
|
+
onSuccess?: OnSuccessMethod;
|
|
12
|
+
};
|
|
13
|
+
export declare function CoinflowWithdraw({ wallet, merchantId, env, connection, onSuccess, }: Props): JSX.Element | null;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
exports.CoinflowWithdraw = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var react_1 = tslib_1.__importDefault(require("react"));
|
|
6
|
+
var CoinflowIFrame_1 = require("./CoinflowIFrame");
|
|
7
|
+
var IFrameWalletConnector_1 = require("./IFrameWalletConnector");
|
|
8
|
+
function CoinflowWithdraw(_a) {
|
|
9
|
+
var wallet = _a.wallet, merchantId = _a.merchantId, env = _a.env, connection = _a.connection, onSuccess = _a.onSuccess;
|
|
10
|
+
var IFrameRef = (0, IFrameWalletConnector_1.useIframeWallet)({ wallet: wallet, connection: connection, onSuccess: onSuccess }).IFrameRef;
|
|
11
|
+
if (!wallet.publicKey || !wallet.connected)
|
|
12
|
+
return null;
|
|
13
|
+
return (react_1["default"].createElement(CoinflowIFrame_1.CoinflowIframe, { publicKey: wallet.publicKey.toString(), IFrameRef: IFrameRef, route: "/withdraw/".concat(merchantId), env: env }));
|
|
14
|
+
}
|
|
15
|
+
exports.CoinflowWithdraw = CoinflowWithdraw;
|
|
16
|
+
//# sourceMappingURL=CoinflowWithdraw.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CoinflowWithdraw.js","sourceRoot":"","sources":["../../src/CoinflowWithdraw.tsx"],"names":[],"mappings":";;;;AACA,wDAA0B;AAE1B,mDAA8D;AAC9D,iEAAyE;AAUzE,SAAgB,gBAAgB,CAAC,EAMzB;QALN,MAAM,YAAA,EACN,UAAU,gBAAA,EACV,GAAG,SAAA,EACH,UAAU,gBAAA,EACV,SAAS,eAAA;IAEF,IAAA,SAAS,GAAI,IAAA,uCAAe,EAAC,EAAC,MAAM,QAAA,EAAE,UAAU,YAAA,EAAE,SAAS,WAAA,EAAC,CAAC,UAApD,CAAqD;IAErE,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,MAAM,CAAC,SAAS;QAAE,OAAO,IAAI,CAAC;IAExD,OAAO,CACL,iCAAC,+BAAc,IACb,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,EACtC,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,oBAAa,UAAU,CAAE,EAChC,GAAG,EAAE,GAAG,GACR,CACH,CAAC;AACJ,CAAC;AAnBD,4CAmBC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Connection } from '@solana/web3.js';
|
|
3
|
+
import { WalletContextState } from '@solana/wallet-adapter-react';
|
|
4
|
+
export type WalletCall = {
|
|
5
|
+
method: string;
|
|
6
|
+
data: string;
|
|
7
|
+
};
|
|
8
|
+
export type OnSuccessMethod = (params: string) => void | Promise<void>;
|
|
9
|
+
type Props = {
|
|
10
|
+
wallet: WalletContextState;
|
|
11
|
+
connection: Connection;
|
|
12
|
+
onSuccess?: OnSuccessMethod;
|
|
13
|
+
};
|
|
14
|
+
export declare function useIframeWallet({ wallet, connection, onSuccess }: Props): {
|
|
15
|
+
IFrameRef: import("react").RefObject<HTMLIFrameElement>;
|
|
16
|
+
};
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
exports.useIframeWallet = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var react_1 = require("react");
|
|
6
|
+
var bs58_1 = tslib_1.__importDefault(require("bs58"));
|
|
7
|
+
var web3_js_1 = require("@solana/web3.js");
|
|
8
|
+
function useIframeWallet(_a) {
|
|
9
|
+
var _this = this;
|
|
10
|
+
var wallet = _a.wallet, connection = _a.connection, onSuccess = _a.onSuccess;
|
|
11
|
+
var IFrameRef = (0, react_1.useRef)(null);
|
|
12
|
+
var sendIFrameMessage = (0, react_1.useCallback)(function (message) {
|
|
13
|
+
var _a;
|
|
14
|
+
if (!((_a = IFrameRef === null || IFrameRef === void 0 ? void 0 : IFrameRef.current) === null || _a === void 0 ? void 0 : _a.contentWindow))
|
|
15
|
+
throw new Error('Iframe not defined');
|
|
16
|
+
IFrameRef.current.contentWindow.postMessage(message, '*');
|
|
17
|
+
}, [IFrameRef]);
|
|
18
|
+
var handleSignMessage = (0, react_1.useCallback)(function (_a) {
|
|
19
|
+
var data = _a.data;
|
|
20
|
+
return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
21
|
+
var signature;
|
|
22
|
+
return tslib_1.__generator(this, function (_b) {
|
|
23
|
+
switch (_b.label) {
|
|
24
|
+
case 0:
|
|
25
|
+
if (!wallet.signMessage)
|
|
26
|
+
return [2 /*return*/];
|
|
27
|
+
return [4 /*yield*/, wallet.signMessage(bs58_1["default"].decode(data))];
|
|
28
|
+
case 1:
|
|
29
|
+
signature = _b.sent();
|
|
30
|
+
sendIFrameMessage(bs58_1["default"].encode(signature));
|
|
31
|
+
return [2 /*return*/];
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}, [sendIFrameMessage, wallet]);
|
|
36
|
+
var handleSignTransaction = (0, react_1.useCallback)(function (_a) {
|
|
37
|
+
var data = _a.data;
|
|
38
|
+
return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
39
|
+
var tx, _b, signature;
|
|
40
|
+
return tslib_1.__generator(this, function (_c) {
|
|
41
|
+
switch (_c.label) {
|
|
42
|
+
case 0:
|
|
43
|
+
tx = web3_js_1.Transaction.from(bs58_1["default"].decode(data));
|
|
44
|
+
_b = tx;
|
|
45
|
+
return [4 /*yield*/, connection.getLatestBlockhash()];
|
|
46
|
+
case 1:
|
|
47
|
+
_b.recentBlockhash = (_c.sent()).blockhash;
|
|
48
|
+
return [4 /*yield*/, wallet.sendTransaction(tx, connection)];
|
|
49
|
+
case 2:
|
|
50
|
+
signature = _c.sent();
|
|
51
|
+
sendIFrameMessage(signature);
|
|
52
|
+
return [2 /*return*/];
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}, [connection, sendIFrameMessage, wallet]);
|
|
57
|
+
var handleIframeMessages = (0, react_1.useCallback)(function (_a) {
|
|
58
|
+
var data = _a.data;
|
|
59
|
+
return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
60
|
+
var parsedData, _b, e_1;
|
|
61
|
+
return tslib_1.__generator(this, function (_c) {
|
|
62
|
+
switch (_c.label) {
|
|
63
|
+
case 0:
|
|
64
|
+
_c.trys.push([0, 8, , 9]);
|
|
65
|
+
if (!wallet)
|
|
66
|
+
return [2 /*return*/];
|
|
67
|
+
parsedData = parseJSON(data);
|
|
68
|
+
if (!parsedData)
|
|
69
|
+
return [2 /*return*/];
|
|
70
|
+
_b = parsedData.method;
|
|
71
|
+
switch (_b) {
|
|
72
|
+
case 'signMessage': return [3 /*break*/, 1];
|
|
73
|
+
case 'sendTransaction': return [3 /*break*/, 3];
|
|
74
|
+
case 'success': return [3 /*break*/, 5];
|
|
75
|
+
}
|
|
76
|
+
return [3 /*break*/, 6];
|
|
77
|
+
case 1: return [4 /*yield*/, handleSignMessage(parsedData)];
|
|
78
|
+
case 2:
|
|
79
|
+
_c.sent();
|
|
80
|
+
return [3 /*break*/, 7];
|
|
81
|
+
case 3: return [4 /*yield*/, handleSignTransaction(parsedData)];
|
|
82
|
+
case 4:
|
|
83
|
+
_c.sent();
|
|
84
|
+
return [3 /*break*/, 7];
|
|
85
|
+
case 5:
|
|
86
|
+
{
|
|
87
|
+
if (onSuccess)
|
|
88
|
+
onSuccess(data);
|
|
89
|
+
return [3 /*break*/, 7];
|
|
90
|
+
}
|
|
91
|
+
_c.label = 6;
|
|
92
|
+
case 6:
|
|
93
|
+
{
|
|
94
|
+
throw new Error("Unsupported Wallet Method ".concat(parsedData.method, ", must be signMessage or signTransaction"));
|
|
95
|
+
}
|
|
96
|
+
_c.label = 7;
|
|
97
|
+
case 7: return [3 /*break*/, 9];
|
|
98
|
+
case 8:
|
|
99
|
+
e_1 = _c.sent();
|
|
100
|
+
console.error('handleIframeMessages', e_1);
|
|
101
|
+
sendIFrameMessage('ERROR');
|
|
102
|
+
return [3 /*break*/, 9];
|
|
103
|
+
case 9: return [2 /*return*/];
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
}, [
|
|
108
|
+
handleSignMessage,
|
|
109
|
+
handleSignTransaction,
|
|
110
|
+
onSuccess,
|
|
111
|
+
sendIFrameMessage,
|
|
112
|
+
wallet,
|
|
113
|
+
]);
|
|
114
|
+
(0, react_1.useEffect)(function () {
|
|
115
|
+
if (!window)
|
|
116
|
+
throw new Error('Window not defined');
|
|
117
|
+
window.onmessage = handleIframeMessages;
|
|
118
|
+
}, [handleIframeMessages]);
|
|
119
|
+
return { IFrameRef: IFrameRef };
|
|
120
|
+
}
|
|
121
|
+
exports.useIframeWallet = useIframeWallet;
|
|
122
|
+
function parseJSON(data) {
|
|
123
|
+
try {
|
|
124
|
+
var res = JSON.parse(data);
|
|
125
|
+
if (!res.method)
|
|
126
|
+
return null;
|
|
127
|
+
if (!res.data)
|
|
128
|
+
return null;
|
|
129
|
+
return res;
|
|
130
|
+
}
|
|
131
|
+
catch (e) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=IFrameWalletConnector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IFrameWalletConnector.js","sourceRoot":"","sources":["../../src/IFrameWalletConnector.ts"],"names":[],"mappings":";;;;AAAA,+BAAqD;AACrD,sDAA0B;AAC1B,2CAAwD;AAaxD,SAAgB,eAAe,CAAC,EAAsC;IAAtE,iBA8EC;QA9EgC,MAAM,YAAA,EAAE,UAAU,gBAAA,EAAE,SAAS,eAAA;IAC5D,IAAM,SAAS,GAAG,IAAA,cAAM,EAAoB,IAAI,CAAC,CAAC;IAElD,IAAM,iBAAiB,GAAG,IAAA,mBAAW,EACnC,UAAC,OAAe;;QACd,IAAI,CAAC,CAAA,MAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,OAAO,0CAAE,aAAa,CAAA;YACpC,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;QACxC,SAAS,CAAC,OAAO,CAAC,aAAa,CAAC,WAAW,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IAC5D,CAAC,EACD,CAAC,SAAS,CAAC,CACZ,CAAC;IAEF,IAAM,iBAAiB,GAAG,IAAA,mBAAW,EACnC,UAAO,EAAkB;YAAjB,IAAI,UAAA;;;;;;wBACV,IAAI,CAAC,MAAM,CAAC,WAAW;4BAAE,sBAAO;wBACd,qBAAM,MAAM,CAAC,WAAW,CAAC,iBAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,EAAA;;wBAAzD,SAAS,GAAG,SAA6C;wBAC/D,iBAAiB,CAAC,iBAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;;;;;KAC7C,EACD,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAC5B,CAAC;IAEF,IAAM,qBAAqB,GAAG,IAAA,mBAAW,EACvC,UAAO,EAAkB;YAAjB,IAAI,UAAA;;;;;;wBACJ,EAAE,GAAG,qBAAW,CAAC,IAA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9B,EACD;QACE,iBAAiB;QACjB,qBAAqB;QACrB,SAAS;QACT,iBAAiB;QACjB,MAAM;KACP,CACF,CAAC;IAEF,IAAA,iBAAS,EAAC;QACR,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;QACnD,MAAM,CAAC,SAAS,GAAG,oBAAoB,CAAC;IAC1C,CAAC,EAAE,CAAC,oBAAoB,CAAC,CAAC,CAAC;IAE3B,OAAO,EAAC,SAAS,WAAA,EAAC,CAAC;AACrB,CAAC;AA9ED,0CA8EC;AAED,SAAS,SAAS,CAAC,IAAY;IAC7B,IAAI;QACF,IAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC7B,IAAI,CAAC,GAAG,CAAC,MAAM;YAAE,OAAO,IAAI,CAAC;QAC7B,IAAI,CAAC,GAAG,CAAC,IAAI;YAAE,OAAO,IAAI,CAAC;QAC3B,OAAO,GAAG,CAAC;KACZ;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,IAAI,CAAC;KACb;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,6DAAmC;AACnC,6DAAmC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export type CoinflowEnvs = 'prod' | 'staging' | 'sandbox' | 'local';
|
|
3
|
+
type CoinflowIFrameProps = {
|
|
4
|
+
publicKey: string;
|
|
5
|
+
IFrameRef: React.RefObject<HTMLIFrameElement>;
|
|
6
|
+
env?: CoinflowEnvs;
|
|
7
|
+
route: string;
|
|
8
|
+
};
|
|
9
|
+
declare function CoinflowIFrame({ publicKey, IFrameRef, env, route, }: CoinflowIFrameProps): JSX.Element;
|
|
10
|
+
export declare const CoinflowIframe: React.MemoExoticComponent<typeof CoinflowIFrame>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
function getCoinflowUrl(env) {
|
|
3
|
+
if (!env || env === 'prod')
|
|
4
|
+
return 'https://coinflow.cash';
|
|
5
|
+
if (env === 'local')
|
|
6
|
+
return 'http://localhost:3000';
|
|
7
|
+
return "https://".concat(env, ".coinflow.cash");
|
|
8
|
+
}
|
|
9
|
+
function CoinflowIFrame(_a) {
|
|
10
|
+
var publicKey = _a.publicKey, IFrameRef = _a.IFrameRef, env = _a.env, route = _a.route;
|
|
11
|
+
var url = new URL(route, getCoinflowUrl(env));
|
|
12
|
+
url.searchParams.append('pubkey', publicKey);
|
|
13
|
+
return (React.createElement("iframe", { ref: IFrameRef, style: {
|
|
14
|
+
width: '100%',
|
|
15
|
+
height: '100%'
|
|
16
|
+
}, title: "withdraw", frameBorder: "0", src: url.toString() }));
|
|
17
|
+
}
|
|
18
|
+
export var CoinflowIframe = React.memo(CoinflowIFrame);
|
|
19
|
+
//# sourceMappingURL=CoinflowIFrame.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CoinflowIFrame.js","sourceRoot":"","sources":["../../src/CoinflowIFrame.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAW1B,SAAS,cAAc,CAAC,GAAkB;IACxC,IAAI,CAAC,GAAG,IAAI,GAAG,KAAK,MAAM;QAAE,OAAO,uBAAuB,CAAC;IAC3D,IAAI,GAAG,KAAK,OAAO;QAAE,OAAO,uBAAuB,CAAC;IAEpD,OAAO,kBAAW,GAAG,mBAAgB,CAAC;AACxC,CAAC;AAED,SAAS,cAAc,CAAC,EAKF;QAJpB,SAAS,eAAA,EACT,SAAS,eAAA,EACT,GAAG,SAAA,EACH,KAAK,WAAA;IAEL,IAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC;IAChD,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IAE7C,OAAO,CACL,gCACE,GAAG,EAAE,SAAS,EACd,KAAK,EAAE;YACL,KAAK,EAAE,MAAM;YACb,MAAM,EAAE,MAAM;SACf,EACD,KAAK,EAAC,UAAU,EAChB,WAAW,EAAC,GAAG,EACf,GAAG,EAAE,GAAG,CAAC,QAAQ,EAAE,GACnB,CACH,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,IAAM,cAAc,GAAG,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { WalletContextState } from '@solana/wallet-adapter-react';
|
|
3
|
+
import { Connection } from '@solana/web3.js';
|
|
4
|
+
import { CoinflowEnvs } from './CoinflowIFrame';
|
|
5
|
+
import { OnSuccessMethod } from './IFrameWalletConnector';
|
|
6
|
+
type Props = {
|
|
7
|
+
wallet: WalletContextState;
|
|
8
|
+
merchantId: string;
|
|
9
|
+
connection: Connection;
|
|
10
|
+
env?: CoinflowEnvs;
|
|
11
|
+
onSuccess?: OnSuccessMethod;
|
|
12
|
+
};
|
|
13
|
+
export declare function CoinflowPurchase({ wallet, merchantId, env, connection, onSuccess, }: Props): JSX.Element | null;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { CoinflowIframe } from './CoinflowIFrame';
|
|
3
|
+
import { useIframeWallet } from './IFrameWalletConnector';
|
|
4
|
+
export function CoinflowPurchase(_a) {
|
|
5
|
+
var wallet = _a.wallet, merchantId = _a.merchantId, env = _a.env, connection = _a.connection, onSuccess = _a.onSuccess;
|
|
6
|
+
var IFrameRef = useIframeWallet({ wallet: wallet, connection: connection, onSuccess: onSuccess }).IFrameRef;
|
|
7
|
+
if (!wallet.publicKey || !wallet.connected)
|
|
8
|
+
return null;
|
|
9
|
+
return (React.createElement(CoinflowIframe, { publicKey: wallet.publicKey.toString(), IFrameRef: IFrameRef, route: "/purchase/".concat(merchantId), env: env }));
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=CoinflowPurchase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CoinflowPurchase.js","sourceRoot":"","sources":["../../src/CoinflowPurchase.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAe,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAkB,eAAe,EAAC,MAAM,yBAAyB,CAAC;AAUzE,MAAM,UAAU,gBAAgB,CAAC,EAMzB;QALN,MAAM,YAAA,EACN,UAAU,gBAAA,EACV,GAAG,SAAA,EACH,UAAU,gBAAA,EACV,SAAS,eAAA;IAEF,IAAA,SAAS,GAAI,eAAe,CAAC,EAAC,MAAM,QAAA,EAAE,UAAU,YAAA,EAAE,SAAS,WAAA,EAAC,CAAC,UAApD,CAAqD;IAErE,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,MAAM,CAAC,SAAS;QAAE,OAAO,IAAI,CAAC;IAExD,OAAO,CACL,oBAAC,cAAc,IACb,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,EACtC,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,oBAAa,UAAU,CAAE,EAChC,GAAG,EAAE,GAAG,GACR,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { WalletContextState } from '@solana/wallet-adapter-react';
|
|
3
|
+
import { Connection } from '@solana/web3.js';
|
|
4
|
+
import { CoinflowEnvs } from './CoinflowIFrame';
|
|
5
|
+
import { OnSuccessMethod } from './IFrameWalletConnector';
|
|
6
|
+
type Props = {
|
|
7
|
+
wallet: WalletContextState;
|
|
8
|
+
merchantId: string;
|
|
9
|
+
connection: Connection;
|
|
10
|
+
env?: CoinflowEnvs;
|
|
11
|
+
onSuccess?: OnSuccessMethod;
|
|
12
|
+
};
|
|
13
|
+
export declare function CoinflowWithdraw({ wallet, merchantId, env, connection, onSuccess, }: Props): JSX.Element | null;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { CoinflowIframe } from './CoinflowIFrame';
|
|
3
|
+
import { useIframeWallet } from './IFrameWalletConnector';
|
|
4
|
+
export function CoinflowWithdraw(_a) {
|
|
5
|
+
var wallet = _a.wallet, merchantId = _a.merchantId, env = _a.env, connection = _a.connection, onSuccess = _a.onSuccess;
|
|
6
|
+
var IFrameRef = useIframeWallet({ wallet: wallet, connection: connection, onSuccess: onSuccess }).IFrameRef;
|
|
7
|
+
if (!wallet.publicKey || !wallet.connected)
|
|
8
|
+
return null;
|
|
9
|
+
return (React.createElement(CoinflowIframe, { publicKey: wallet.publicKey.toString(), IFrameRef: IFrameRef, route: "/withdraw/".concat(merchantId), env: env }));
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=CoinflowWithdraw.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CoinflowWithdraw.js","sourceRoot":"","sources":["../../src/CoinflowWithdraw.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAe,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAkB,eAAe,EAAC,MAAM,yBAAyB,CAAC;AAUzE,MAAM,UAAU,gBAAgB,CAAC,EAMzB;QALN,MAAM,YAAA,EACN,UAAU,gBAAA,EACV,GAAG,SAAA,EACH,UAAU,gBAAA,EACV,SAAS,eAAA;IAEF,IAAA,SAAS,GAAI,eAAe,CAAC,EAAC,MAAM,QAAA,EAAE,UAAU,YAAA,EAAE,SAAS,WAAA,EAAC,CAAC,UAApD,CAAqD;IAErE,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,MAAM,CAAC,SAAS;QAAE,OAAO,IAAI,CAAC;IAExD,OAAO,CACL,oBAAC,cAAc,IACb,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,EACtC,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,oBAAa,UAAU,CAAE,EAChC,GAAG,EAAE,GAAG,GACR,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Connection } from '@solana/web3.js';
|
|
3
|
+
import { WalletContextState } from '@solana/wallet-adapter-react';
|
|
4
|
+
export type WalletCall = {
|
|
5
|
+
method: string;
|
|
6
|
+
data: string;
|
|
7
|
+
};
|
|
8
|
+
export type OnSuccessMethod = (params: string) => void | Promise<void>;
|
|
9
|
+
type Props = {
|
|
10
|
+
wallet: WalletContextState;
|
|
11
|
+
connection: Connection;
|
|
12
|
+
onSuccess?: OnSuccessMethod;
|
|
13
|
+
};
|
|
14
|
+
export declare function useIframeWallet({ wallet, connection, onSuccess }: Props): {
|
|
15
|
+
IFrameRef: import("react").RefObject<HTMLIFrameElement>;
|
|
16
|
+
};
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { __awaiter, __generator } from "tslib";
|
|
2
|
+
import { useCallback, useEffect, useRef } from 'react';
|
|
3
|
+
import base58 from 'bs58';
|
|
4
|
+
import { Transaction } from '@solana/web3.js';
|
|
5
|
+
export function useIframeWallet(_a) {
|
|
6
|
+
var _this = this;
|
|
7
|
+
var wallet = _a.wallet, connection = _a.connection, onSuccess = _a.onSuccess;
|
|
8
|
+
var IFrameRef = useRef(null);
|
|
9
|
+
var sendIFrameMessage = useCallback(function (message) {
|
|
10
|
+
var _a;
|
|
11
|
+
if (!((_a = IFrameRef === null || IFrameRef === void 0 ? void 0 : IFrameRef.current) === null || _a === void 0 ? void 0 : _a.contentWindow))
|
|
12
|
+
throw new Error('Iframe not defined');
|
|
13
|
+
IFrameRef.current.contentWindow.postMessage(message, '*');
|
|
14
|
+
}, [IFrameRef]);
|
|
15
|
+
var handleSignMessage = useCallback(function (_a) {
|
|
16
|
+
var data = _a.data;
|
|
17
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
18
|
+
var signature;
|
|
19
|
+
return __generator(this, function (_b) {
|
|
20
|
+
switch (_b.label) {
|
|
21
|
+
case 0:
|
|
22
|
+
if (!wallet.signMessage)
|
|
23
|
+
return [2 /*return*/];
|
|
24
|
+
return [4 /*yield*/, wallet.signMessage(base58.decode(data))];
|
|
25
|
+
case 1:
|
|
26
|
+
signature = _b.sent();
|
|
27
|
+
sendIFrameMessage(base58.encode(signature));
|
|
28
|
+
return [2 /*return*/];
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
}, [sendIFrameMessage, wallet]);
|
|
33
|
+
var handleSignTransaction = useCallback(function (_a) {
|
|
34
|
+
var data = _a.data;
|
|
35
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
36
|
+
var tx, _b, signature;
|
|
37
|
+
return __generator(this, function (_c) {
|
|
38
|
+
switch (_c.label) {
|
|
39
|
+
case 0:
|
|
40
|
+
tx = Transaction.from(base58.decode(data));
|
|
41
|
+
_b = tx;
|
|
42
|
+
return [4 /*yield*/, connection.getLatestBlockhash()];
|
|
43
|
+
case 1:
|
|
44
|
+
_b.recentBlockhash = (_c.sent()).blockhash;
|
|
45
|
+
return [4 /*yield*/, wallet.sendTransaction(tx, connection)];
|
|
46
|
+
case 2:
|
|
47
|
+
signature = _c.sent();
|
|
48
|
+
sendIFrameMessage(signature);
|
|
49
|
+
return [2 /*return*/];
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}, [connection, sendIFrameMessage, wallet]);
|
|
54
|
+
var handleIframeMessages = useCallback(function (_a) {
|
|
55
|
+
var data = _a.data;
|
|
56
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
57
|
+
var parsedData, _b, e_1;
|
|
58
|
+
return __generator(this, function (_c) {
|
|
59
|
+
switch (_c.label) {
|
|
60
|
+
case 0:
|
|
61
|
+
_c.trys.push([0, 8, , 9]);
|
|
62
|
+
if (!wallet)
|
|
63
|
+
return [2 /*return*/];
|
|
64
|
+
parsedData = parseJSON(data);
|
|
65
|
+
if (!parsedData)
|
|
66
|
+
return [2 /*return*/];
|
|
67
|
+
_b = parsedData.method;
|
|
68
|
+
switch (_b) {
|
|
69
|
+
case 'signMessage': return [3 /*break*/, 1];
|
|
70
|
+
case 'sendTransaction': return [3 /*break*/, 3];
|
|
71
|
+
case 'success': return [3 /*break*/, 5];
|
|
72
|
+
}
|
|
73
|
+
return [3 /*break*/, 6];
|
|
74
|
+
case 1: return [4 /*yield*/, handleSignMessage(parsedData)];
|
|
75
|
+
case 2:
|
|
76
|
+
_c.sent();
|
|
77
|
+
return [3 /*break*/, 7];
|
|
78
|
+
case 3: return [4 /*yield*/, handleSignTransaction(parsedData)];
|
|
79
|
+
case 4:
|
|
80
|
+
_c.sent();
|
|
81
|
+
return [3 /*break*/, 7];
|
|
82
|
+
case 5:
|
|
83
|
+
{
|
|
84
|
+
if (onSuccess)
|
|
85
|
+
onSuccess(data);
|
|
86
|
+
return [3 /*break*/, 7];
|
|
87
|
+
}
|
|
88
|
+
_c.label = 6;
|
|
89
|
+
case 6:
|
|
90
|
+
{
|
|
91
|
+
throw new Error("Unsupported Wallet Method ".concat(parsedData.method, ", must be signMessage or signTransaction"));
|
|
92
|
+
}
|
|
93
|
+
_c.label = 7;
|
|
94
|
+
case 7: return [3 /*break*/, 9];
|
|
95
|
+
case 8:
|
|
96
|
+
e_1 = _c.sent();
|
|
97
|
+
console.error('handleIframeMessages', e_1);
|
|
98
|
+
sendIFrameMessage('ERROR');
|
|
99
|
+
return [3 /*break*/, 9];
|
|
100
|
+
case 9: return [2 /*return*/];
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}, [
|
|
105
|
+
handleSignMessage,
|
|
106
|
+
handleSignTransaction,
|
|
107
|
+
onSuccess,
|
|
108
|
+
sendIFrameMessage,
|
|
109
|
+
wallet,
|
|
110
|
+
]);
|
|
111
|
+
useEffect(function () {
|
|
112
|
+
if (!window)
|
|
113
|
+
throw new Error('Window not defined');
|
|
114
|
+
window.onmessage = handleIframeMessages;
|
|
115
|
+
}, [handleIframeMessages]);
|
|
116
|
+
return { IFrameRef: IFrameRef };
|
|
117
|
+
}
|
|
118
|
+
function parseJSON(data) {
|
|
119
|
+
try {
|
|
120
|
+
var res = JSON.parse(data);
|
|
121
|
+
if (!res.method)
|
|
122
|
+
return null;
|
|
123
|
+
if (!res.data)
|
|
124
|
+
return null;
|
|
125
|
+
return res;
|
|
126
|
+
}
|
|
127
|
+
catch (e) {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=IFrameWalletConnector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IFrameWalletConnector.js","sourceRoot":"","sources":["../../src/IFrameWalletConnector.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,WAAW,EAAE,SAAS,EAAE,MAAM,EAAC,MAAM,OAAO,CAAC;AACrD,OAAO,MAAM,MAAM,MAAM,CAAC;AAC1B,OAAO,EAAa,WAAW,EAAC,MAAM,iBAAiB,CAAC;AAaxD,MAAM,UAAU,eAAe,CAAC,EAAsC;IAAtE,iBA8EC;QA9EgC,MAAM,YAAA,EAAE,UAAU,gBAAA,EAAE,SAAS,eAAA;IAC5D,IAAM,SAAS,GAAG,MAAM,CAAoB,IAAI,CAAC,CAAC;IAElD,IAAM,iBAAiB,GAAG,WAAW,CACnC,UAAC,OAAe;;QACd,IAAI,CAAC,CAAA,MAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,OAAO,0CAAE,aAAa,CAAA;YACpC,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;QACxC,SAAS,CAAC,OAAO,CAAC,aAAa,CAAC,WAA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-0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@coinflowlabs/react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "React Component for Coinflow Withdraw",
|
|
5
|
+
"main": "./build/cjs/index.js",
|
|
6
|
+
"module": "./build/esm/index.js",
|
|
7
|
+
"types": "./build/esm/index.d.ts",
|
|
8
|
+
"license": "Apache-2.0",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"react",
|
|
11
|
+
"typescript",
|
|
12
|
+
"solana",
|
|
13
|
+
"web3"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"clean": "rimraf build",
|
|
17
|
+
"build": "npm run build:esm && npm run build:cjs",
|
|
18
|
+
"build:esm": "tsc",
|
|
19
|
+
"build:cjs": "tsc --module commonjs --outDir build/cjs"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"build",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"bs58": "^5.0.0",
|
|
27
|
+
"@solana/web3.js": "^1.66.2"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/react": "^18.0.25",
|
|
31
|
+
"eslint-config-react-app": "^7.0.1",
|
|
32
|
+
"react": "^18.2.0",
|
|
33
|
+
"react-dom": "^18.2.0",
|
|
34
|
+
"typescript": "^4.9.3"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"react": ">=16"
|
|
38
|
+
},
|
|
39
|
+
"eslintConfig": {
|
|
40
|
+
"extends": [
|
|
41
|
+
"react-app",
|
|
42
|
+
"react-app/jest"
|
|
43
|
+
]
|
|
44
|
+
},
|
|
45
|
+
"browserslist": {
|
|
46
|
+
"production": [
|
|
47
|
+
">0.2%",
|
|
48
|
+
"not dead",
|
|
49
|
+
"not op_mini all"
|
|
50
|
+
],
|
|
51
|
+
"development": [
|
|
52
|
+
"last 1 chrome version",
|
|
53
|
+
"last 1 firefox version",
|
|
54
|
+
"last 1 safari version"
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
}
|