@coinflowlabs/react 0.2.7 → 0.2.9
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 +4 -0
- package/build/cjs/CoinflowIFrame.d.ts +2 -3
- package/build/cjs/CoinflowIFrame.js +9 -22
- package/build/cjs/CoinflowIFrame.js.map +1 -1
- package/build/cjs/CoinflowPurchase.d.ts +4 -6
- package/build/cjs/CoinflowPurchase.js +2 -2
- package/build/cjs/CoinflowPurchase.js.map +1 -1
- package/build/cjs/CoinflowUtils.d.ts +13 -2
- package/build/cjs/CoinflowUtils.js +103 -6
- package/build/cjs/CoinflowUtils.js.map +1 -1
- package/build/cjs/CoinflowWithdraw.d.ts +4 -6
- package/build/cjs/CoinflowWithdraw.js +2 -2
- package/build/cjs/CoinflowWithdraw.js.map +1 -1
- package/build/cjs/IFrameWalletConnector.d.ts +7 -5
- package/build/cjs/IFrameWalletConnector.js +55 -28
- package/build/cjs/IFrameWalletConnector.js.map +1 -1
- package/build/cjs/index.d.ts +3 -0
- package/build/cjs/index.js +3 -0
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/useIframeWallet.d.ts +14 -0
- package/build/cjs/useIframeWallet.js +31 -0
- package/build/cjs/useIframeWallet.js.map +1 -0
- package/build/esm/CoinflowIFrame.d.ts +2 -3
- package/build/esm/CoinflowIFrame.js +9 -22
- package/build/esm/CoinflowIFrame.js.map +1 -1
- package/build/esm/CoinflowPurchase.d.ts +4 -6
- package/build/esm/CoinflowPurchase.js +1 -1
- package/build/esm/CoinflowPurchase.js.map +1 -1
- package/build/esm/CoinflowUtils.d.ts +13 -2
- package/build/esm/CoinflowUtils.js +103 -6
- package/build/esm/CoinflowUtils.js.map +1 -1
- package/build/esm/CoinflowWithdraw.d.ts +4 -6
- package/build/esm/CoinflowWithdraw.js +1 -1
- package/build/esm/CoinflowWithdraw.js.map +1 -1
- package/build/esm/IFrameWalletConnector.d.ts +7 -5
- package/build/esm/IFrameWalletConnector.js +54 -27
- package/build/esm/IFrameWalletConnector.js.map +1 -1
- package/build/esm/index.d.ts +3 -0
- package/build/esm/index.js +3 -0
- package/build/esm/index.js.map +1 -1
- package/build/esm/useIframeWallet.d.ts +14 -0
- package/build/esm/useIframeWallet.js +27 -0
- package/build/esm/useIframeWallet.js.map +1 -0
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Transaction } from '@solana/web3.js';
|
|
3
|
-
|
|
4
|
-
type CoinflowIFrameProps = {
|
|
3
|
+
import { CoinflowEnvs } from './CoinflowUtils';
|
|
4
|
+
export type CoinflowIFrameProps = {
|
|
5
5
|
publicKey: string;
|
|
6
6
|
IFrameRef: React.RefObject<HTMLIFrameElement>;
|
|
7
7
|
env?: CoinflowEnvs;
|
|
@@ -10,4 +10,3 @@ type CoinflowIFrameProps = {
|
|
|
10
10
|
transaction?: Transaction;
|
|
11
11
|
};
|
|
12
12
|
export declare function CoinflowIFrame({ publicKey, IFrameRef, env, route, transaction, amount, }: CoinflowIFrameProps): JSX.Element;
|
|
13
|
-
export {};
|
|
@@ -3,35 +3,22 @@ exports.__esModule = true;
|
|
|
3
3
|
exports.CoinflowIFrame = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var react_1 = tslib_1.__importStar(require("react"));
|
|
6
|
-
var
|
|
7
|
-
function getCoinflowUrl(env) {
|
|
8
|
-
if (!env || env === 'prod')
|
|
9
|
-
return 'https://coinflow.cash';
|
|
10
|
-
if (env === 'local')
|
|
11
|
-
return 'http://localhost:3000';
|
|
12
|
-
return "https://".concat(env, ".coinflow.cash");
|
|
13
|
-
}
|
|
6
|
+
var CoinflowUtils_1 = require("./CoinflowUtils");
|
|
14
7
|
function CoinflowIFrame(_a) {
|
|
15
8
|
var publicKey = _a.publicKey, IFrameRef = _a.IFrameRef, env = _a.env, route = _a.route, transaction = _a.transaction, amount = _a.amount;
|
|
16
9
|
var url = (0, react_1.useMemo)(function () {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
url.searchParams.append('transaction', serializedTx);
|
|
25
|
-
}
|
|
26
|
-
if (amount) {
|
|
27
|
-
url.searchParams.append('amount', amount.toString());
|
|
28
|
-
}
|
|
29
|
-
return url;
|
|
10
|
+
return CoinflowUtils_1.CoinflowUtils.getCoinflowUrl({
|
|
11
|
+
amount: amount,
|
|
12
|
+
env: env,
|
|
13
|
+
publicKey: publicKey,
|
|
14
|
+
route: route,
|
|
15
|
+
transaction: transaction
|
|
16
|
+
});
|
|
30
17
|
}, [amount, env, publicKey, route, transaction]);
|
|
31
18
|
return (0, react_1.useMemo)(function () { return (react_1["default"].createElement("iframe", { ref: IFrameRef, style: {
|
|
32
19
|
width: '100%',
|
|
33
20
|
height: '100%'
|
|
34
|
-
}, title: "withdraw", frameBorder: "0", src: url
|
|
21
|
+
}, title: "withdraw", frameBorder: "0", src: url })); }, [IFrameRef, url]);
|
|
35
22
|
}
|
|
36
23
|
exports.CoinflowIFrame = CoinflowIFrame;
|
|
37
24
|
//# sourceMappingURL=CoinflowIFrame.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CoinflowIFrame.js","sourceRoot":"","sources":["../../src/CoinflowIFrame.tsx"],"names":[],"mappings":";;;;AAAA,qDAAqC;AAErC,
|
|
1
|
+
{"version":3,"file":"CoinflowIFrame.js","sourceRoot":"","sources":["../../src/CoinflowIFrame.tsx"],"names":[],"mappings":";;;;AAAA,qDAAqC;AAErC,iDAA4D;AAW5D,SAAgB,cAAc,CAAC,EAOT;QANpB,SAAS,eAAA,EACT,SAAS,eAAA,EACT,GAAG,SAAA,EACH,KAAK,WAAA,EACL,WAAW,iBAAA,EACX,MAAM,YAAA;IAEN,IAAM,GAAG,GAAG,IAAA,eAAO,EAAC;QAClB,OAAO,6BAAa,CAAC,cAAc,CAAC;YAClC,MAAM,QAAA;YACN,GAAG,KAAA;YACH,SAAS,WAAA;YACT,KAAK,OAAA;YACL,WAAW,aAAA;SACZ,CAAC,CAAC;IACL,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC;IAEjD,OAAO,IAAA,eAAO,EACZ,cAAM,OAAA,CACJ,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,GACR,CACH,EAXK,CAWL,EACD,CAAC,SAAS,EAAE,GAAG,CAAC,CACjB,CAAC;AACJ,CAAC;AAjCD,wCAiCC"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { WalletContextState } from '@solana/wallet-adapter-react';
|
|
3
2
|
import { Connection, Signer, Transaction } from '@solana/web3.js';
|
|
4
|
-
import { CoinflowEnvs } from './CoinflowIFrame';
|
|
5
3
|
import { OnSuccessMethod } from './IFrameWalletConnector';
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
import { CoinflowEnvs, SubsetWalletContextState } from './CoinflowUtils';
|
|
5
|
+
export type CoinflowPurchaseProps = {
|
|
6
|
+
wallet: SubsetWalletContextState;
|
|
8
7
|
merchantId: string;
|
|
9
8
|
connection: Connection;
|
|
10
9
|
amount?: number;
|
|
@@ -14,5 +13,4 @@ type Props = {
|
|
|
14
13
|
partialSigners?: Signer[];
|
|
15
14
|
debugTx?: boolean;
|
|
16
15
|
};
|
|
17
|
-
export declare function CoinflowPurchase({ wallet, merchantId, env, connection, onSuccess, transaction, amount, partialSigners, debugTx, }:
|
|
18
|
-
export {};
|
|
16
|
+
export declare function CoinflowPurchase({ wallet, merchantId, env, connection, onSuccess, transaction, amount, partialSigners, debugTx, }: CoinflowPurchaseProps): JSX.Element | null;
|
|
@@ -4,10 +4,10 @@ exports.CoinflowPurchase = void 0;
|
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var react_1 = tslib_1.__importDefault(require("react"));
|
|
6
6
|
var CoinflowIFrame_1 = require("./CoinflowIFrame");
|
|
7
|
-
var
|
|
7
|
+
var useIframeWallet_1 = require("./useIframeWallet");
|
|
8
8
|
function CoinflowPurchase(_a) {
|
|
9
9
|
var wallet = _a.wallet, merchantId = _a.merchantId, env = _a.env, connection = _a.connection, onSuccess = _a.onSuccess, transaction = _a.transaction, amount = _a.amount, partialSigners = _a.partialSigners, _b = _a.debugTx, debugTx = _b === void 0 ? false : _b;
|
|
10
|
-
var IFrameRef = (0,
|
|
10
|
+
var IFrameRef = (0, useIframeWallet_1.useIframeWallet)({
|
|
11
11
|
wallet: wallet,
|
|
12
12
|
connection: connection,
|
|
13
13
|
onSuccess: onSuccess,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CoinflowPurchase.js","sourceRoot":"","sources":["../../src/CoinflowPurchase.tsx"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"CoinflowPurchase.js","sourceRoot":"","sources":["../../src/CoinflowPurchase.tsx"],"names":[],"mappings":";;;;AAAA,wDAA0B;AAE1B,mDAAgD;AAGhD,qDAAkD;AAclD,SAAgB,gBAAgB,CAAC,EAUT;QATtB,MAAM,YAAA,EACN,UAAU,gBAAA,EACV,GAAG,SAAA,EACH,UAAU,gBAAA,EACV,SAAS,eAAA,EACT,WAAW,iBAAA,EACX,MAAM,YAAA,EACN,cAAc,oBAAA,EACd,eAAe,EAAf,OAAO,mBAAG,KAAK,KAAA;IAER,IAAA,SAAS,GAAI,IAAA,iCAAe,EAAC;QAClC,MAAM,QAAA;QACN,UAAU,YAAA;QACV,SAAS,WAAA;QACT,cAAc,gBAAA;QACd,OAAO,SAAA;KACR,CAAC,UANc,CAMb;IAEH,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,EACR,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,MAAM,GACd,CACH,CAAC;AACJ,CAAC;AA/BD,4CA+BC"}
|
|
@@ -1,8 +1,19 @@
|
|
|
1
|
-
import { PublicKey } from '@solana/web3.js';
|
|
2
|
-
import {
|
|
1
|
+
import { Connection, PublicKey, Transaction } from '@solana/web3.js';
|
|
2
|
+
import { WalletContextState } from '@solana/wallet-adapter-react';
|
|
3
|
+
export type CoinflowEnvs = 'prod' | 'staging' | 'sandbox' | 'local';
|
|
4
|
+
export type SubsetWalletContextState = Pick<WalletContextState, 'signTransaction' | 'signMessage' | 'connected' | 'publicKey' | 'sendTransaction'>;
|
|
3
5
|
export declare class CoinflowUtils {
|
|
4
6
|
env: CoinflowEnvs;
|
|
5
7
|
url: string;
|
|
6
8
|
constructor(env?: CoinflowEnvs);
|
|
7
9
|
getFeePayer(): Promise<PublicKey>;
|
|
10
|
+
static getCoinflowBaseUrl(env?: CoinflowEnvs): string;
|
|
11
|
+
static getCoinflowUrl({ route, env, amount, publicKey, transaction, }: {
|
|
12
|
+
route: string;
|
|
13
|
+
publicKey: string;
|
|
14
|
+
env?: CoinflowEnvs;
|
|
15
|
+
amount?: number;
|
|
16
|
+
transaction?: Transaction;
|
|
17
|
+
}): string;
|
|
18
|
+
getCoinflowCreditsBalance(publicKey: PublicKey, connection: Connection): Promise<number>;
|
|
8
19
|
}
|
|
@@ -3,7 +3,8 @@ exports.__esModule = true;
|
|
|
3
3
|
exports.CoinflowUtils = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var web3_js_1 = require("@solana/web3.js");
|
|
6
|
-
var
|
|
6
|
+
var spl_token_1 = require("@solana/spl-token");
|
|
7
|
+
var bs58_1 = tslib_1.__importDefault(require("bs58"));
|
|
7
8
|
var CoinflowUtils = /** @class */ (function () {
|
|
8
9
|
function CoinflowUtils(env) {
|
|
9
10
|
this.env = env !== null && env !== void 0 ? env : 'prod';
|
|
@@ -16,13 +17,109 @@ var CoinflowUtils = /** @class */ (function () {
|
|
|
16
17
|
}
|
|
17
18
|
CoinflowUtils.prototype.getFeePayer = function () {
|
|
18
19
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
19
|
-
var
|
|
20
|
+
var response, _a;
|
|
21
|
+
return tslib_1.__generator(this, function (_b) {
|
|
22
|
+
switch (_b.label) {
|
|
23
|
+
case 0: return [4 /*yield*/, fetch(this.url + '/v1/redeem/fee-payer')];
|
|
24
|
+
case 1:
|
|
25
|
+
response = _b.sent();
|
|
26
|
+
_a = web3_js_1.PublicKey.bind;
|
|
27
|
+
return [4 /*yield*/, response.json()];
|
|
28
|
+
case 2: return [2 /*return*/, new (_a.apply(web3_js_1.PublicKey, [void 0, _b.sent()]))()];
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
CoinflowUtils.getCoinflowBaseUrl = function (env) {
|
|
34
|
+
if (!env || env === 'prod')
|
|
35
|
+
return 'https://coinflow.cash';
|
|
36
|
+
if (env === 'local')
|
|
37
|
+
return 'http://localhost:3000';
|
|
38
|
+
return "https://".concat(env, ".coinflow.cash");
|
|
39
|
+
};
|
|
40
|
+
CoinflowUtils.getCoinflowUrl = function (_a) {
|
|
41
|
+
var route = _a.route, env = _a.env, amount = _a.amount, publicKey = _a.publicKey, transaction = _a.transaction;
|
|
42
|
+
var url = new URL(route, CoinflowUtils.getCoinflowBaseUrl(env));
|
|
43
|
+
url.searchParams.append('pubkey', publicKey);
|
|
44
|
+
if (transaction) {
|
|
45
|
+
var serializedTx = bs58_1["default"].encode(transaction.serialize({
|
|
46
|
+
requireAllSignatures: false,
|
|
47
|
+
verifySignatures: false
|
|
48
|
+
}));
|
|
49
|
+
url.searchParams.append('transaction', serializedTx);
|
|
50
|
+
}
|
|
51
|
+
if (amount) {
|
|
52
|
+
url.searchParams.append('amount', amount.toString());
|
|
53
|
+
}
|
|
54
|
+
return url.toString();
|
|
55
|
+
};
|
|
56
|
+
CoinflowUtils.prototype.getCoinflowCreditsBalance = function (publicKey, connection) {
|
|
57
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
58
|
+
function getCreditBalance(wallet) {
|
|
59
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
60
|
+
var ataInfo;
|
|
61
|
+
return tslib_1.__generator(this, function (_a) {
|
|
62
|
+
switch (_a.label) {
|
|
63
|
+
case 0: return [4 /*yield*/, getCreditAtaInfo(wallet)];
|
|
64
|
+
case 1:
|
|
65
|
+
ataInfo = _a.sent();
|
|
66
|
+
if (!ataInfo)
|
|
67
|
+
return [2 /*return*/, 0];
|
|
68
|
+
return [2 /*return*/, Number(ataInfo.amount) / Math.pow(10, 6)];
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function getCreditAtaInfo(wallet) {
|
|
74
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
75
|
+
var ata, e_1;
|
|
76
|
+
return tslib_1.__generator(this, function (_a) {
|
|
77
|
+
switch (_a.label) {
|
|
78
|
+
case 0:
|
|
79
|
+
_a.trys.push([0, 3, , 4]);
|
|
80
|
+
return [4 /*yield*/, getCreditAtaAddress(wallet)];
|
|
81
|
+
case 1:
|
|
82
|
+
ata = _a.sent();
|
|
83
|
+
return [4 /*yield*/, (0, spl_token_1.getAccount)(connection, ata)];
|
|
84
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
85
|
+
case 3:
|
|
86
|
+
e_1 = _a.sent();
|
|
87
|
+
return [2 /*return*/, undefined];
|
|
88
|
+
case 4: return [2 /*return*/];
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
function getCreditAtaAddress(wallet) {
|
|
94
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
95
|
+
var _a;
|
|
96
|
+
return tslib_1.__generator(this, function (_b) {
|
|
97
|
+
switch (_b.label) {
|
|
98
|
+
case 0:
|
|
99
|
+
_a = spl_token_1.getAssociatedTokenAddress;
|
|
100
|
+
return [4 /*yield*/, creditsMint()];
|
|
101
|
+
case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent(), wallet])];
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
function creditsMint() {
|
|
107
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
108
|
+
return tslib_1.__generator(this, function (_a) {
|
|
109
|
+
switch (_a.label) {
|
|
110
|
+
case 0: return [4 /*yield*/, web3_js_1.PublicKey.findProgramAddress([Buffer.from('usdc-credits-mint-2')], new web3_js_1.PublicKey('FD1amxhTsDpwzoVX41dxp2ygAESURV2zdUACzxM1Dfw9'))];
|
|
111
|
+
case 1: return [2 /*return*/, (_a.sent())[0]];
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
}
|
|
20
116
|
return tslib_1.__generator(this, function (_a) {
|
|
21
117
|
switch (_a.label) {
|
|
22
|
-
case 0:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return [
|
|
118
|
+
case 0:
|
|
119
|
+
if (!publicKey)
|
|
120
|
+
return [2 /*return*/, 0];
|
|
121
|
+
return [4 /*yield*/, getCreditBalance(publicKey)];
|
|
122
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
26
123
|
}
|
|
27
124
|
});
|
|
28
125
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CoinflowUtils.js","sourceRoot":"","sources":["../../src/CoinflowUtils.ts"],"names":[],"mappings":";;;;AAAA,
|
|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AAW;;;;oCAEtB,qBAAM,mBAAS,CAAC,kBAAkB,CAChC,CAAC,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC,EACpC,IAAI,mBAAS,CAAC,8CAA8C,CAAC,CAC9D,EAAA;oCAJH,sBAAO,CACL,SAGC,CACF,CAAC,CAAC,CAAC,EAAC;;;;aACN;;;;wBA9BD,IAAI,CAAC,SAAS;4BAAE,sBAAO,CAAC,EAAC;wBAgClB,qBAAM,gBAAgB,CAAC,SAAS,CAAC,EAAA;4BAAxC,sBAAO,SAAiC,EAAC;;;;KAC1C;IACH,oBAAC;AAAD,CAAC,AA3FD,IA2FC;AA3FY,sCAAa"}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { WalletContextState } from '@solana/wallet-adapter-react';
|
|
3
2
|
import { Connection } from '@solana/web3.js';
|
|
4
|
-
import { CoinflowEnvs } from './
|
|
3
|
+
import { CoinflowEnvs, SubsetWalletContextState } from './CoinflowUtils';
|
|
5
4
|
import { OnSuccessMethod } from './IFrameWalletConnector';
|
|
6
|
-
type
|
|
7
|
-
wallet:
|
|
5
|
+
export type CoinflowWithdrawProps = {
|
|
6
|
+
wallet: SubsetWalletContextState;
|
|
8
7
|
merchantId: string;
|
|
9
8
|
connection: Connection;
|
|
10
9
|
env?: CoinflowEnvs;
|
|
11
10
|
onSuccess?: OnSuccessMethod;
|
|
12
11
|
};
|
|
13
|
-
export declare function CoinflowWithdraw({ wallet, merchantId, env, connection, onSuccess, }:
|
|
14
|
-
export {};
|
|
12
|
+
export declare function CoinflowWithdraw({ wallet, merchantId, env, connection, onSuccess, }: CoinflowWithdrawProps): JSX.Element | null;
|
|
@@ -4,10 +4,10 @@ exports.CoinflowWithdraw = void 0;
|
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var react_1 = tslib_1.__importDefault(require("react"));
|
|
6
6
|
var CoinflowIFrame_1 = require("./CoinflowIFrame");
|
|
7
|
-
var
|
|
7
|
+
var useIframeWallet_1 = require("./useIframeWallet");
|
|
8
8
|
function CoinflowWithdraw(_a) {
|
|
9
9
|
var wallet = _a.wallet, merchantId = _a.merchantId, env = _a.env, connection = _a.connection, onSuccess = _a.onSuccess;
|
|
10
|
-
var IFrameRef = (0,
|
|
10
|
+
var IFrameRef = (0, useIframeWallet_1.useIframeWallet)({ wallet: wallet, connection: connection, onSuccess: onSuccess }).IFrameRef;
|
|
11
11
|
if (!wallet.publicKey || !wallet.connected)
|
|
12
12
|
return null;
|
|
13
13
|
return (react_1["default"].createElement(CoinflowIFrame_1.CoinflowIFrame, { publicKey: wallet.publicKey.toString(), IFrameRef: IFrameRef, route: "/withdraw/".concat(merchantId), env: env }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CoinflowWithdraw.js","sourceRoot":"","sources":["../../src/CoinflowWithdraw.tsx"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"CoinflowWithdraw.js","sourceRoot":"","sources":["../../src/CoinflowWithdraw.tsx"],"names":[],"mappings":";;;;AAAA,wDAA0B;AAE1B,mDAAgD;AAGhD,qDAAkD;AAUlD,SAAgB,gBAAgB,CAAC,EAMT;QALtB,MAAM,YAAA,EACN,UAAU,gBAAA,EACV,GAAG,SAAA,EACH,UAAU,gBAAA,EACV,SAAS,eAAA;IAEF,IAAA,SAAS,GAAI,IAAA,iCAAe,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"}
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { Connection, Signer } from '@solana/web3.js';
|
|
3
|
-
import {
|
|
2
|
+
import { SubsetWalletContextState } from './CoinflowUtils';
|
|
4
3
|
export type WalletCall = {
|
|
5
4
|
method: string;
|
|
6
5
|
data: string;
|
|
7
6
|
};
|
|
8
7
|
export type OnSuccessMethod = (params: string) => void | Promise<void>;
|
|
9
8
|
type Props = {
|
|
10
|
-
wallet:
|
|
9
|
+
wallet: SubsetWalletContextState;
|
|
11
10
|
connection: Connection;
|
|
12
11
|
onSuccess?: OnSuccessMethod;
|
|
13
12
|
partialSigners?: Signer[];
|
|
14
13
|
debugTx?: boolean;
|
|
14
|
+
sendIFrameMessage: (message: string) => void;
|
|
15
15
|
};
|
|
16
|
-
export declare function
|
|
17
|
-
|
|
16
|
+
export declare function useHandleIFrameMessages({ wallet, connection, onSuccess, partialSigners, debugTx, sendIFrameMessage, }: Props): {
|
|
17
|
+
handleIframeMessages: ({ data }: {
|
|
18
|
+
data: string;
|
|
19
|
+
}) => Promise<void>;
|
|
18
20
|
};
|
|
19
21
|
export {};
|
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
exports.__esModule = true;
|
|
3
|
-
exports.
|
|
3
|
+
exports.useHandleIFrameMessages = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var react_1 = require("react");
|
|
6
6
|
var bs58_1 = tslib_1.__importDefault(require("bs58"));
|
|
7
7
|
var web3_js_1 = require("@solana/web3.js");
|
|
8
|
-
function
|
|
8
|
+
function useHandleIFrameMessages(_a) {
|
|
9
9
|
var _this = this;
|
|
10
|
-
var wallet = _a.wallet, connection = _a.connection, onSuccess = _a.onSuccess, partialSigners = _a.partialSigners, _b = _a.debugTx, debugTx = _b === void 0 ? false : _b;
|
|
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]);
|
|
10
|
+
var wallet = _a.wallet, connection = _a.connection, onSuccess = _a.onSuccess, partialSigners = _a.partialSigners, _b = _a.debugTx, debugTx = _b === void 0 ? false : _b, sendIFrameMessage = _a.sendIFrameMessage;
|
|
18
11
|
var handleSignMessage = (0, react_1.useCallback)(function (_a) {
|
|
19
12
|
var data = _a.data;
|
|
20
13
|
return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
@@ -94,6 +87,40 @@ function useIframeWallet(_a) {
|
|
|
94
87
|
sendTransactionDebug,
|
|
95
88
|
wallet,
|
|
96
89
|
]);
|
|
90
|
+
var handleSignTransaction = (0, react_1.useCallback)(function (_a) {
|
|
91
|
+
var data = _a.data;
|
|
92
|
+
return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
93
|
+
var tx, partiallySign, signedTransaction;
|
|
94
|
+
return tslib_1.__generator(this, function (_b) {
|
|
95
|
+
switch (_b.label) {
|
|
96
|
+
case 0:
|
|
97
|
+
if (!wallet.signTransaction) {
|
|
98
|
+
throw new Error('signTransaction is not supported by this wallet');
|
|
99
|
+
}
|
|
100
|
+
tx = web3_js_1.Transaction.from(bs58_1["default"].decode(data));
|
|
101
|
+
partiallySign = function (signer) {
|
|
102
|
+
var requiredSignatures = tx.signatures.map(function (sig) {
|
|
103
|
+
return sig.publicKey.toString();
|
|
104
|
+
});
|
|
105
|
+
var shouldSign = requiredSignatures.includes(signer.publicKey.toString());
|
|
106
|
+
if (shouldSign)
|
|
107
|
+
tx.partialSign(signer);
|
|
108
|
+
};
|
|
109
|
+
if (partialSigners) {
|
|
110
|
+
partialSigners.forEach(partiallySign);
|
|
111
|
+
}
|
|
112
|
+
return [4 /*yield*/, wallet.signTransaction(tx)];
|
|
113
|
+
case 1:
|
|
114
|
+
signedTransaction = _b.sent();
|
|
115
|
+
sendIFrameMessage(bs58_1["default"].encode(signedTransaction.serialize({
|
|
116
|
+
requireAllSignatures: false,
|
|
117
|
+
verifySignatures: false
|
|
118
|
+
})));
|
|
119
|
+
return [2 /*return*/];
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
}, [partialSigners, sendIFrameMessage, wallet]);
|
|
97
124
|
var handleIframeMessages = (0, react_1.useCallback)(function (_a) {
|
|
98
125
|
var data = _a.data;
|
|
99
126
|
return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
@@ -101,7 +128,7 @@ function useIframeWallet(_a) {
|
|
|
101
128
|
return tslib_1.__generator(this, function (_c) {
|
|
102
129
|
switch (_c.label) {
|
|
103
130
|
case 0:
|
|
104
|
-
_c.trys.push([0,
|
|
131
|
+
_c.trys.push([0, 10, , 11]);
|
|
105
132
|
if (!wallet)
|
|
106
133
|
return [2 /*return*/];
|
|
107
134
|
parsedData = parseJSON(data);
|
|
@@ -112,35 +139,40 @@ function useIframeWallet(_a) {
|
|
|
112
139
|
case 'signMessage': return [3 /*break*/, 1];
|
|
113
140
|
case 'sendTransaction': return [3 /*break*/, 3];
|
|
114
141
|
case 'success': return [3 /*break*/, 5];
|
|
142
|
+
case 'signTransaction': return [3 /*break*/, 6];
|
|
115
143
|
}
|
|
116
|
-
return [3 /*break*/,
|
|
144
|
+
return [3 /*break*/, 8];
|
|
117
145
|
case 1: return [4 /*yield*/, handleSignMessage(parsedData)];
|
|
118
146
|
case 2:
|
|
119
147
|
_c.sent();
|
|
120
|
-
return [3 /*break*/,
|
|
148
|
+
return [3 /*break*/, 9];
|
|
121
149
|
case 3: return [4 /*yield*/, handleSendTransaction(parsedData)];
|
|
122
150
|
case 4:
|
|
123
151
|
_c.sent();
|
|
124
|
-
return [3 /*break*/,
|
|
152
|
+
return [3 /*break*/, 9];
|
|
125
153
|
case 5:
|
|
126
154
|
{
|
|
127
155
|
if (onSuccess)
|
|
128
156
|
onSuccess(data);
|
|
129
|
-
return [3 /*break*/,
|
|
157
|
+
return [3 /*break*/, 9];
|
|
130
158
|
}
|
|
131
159
|
_c.label = 6;
|
|
132
|
-
case 6:
|
|
160
|
+
case 6: return [4 /*yield*/, handleSignTransaction(parsedData)];
|
|
161
|
+
case 7:
|
|
162
|
+
_c.sent();
|
|
163
|
+
return [3 /*break*/, 9];
|
|
164
|
+
case 8:
|
|
133
165
|
{
|
|
134
166
|
throw new Error("Unsupported Wallet Method ".concat(parsedData.method, ", must be signMessage or signTransaction"));
|
|
135
167
|
}
|
|
136
|
-
_c.label =
|
|
137
|
-
case
|
|
138
|
-
case
|
|
168
|
+
_c.label = 9;
|
|
169
|
+
case 9: return [3 /*break*/, 11];
|
|
170
|
+
case 10:
|
|
139
171
|
e_1 = _c.sent();
|
|
140
172
|
console.error('handleIframeMessages', e_1);
|
|
141
173
|
sendIFrameMessage('ERROR');
|
|
142
|
-
return [3 /*break*/,
|
|
143
|
-
case
|
|
174
|
+
return [3 /*break*/, 11];
|
|
175
|
+
case 11: return [2 /*return*/];
|
|
144
176
|
}
|
|
145
177
|
});
|
|
146
178
|
});
|
|
@@ -151,14 +183,9 @@ function useIframeWallet(_a) {
|
|
|
151
183
|
sendIFrameMessage,
|
|
152
184
|
wallet,
|
|
153
185
|
]);
|
|
154
|
-
|
|
155
|
-
if (!window)
|
|
156
|
-
throw new Error('Window not defined');
|
|
157
|
-
window.onmessage = handleIframeMessages;
|
|
158
|
-
}, [handleIframeMessages]);
|
|
159
|
-
return { IFrameRef: IFrameRef };
|
|
186
|
+
return { handleIframeMessages: handleIframeMessages };
|
|
160
187
|
}
|
|
161
|
-
exports.
|
|
188
|
+
exports.useHandleIFrameMessages = useHandleIFrameMessages;
|
|
162
189
|
function parseJSON(data) {
|
|
163
190
|
try {
|
|
164
191
|
var res = JSON.parse(data);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IFrameWalletConnector.js","sourceRoot":"","sources":["../../src/IFrameWalletConnector.ts"],"names":[],"mappings":";;;;AAAA,+
|
|
1
|
+
{"version":3,"file":"IFrameWalletConnector.js","sourceRoot":"","sources":["../../src/IFrameWalletConnector.ts"],"names":[],"mappings":";;;;AAAA,+BAAkC;AAClC,sDAA0B;AAC1B,2CAAgE;AAgBhE,SAAgB,uBAAuB,CAAC,EAOhC;IAPR,iBAqJC;QApJC,MAAM,YAAA,EACN,UAAU,gBAAA,EACV,SAAS,eAAA,EACT,cAAc,oBAAA,EACd,eAAe,EAAf,OAAO,mBAAG,KAAK,KAAA,EACf,iBAAiB,uBAAA;IAEjB,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,oBAAoB,GAAG,IAAA,mBAAW,EACtC,UAAO,EAAe;;;;;oBACpB,IAAI,CAAC,MAAM,CAAC,eAAe;wBACzB,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;oBAE7C,qBAAM,MAAM,CAAC,eAAe,CAAC,EAAE,CAAC,EAAA;;oBAA3C,QAAQ,GAAG,SAAgC;oBAC3C,YAAY,GAAG,QAAQ,CAAC,SAAS,EAAE,CAAC;oBACxB,qBAAM,UAAU,CAAC,kBAAkB,CAAC,YAAY,EAAE;4BAClE,aAAa,EAAE,IAAI;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,4 +4,7 @@ var tslib_1 = require("tslib");
|
|
|
4
4
|
tslib_1.__exportStar(require("./CoinflowWithdraw"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./CoinflowPurchase"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./CoinflowUtils"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./IFrameWalletConnector"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./useIframeWallet"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./CoinflowIFrame"), exports);
|
|
7
10
|
//# sourceMappingURL=index.js.map
|
package/build/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,6DAAmC;AACnC,6DAAmC;AACnC,0DAAgC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,6DAAmC;AACnC,6DAAmC;AACnC,0DAAgC;AAChC,kEAAwC;AACxC,4DAAkC;AAClC,2DAAiC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Connection, Signer } from '@solana/web3.js';
|
|
3
|
+
import { OnSuccessMethod } from './IFrameWalletConnector';
|
|
4
|
+
import { SubsetWalletContextState } from './CoinflowUtils';
|
|
5
|
+
export type IFrameWalletProps = {
|
|
6
|
+
wallet: SubsetWalletContextState;
|
|
7
|
+
connection: Connection;
|
|
8
|
+
onSuccess?: OnSuccessMethod;
|
|
9
|
+
partialSigners?: Signer[];
|
|
10
|
+
debugTx?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare function useIframeWallet({ wallet, connection, onSuccess, partialSigners, debugTx, }: IFrameWalletProps): {
|
|
13
|
+
IFrameRef: import("react").RefObject<HTMLIFrameElement>;
|
|
14
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
exports.useIframeWallet = void 0;
|
|
4
|
+
var react_1 = require("react");
|
|
5
|
+
var IFrameWalletConnector_1 = require("./IFrameWalletConnector");
|
|
6
|
+
function useIframeWallet(_a) {
|
|
7
|
+
var wallet = _a.wallet, connection = _a.connection, onSuccess = _a.onSuccess, partialSigners = _a.partialSigners, _b = _a.debugTx, debugTx = _b === void 0 ? false : _b;
|
|
8
|
+
var IFrameRef = (0, react_1.useRef)(null);
|
|
9
|
+
var sendIFrameMessage = (0, react_1.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 handleIframeMessages = (0, IFrameWalletConnector_1.useHandleIFrameMessages)({
|
|
16
|
+
wallet: wallet,
|
|
17
|
+
connection: connection,
|
|
18
|
+
onSuccess: onSuccess,
|
|
19
|
+
partialSigners: partialSigners,
|
|
20
|
+
debugTx: debugTx,
|
|
21
|
+
sendIFrameMessage: sendIFrameMessage
|
|
22
|
+
}).handleIframeMessages;
|
|
23
|
+
(0, react_1.useEffect)(function () {
|
|
24
|
+
if (!window)
|
|
25
|
+
throw new Error('Window not defined');
|
|
26
|
+
window.onmessage = handleIframeMessages;
|
|
27
|
+
}, [handleIframeMessages]);
|
|
28
|
+
return { IFrameRef: IFrameRef };
|
|
29
|
+
}
|
|
30
|
+
exports.useIframeWallet = useIframeWallet;
|
|
31
|
+
//# sourceMappingURL=useIframeWallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIframeWallet.js","sourceRoot":"","sources":["../../src/useIframeWallet.ts"],"names":[],"mappings":";;;AAAA,+BAAqD;AAErD,iEAGiC;AAWjC,SAAgB,eAAe,CAAC,EAMZ;QALlB,MAAM,YAAA,EACN,UAAU,gBAAA,EACV,SAAS,eAAA,EACT,cAAc,oBAAA,EACd,eAAe,EAAf,OAAO,mBAAG,KAAK,KAAA;IAEf,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;IAEK,IAAA,oBAAoB,GAAI,IAAA,+CAAuB,EAAC;QACrD,MAAM,QAAA;QACN,UAAU,YAAA;QACV,SAAS,WAAA;QACT,cAAc,gBAAA;QACd,OAAO,SAAA;QACP,iBAAiB,mBAAA;KAClB,CAAC,qBAPyB,CAOxB;IAEH,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;AAjCD,0CAiCC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Transaction } from '@solana/web3.js';
|
|
3
|
-
|
|
4
|
-
type CoinflowIFrameProps = {
|
|
3
|
+
import { CoinflowEnvs } from './CoinflowUtils';
|
|
4
|
+
export type CoinflowIFrameProps = {
|
|
5
5
|
publicKey: string;
|
|
6
6
|
IFrameRef: React.RefObject<HTMLIFrameElement>;
|
|
7
7
|
env?: CoinflowEnvs;
|
|
@@ -10,4 +10,3 @@ type CoinflowIFrameProps = {
|
|
|
10
10
|
transaction?: Transaction;
|
|
11
11
|
};
|
|
12
12
|
export declare function CoinflowIFrame({ publicKey, IFrameRef, env, route, transaction, amount, }: CoinflowIFrameProps): JSX.Element;
|
|
13
|
-
export {};
|
|
@@ -1,32 +1,19 @@
|
|
|
1
1
|
import React, { useMemo } from 'react';
|
|
2
|
-
import
|
|
3
|
-
function getCoinflowUrl(env) {
|
|
4
|
-
if (!env || env === 'prod')
|
|
5
|
-
return 'https://coinflow.cash';
|
|
6
|
-
if (env === 'local')
|
|
7
|
-
return 'http://localhost:3000';
|
|
8
|
-
return "https://".concat(env, ".coinflow.cash");
|
|
9
|
-
}
|
|
2
|
+
import { CoinflowUtils } from './CoinflowUtils';
|
|
10
3
|
export function CoinflowIFrame(_a) {
|
|
11
4
|
var publicKey = _a.publicKey, IFrameRef = _a.IFrameRef, env = _a.env, route = _a.route, transaction = _a.transaction, amount = _a.amount;
|
|
12
5
|
var url = useMemo(function () {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
url.searchParams.append('transaction', serializedTx);
|
|
21
|
-
}
|
|
22
|
-
if (amount) {
|
|
23
|
-
url.searchParams.append('amount', amount.toString());
|
|
24
|
-
}
|
|
25
|
-
return url;
|
|
6
|
+
return CoinflowUtils.getCoinflowUrl({
|
|
7
|
+
amount: amount,
|
|
8
|
+
env: env,
|
|
9
|
+
publicKey: publicKey,
|
|
10
|
+
route: route,
|
|
11
|
+
transaction: transaction
|
|
12
|
+
});
|
|
26
13
|
}, [amount, env, publicKey, route, transaction]);
|
|
27
14
|
return useMemo(function () { return (React.createElement("iframe", { ref: IFrameRef, style: {
|
|
28
15
|
width: '100%',
|
|
29
16
|
height: '100%'
|
|
30
|
-
}, title: "withdraw", frameBorder: "0", src: url
|
|
17
|
+
}, title: "withdraw", frameBorder: "0", src: url })); }, [IFrameRef, url]);
|
|
31
18
|
}
|
|
32
19
|
//# sourceMappingURL=CoinflowIFrame.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CoinflowIFrame.js","sourceRoot":"","sources":["../../src/CoinflowIFrame.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAErC,OAAO,
|
|
1
|
+
{"version":3,"file":"CoinflowIFrame.js","sourceRoot":"","sources":["../../src/CoinflowIFrame.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAErC,OAAO,EAAe,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAW5D,MAAM,UAAU,cAAc,CAAC,EAOT;QANpB,SAAS,eAAA,EACT,SAAS,eAAA,EACT,GAAG,SAAA,EACH,KAAK,WAAA,EACL,WAAW,iBAAA,EACX,MAAM,YAAA;IAEN,IAAM,GAAG,GAAG,OAAO,CAAC;QAClB,OAAO,aAAa,CAAC,cAAc,CAAC;YAClC,MAAM,QAAA;YACN,GAAG,KAAA;YACH,SAAS,WAAA;YACT,KAAK,OAAA;YACL,WAAW,aAAA;SACZ,CAAC,CAAC;IACL,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC;IAEjD,OAAO,OAAO,CACZ,cAAM,OAAA,CACJ,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,GACR,CACH,EAXK,CAWL,EACD,CAAC,SAAS,EAAE,GAAG,CAAC,CACjB,CAAC;AACJ,CAAC"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { WalletContextState } from '@solana/wallet-adapter-react';
|
|
3
2
|
import { Connection, Signer, Transaction } from '@solana/web3.js';
|
|
4
|
-
import { CoinflowEnvs } from './CoinflowIFrame';
|
|
5
3
|
import { OnSuccessMethod } from './IFrameWalletConnector';
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
import { CoinflowEnvs, SubsetWalletContextState } from './CoinflowUtils';
|
|
5
|
+
export type CoinflowPurchaseProps = {
|
|
6
|
+
wallet: SubsetWalletContextState;
|
|
8
7
|
merchantId: string;
|
|
9
8
|
connection: Connection;
|
|
10
9
|
amount?: number;
|
|
@@ -14,5 +13,4 @@ type Props = {
|
|
|
14
13
|
partialSigners?: Signer[];
|
|
15
14
|
debugTx?: boolean;
|
|
16
15
|
};
|
|
17
|
-
export declare function CoinflowPurchase({ wallet, merchantId, env, connection, onSuccess, transaction, amount, partialSigners, debugTx, }:
|
|
18
|
-
export {};
|
|
16
|
+
export declare function CoinflowPurchase({ wallet, merchantId, env, connection, onSuccess, transaction, amount, partialSigners, debugTx, }: CoinflowPurchaseProps): JSX.Element | null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { CoinflowIFrame } from './CoinflowIFrame';
|
|
3
|
-
import { useIframeWallet } from './
|
|
3
|
+
import { useIframeWallet } from './useIframeWallet';
|
|
4
4
|
export function CoinflowPurchase(_a) {
|
|
5
5
|
var wallet = _a.wallet, merchantId = _a.merchantId, env = _a.env, connection = _a.connection, onSuccess = _a.onSuccess, transaction = _a.transaction, amount = _a.amount, partialSigners = _a.partialSigners, _b = _a.debugTx, debugTx = _b === void 0 ? false : _b;
|
|
6
6
|
var IFrameRef = useIframeWallet({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CoinflowPurchase.js","sourceRoot":"","sources":["../../src/CoinflowPurchase.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CoinflowPurchase.js","sourceRoot":"","sources":["../../src/CoinflowPurchase.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAGhD,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAclD,MAAM,UAAU,gBAAgB,CAAC,EAUT;QATtB,MAAM,YAAA,EACN,UAAU,gBAAA,EACV,GAAG,SAAA,EACH,UAAU,gBAAA,EACV,SAAS,eAAA,EACT,WAAW,iBAAA,EACX,MAAM,YAAA,EACN,cAAc,oBAAA,EACd,eAAe,EAAf,OAAO,mBAAG,KAAK,KAAA;IAER,IAAA,SAAS,GAAI,eAAe,CAAC;QAClC,MAAM,QAAA;QACN,UAAU,YAAA;QACV,SAAS,WAAA;QACT,cAAc,gBAAA;QACd,OAAO,SAAA;KACR,CAAC,UANc,CAMb;IAEH,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,EACR,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,MAAM,GACd,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -1,8 +1,19 @@
|
|
|
1
|
-
import { PublicKey } from '@solana/web3.js';
|
|
2
|
-
import {
|
|
1
|
+
import { Connection, PublicKey, Transaction } from '@solana/web3.js';
|
|
2
|
+
import { WalletContextState } from '@solana/wallet-adapter-react';
|
|
3
|
+
export type CoinflowEnvs = 'prod' | 'staging' | 'sandbox' | 'local';
|
|
4
|
+
export type SubsetWalletContextState = Pick<WalletContextState, 'signTransaction' | 'signMessage' | 'connected' | 'publicKey' | 'sendTransaction'>;
|
|
3
5
|
export declare class CoinflowUtils {
|
|
4
6
|
env: CoinflowEnvs;
|
|
5
7
|
url: string;
|
|
6
8
|
constructor(env?: CoinflowEnvs);
|
|
7
9
|
getFeePayer(): Promise<PublicKey>;
|
|
10
|
+
static getCoinflowBaseUrl(env?: CoinflowEnvs): string;
|
|
11
|
+
static getCoinflowUrl({ route, env, amount, publicKey, transaction, }: {
|
|
12
|
+
route: string;
|
|
13
|
+
publicKey: string;
|
|
14
|
+
env?: CoinflowEnvs;
|
|
15
|
+
amount?: number;
|
|
16
|
+
transaction?: Transaction;
|
|
17
|
+
}): string;
|
|
18
|
+
getCoinflowCreditsBalance(publicKey: PublicKey, connection: Connection): Promise<number>;
|
|
8
19
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { __awaiter, __generator } from "tslib";
|
|
2
2
|
import { PublicKey } from '@solana/web3.js';
|
|
3
|
-
import
|
|
3
|
+
import { getAccount, getAssociatedTokenAddress, } from '@solana/spl-token';
|
|
4
|
+
import base58 from 'bs58';
|
|
4
5
|
var CoinflowUtils = /** @class */ (function () {
|
|
5
6
|
function CoinflowUtils(env) {
|
|
6
7
|
this.env = env !== null && env !== void 0 ? env : 'prod';
|
|
@@ -13,13 +14,109 @@ var CoinflowUtils = /** @class */ (function () {
|
|
|
13
14
|
}
|
|
14
15
|
CoinflowUtils.prototype.getFeePayer = function () {
|
|
15
16
|
return __awaiter(this, void 0, void 0, function () {
|
|
16
|
-
var
|
|
17
|
+
var response, _a;
|
|
18
|
+
return __generator(this, function (_b) {
|
|
19
|
+
switch (_b.label) {
|
|
20
|
+
case 0: return [4 /*yield*/, fetch(this.url + '/v1/redeem/fee-payer')];
|
|
21
|
+
case 1:
|
|
22
|
+
response = _b.sent();
|
|
23
|
+
_a = PublicKey.bind;
|
|
24
|
+
return [4 /*yield*/, response.json()];
|
|
25
|
+
case 2: return [2 /*return*/, new (_a.apply(PublicKey, [void 0, _b.sent()]))()];
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
CoinflowUtils.getCoinflowBaseUrl = function (env) {
|
|
31
|
+
if (!env || env === 'prod')
|
|
32
|
+
return 'https://coinflow.cash';
|
|
33
|
+
if (env === 'local')
|
|
34
|
+
return 'http://localhost:3000';
|
|
35
|
+
return "https://".concat(env, ".coinflow.cash");
|
|
36
|
+
};
|
|
37
|
+
CoinflowUtils.getCoinflowUrl = function (_a) {
|
|
38
|
+
var route = _a.route, env = _a.env, amount = _a.amount, publicKey = _a.publicKey, transaction = _a.transaction;
|
|
39
|
+
var url = new URL(route, CoinflowUtils.getCoinflowBaseUrl(env));
|
|
40
|
+
url.searchParams.append('pubkey', publicKey);
|
|
41
|
+
if (transaction) {
|
|
42
|
+
var serializedTx = base58.encode(transaction.serialize({
|
|
43
|
+
requireAllSignatures: false,
|
|
44
|
+
verifySignatures: false
|
|
45
|
+
}));
|
|
46
|
+
url.searchParams.append('transaction', serializedTx);
|
|
47
|
+
}
|
|
48
|
+
if (amount) {
|
|
49
|
+
url.searchParams.append('amount', amount.toString());
|
|
50
|
+
}
|
|
51
|
+
return url.toString();
|
|
52
|
+
};
|
|
53
|
+
CoinflowUtils.prototype.getCoinflowCreditsBalance = function (publicKey, connection) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
55
|
+
function getCreditBalance(wallet) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
57
|
+
var ataInfo;
|
|
58
|
+
return __generator(this, function (_a) {
|
|
59
|
+
switch (_a.label) {
|
|
60
|
+
case 0: return [4 /*yield*/, getCreditAtaInfo(wallet)];
|
|
61
|
+
case 1:
|
|
62
|
+
ataInfo = _a.sent();
|
|
63
|
+
if (!ataInfo)
|
|
64
|
+
return [2 /*return*/, 0];
|
|
65
|
+
return [2 /*return*/, Number(ataInfo.amount) / Math.pow(10, 6)];
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
function getCreditAtaInfo(wallet) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
72
|
+
var ata, e_1;
|
|
73
|
+
return __generator(this, function (_a) {
|
|
74
|
+
switch (_a.label) {
|
|
75
|
+
case 0:
|
|
76
|
+
_a.trys.push([0, 3, , 4]);
|
|
77
|
+
return [4 /*yield*/, getCreditAtaAddress(wallet)];
|
|
78
|
+
case 1:
|
|
79
|
+
ata = _a.sent();
|
|
80
|
+
return [4 /*yield*/, getAccount(connection, ata)];
|
|
81
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
82
|
+
case 3:
|
|
83
|
+
e_1 = _a.sent();
|
|
84
|
+
return [2 /*return*/, undefined];
|
|
85
|
+
case 4: return [2 /*return*/];
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
function getCreditAtaAddress(wallet) {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
92
|
+
var _a;
|
|
93
|
+
return __generator(this, function (_b) {
|
|
94
|
+
switch (_b.label) {
|
|
95
|
+
case 0:
|
|
96
|
+
_a = getAssociatedTokenAddress;
|
|
97
|
+
return [4 /*yield*/, creditsMint()];
|
|
98
|
+
case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent(), wallet])];
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
function creditsMint() {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
105
|
+
return __generator(this, function (_a) {
|
|
106
|
+
switch (_a.label) {
|
|
107
|
+
case 0: return [4 /*yield*/, PublicKey.findProgramAddress([Buffer.from('usdc-credits-mint-2')], new PublicKey('FD1amxhTsDpwzoVX41dxp2ygAESURV2zdUACzxM1Dfw9'))];
|
|
108
|
+
case 1: return [2 /*return*/, (_a.sent())[0]];
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
}
|
|
17
113
|
return __generator(this, function (_a) {
|
|
18
114
|
switch (_a.label) {
|
|
19
|
-
case 0:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return [
|
|
115
|
+
case 0:
|
|
116
|
+
if (!publicKey)
|
|
117
|
+
return [2 /*return*/, 0];
|
|
118
|
+
return [4 /*yield*/, getCreditBalance(publicKey)];
|
|
119
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
23
120
|
}
|
|
24
121
|
});
|
|
25
122
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CoinflowUtils.js","sourceRoot":"","sources":["../../src/CoinflowUtils.ts"],"names":[],"mappings":";AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"CoinflowUtils.js","sourceRoot":"","sources":["../../src/CoinflowUtils.ts"],"names":[],"mappings":";AAAA,OAAO,EAAa,SAAS,EAAc,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAEL,UAAU,EACV,yBAAyB,GAC1B,MAAM,mBAAmB,CAAC;AAE3B,OAAO,MAAM,MAAM,MAAM,CAAC;AAY1B;IAIE,uBAAY,GAAkB;QAC5B,IAAI,CAAC,GAAG,GAAG,GAAG,aAAH,GAAG,cAAH,GAAG,GAAI,MAAM,CAAC;QACzB,IAAI,IAAI,CAAC,GAAG,KAAK,MAAM;YAAE,IAAI,CAAC,GAAG,GAAG,2BAA2B,CAAC;aAC3D,IAAI,IAAI,CAAC,GAAG,KAAK,OAAO;YAAE,IAAI,CAAC,GAAG,GAAG,uBAAuB,CAAC;;YAC7D,IAAI,CAAC,GAAG,GAAG,sBAAe,IAAI,CAAC,GAAG,mBAAgB,CAAC;IAC1D,CAAC;IAEK,mCAAW,GAAjB;;;;;4BACmB,qBAAM,KAAK,CAAC,IAAI,CAAC,GAAG,GAAG,sBAAsB,CAAC,EAAA;;wBAAzD,QAAQ,GAAG,SAA8C;6BACpD,SAAS;wBAAC,qBAAM,QAAQ,CAAC,IAAI,EAAE,EAAA;4BAA1C,sBAAO,cAAI,SAAS,WAAC,SAAqB,KAAC,EAAC;;;;KAC7C;IAEM,gCAAkB,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AAE,EAAE,CAAC,CAAC,EAAC;;;;aACjD;YAED,SAAe,gBAAgB,CAC7B,MAAiB;;;;;;;gCAGH,qBAAM,mBAAmB,CAAC,MAAM,CAAC,EAAA;;gCAAvC,GAAG,GAAG,SAAiC;gCACtC,qBAAM,UAAU,CAAC,UAAU,EAAE,GAAG,CAAC,EAAA;oCAAxC,sBAAO,SAAiC,EAAC;;;gCAEzC,sBAAO,SAAS,EAAC;;;;;aAEpB;YAED,SAAe,mBAAmB,CAAC,MAAiB;;;;;;gCAC3C,KAAA,yBAAyB,CAAA;gCAAC,qBAAM,WAAW,EAAE,EAAA;oCAApD,sBAAO,kBAA0B,SAAmB,EAAE,MAAM,EAAC,EAAC;;;;aAC/D;YAED,SAAe,WAAW;;;;oCAEtB,qBAAM,SAAS,CAAC,kBAAkB,CAChC,CAAC,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC,EACpC,IAAI,SAAS,CAAC,8CAA8C,CAAC,CAC9D,EAAA;oCAJH,sBAAO,CACL,SAGC,CACF,CAAC,CAAC,CAAC,EAAC;;;;aACN;;;;wBA9BD,IAAI,CAAC,SAAS;4BAAE,sBAAO,CAAC,EAAC;wBAgClB,qBAAM,gBAAgB,CAAC,SAAS,CAAC,EAAA;4BAAxC,sBAAO,SAAiC,EAAC;;;;KAC1C;IACH,oBAAC;AAAD,CAAC,AA3FD,IA2FC"}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { WalletContextState } from '@solana/wallet-adapter-react';
|
|
3
2
|
import { Connection } from '@solana/web3.js';
|
|
4
|
-
import { CoinflowEnvs } from './
|
|
3
|
+
import { CoinflowEnvs, SubsetWalletContextState } from './CoinflowUtils';
|
|
5
4
|
import { OnSuccessMethod } from './IFrameWalletConnector';
|
|
6
|
-
type
|
|
7
|
-
wallet:
|
|
5
|
+
export type CoinflowWithdrawProps = {
|
|
6
|
+
wallet: SubsetWalletContextState;
|
|
8
7
|
merchantId: string;
|
|
9
8
|
connection: Connection;
|
|
10
9
|
env?: CoinflowEnvs;
|
|
11
10
|
onSuccess?: OnSuccessMethod;
|
|
12
11
|
};
|
|
13
|
-
export declare function CoinflowWithdraw({ wallet, merchantId, env, connection, onSuccess, }:
|
|
14
|
-
export {};
|
|
12
|
+
export declare function CoinflowWithdraw({ wallet, merchantId, env, connection, onSuccess, }: CoinflowWithdrawProps): JSX.Element | null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { CoinflowIFrame } from './CoinflowIFrame';
|
|
3
|
-
import { useIframeWallet } from './
|
|
3
|
+
import { useIframeWallet } from './useIframeWallet';
|
|
4
4
|
export function CoinflowWithdraw(_a) {
|
|
5
5
|
var wallet = _a.wallet, merchantId = _a.merchantId, env = _a.env, connection = _a.connection, onSuccess = _a.onSuccess;
|
|
6
6
|
var IFrameRef = useIframeWallet({ wallet: wallet, connection: connection, onSuccess: onSuccess }).IFrameRef;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CoinflowWithdraw.js","sourceRoot":"","sources":["../../src/CoinflowWithdraw.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CoinflowWithdraw.js","sourceRoot":"","sources":["../../src/CoinflowWithdraw.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAGhD,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAUlD,MAAM,UAAU,gBAAgB,CAAC,EAMT;QALtB,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"}
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { Connection, Signer } from '@solana/web3.js';
|
|
3
|
-
import {
|
|
2
|
+
import { SubsetWalletContextState } from './CoinflowUtils';
|
|
4
3
|
export type WalletCall = {
|
|
5
4
|
method: string;
|
|
6
5
|
data: string;
|
|
7
6
|
};
|
|
8
7
|
export type OnSuccessMethod = (params: string) => void | Promise<void>;
|
|
9
8
|
type Props = {
|
|
10
|
-
wallet:
|
|
9
|
+
wallet: SubsetWalletContextState;
|
|
11
10
|
connection: Connection;
|
|
12
11
|
onSuccess?: OnSuccessMethod;
|
|
13
12
|
partialSigners?: Signer[];
|
|
14
13
|
debugTx?: boolean;
|
|
14
|
+
sendIFrameMessage: (message: string) => void;
|
|
15
15
|
};
|
|
16
|
-
export declare function
|
|
17
|
-
|
|
16
|
+
export declare function useHandleIFrameMessages({ wallet, connection, onSuccess, partialSigners, debugTx, sendIFrameMessage, }: Props): {
|
|
17
|
+
handleIframeMessages: ({ data }: {
|
|
18
|
+
data: string;
|
|
19
|
+
}) => Promise<void>;
|
|
18
20
|
};
|
|
19
21
|
export {};
|
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
import { __awaiter, __generator } from "tslib";
|
|
2
|
-
import { useCallback
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
3
|
import base58 from 'bs58';
|
|
4
4
|
import { Transaction } from '@solana/web3.js';
|
|
5
|
-
export function
|
|
5
|
+
export function useHandleIFrameMessages(_a) {
|
|
6
6
|
var _this = this;
|
|
7
|
-
var wallet = _a.wallet, connection = _a.connection, onSuccess = _a.onSuccess, partialSigners = _a.partialSigners, _b = _a.debugTx, debugTx = _b === void 0 ? false : _b;
|
|
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]);
|
|
7
|
+
var wallet = _a.wallet, connection = _a.connection, onSuccess = _a.onSuccess, partialSigners = _a.partialSigners, _b = _a.debugTx, debugTx = _b === void 0 ? false : _b, sendIFrameMessage = _a.sendIFrameMessage;
|
|
15
8
|
var handleSignMessage = useCallback(function (_a) {
|
|
16
9
|
var data = _a.data;
|
|
17
10
|
return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -91,6 +84,40 @@ export function useIframeWallet(_a) {
|
|
|
91
84
|
sendTransactionDebug,
|
|
92
85
|
wallet,
|
|
93
86
|
]);
|
|
87
|
+
var handleSignTransaction = useCallback(function (_a) {
|
|
88
|
+
var data = _a.data;
|
|
89
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
90
|
+
var tx, partiallySign, signedTransaction;
|
|
91
|
+
return __generator(this, function (_b) {
|
|
92
|
+
switch (_b.label) {
|
|
93
|
+
case 0:
|
|
94
|
+
if (!wallet.signTransaction) {
|
|
95
|
+
throw new Error('signTransaction is not supported by this wallet');
|
|
96
|
+
}
|
|
97
|
+
tx = Transaction.from(base58.decode(data));
|
|
98
|
+
partiallySign = function (signer) {
|
|
99
|
+
var requiredSignatures = tx.signatures.map(function (sig) {
|
|
100
|
+
return sig.publicKey.toString();
|
|
101
|
+
});
|
|
102
|
+
var shouldSign = requiredSignatures.includes(signer.publicKey.toString());
|
|
103
|
+
if (shouldSign)
|
|
104
|
+
tx.partialSign(signer);
|
|
105
|
+
};
|
|
106
|
+
if (partialSigners) {
|
|
107
|
+
partialSigners.forEach(partiallySign);
|
|
108
|
+
}
|
|
109
|
+
return [4 /*yield*/, wallet.signTransaction(tx)];
|
|
110
|
+
case 1:
|
|
111
|
+
signedTransaction = _b.sent();
|
|
112
|
+
sendIFrameMessage(base58.encode(signedTransaction.serialize({
|
|
113
|
+
requireAllSignatures: false,
|
|
114
|
+
verifySignatures: false
|
|
115
|
+
})));
|
|
116
|
+
return [2 /*return*/];
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
}, [partialSigners, sendIFrameMessage, wallet]);
|
|
94
121
|
var handleIframeMessages = useCallback(function (_a) {
|
|
95
122
|
var data = _a.data;
|
|
96
123
|
return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -98,7 +125,7 @@ export function useIframeWallet(_a) {
|
|
|
98
125
|
return __generator(this, function (_c) {
|
|
99
126
|
switch (_c.label) {
|
|
100
127
|
case 0:
|
|
101
|
-
_c.trys.push([0,
|
|
128
|
+
_c.trys.push([0, 10, , 11]);
|
|
102
129
|
if (!wallet)
|
|
103
130
|
return [2 /*return*/];
|
|
104
131
|
parsedData = parseJSON(data);
|
|
@@ -109,35 +136,40 @@ export function useIframeWallet(_a) {
|
|
|
109
136
|
case 'signMessage': return [3 /*break*/, 1];
|
|
110
137
|
case 'sendTransaction': return [3 /*break*/, 3];
|
|
111
138
|
case 'success': return [3 /*break*/, 5];
|
|
139
|
+
case 'signTransaction': return [3 /*break*/, 6];
|
|
112
140
|
}
|
|
113
|
-
return [3 /*break*/,
|
|
141
|
+
return [3 /*break*/, 8];
|
|
114
142
|
case 1: return [4 /*yield*/, handleSignMessage(parsedData)];
|
|
115
143
|
case 2:
|
|
116
144
|
_c.sent();
|
|
117
|
-
return [3 /*break*/,
|
|
145
|
+
return [3 /*break*/, 9];
|
|
118
146
|
case 3: return [4 /*yield*/, handleSendTransaction(parsedData)];
|
|
119
147
|
case 4:
|
|
120
148
|
_c.sent();
|
|
121
|
-
return [3 /*break*/,
|
|
149
|
+
return [3 /*break*/, 9];
|
|
122
150
|
case 5:
|
|
123
151
|
{
|
|
124
152
|
if (onSuccess)
|
|
125
153
|
onSuccess(data);
|
|
126
|
-
return [3 /*break*/,
|
|
154
|
+
return [3 /*break*/, 9];
|
|
127
155
|
}
|
|
128
156
|
_c.label = 6;
|
|
129
|
-
case 6:
|
|
157
|
+
case 6: return [4 /*yield*/, handleSignTransaction(parsedData)];
|
|
158
|
+
case 7:
|
|
159
|
+
_c.sent();
|
|
160
|
+
return [3 /*break*/, 9];
|
|
161
|
+
case 8:
|
|
130
162
|
{
|
|
131
163
|
throw new Error("Unsupported Wallet Method ".concat(parsedData.method, ", must be signMessage or signTransaction"));
|
|
132
164
|
}
|
|
133
|
-
_c.label =
|
|
134
|
-
case
|
|
135
|
-
case
|
|
165
|
+
_c.label = 9;
|
|
166
|
+
case 9: return [3 /*break*/, 11];
|
|
167
|
+
case 10:
|
|
136
168
|
e_1 = _c.sent();
|
|
137
169
|
console.error('handleIframeMessages', e_1);
|
|
138
170
|
sendIFrameMessage('ERROR');
|
|
139
|
-
return [3 /*break*/,
|
|
140
|
-
case
|
|
171
|
+
return [3 /*break*/, 11];
|
|
172
|
+
case 11: return [2 /*return*/];
|
|
141
173
|
}
|
|
142
174
|
});
|
|
143
175
|
});
|
|
@@ -148,12 +180,7 @@ export function useIframeWallet(_a) {
|
|
|
148
180
|
sendIFrameMessage,
|
|
149
181
|
wallet,
|
|
150
182
|
]);
|
|
151
|
-
|
|
152
|
-
if (!window)
|
|
153
|
-
throw new Error('Window not defined');
|
|
154
|
-
window.onmessage = handleIframeMessages;
|
|
155
|
-
}, [handleIframeMessages]);
|
|
156
|
-
return { IFrameRef: IFrameRef };
|
|
183
|
+
return { handleIframeMessages: handleIframeMessages };
|
|
157
184
|
}
|
|
158
185
|
function parseJSON(data) {
|
|
159
186
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IFrameWalletConnector.js","sourceRoot":"","sources":["../../src/IFrameWalletConnector.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,WAAW,
|
|
1
|
+
{"version":3,"file":"IFrameWalletConnector.js","sourceRoot":"","sources":["../../src/IFrameWalletConnector.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,OAAO,CAAC;AAClC,OAAO,MAAM,MAAM,MAAM,CAAC;AAC1B,OAAO,EAAqB,WAAW,EAAC,MAAM,iBAAiB,CAAC;AAgBhE,MAAM,UAAU,uBAAuB,CAAC,EAOhC;IAPR,iBAqJC;QApJC,MAAM,YAAA,EACN,UAAU,gBAAA,EACV,SAAS,eAAA,EACT,cAAc,oBAAA,EACd,eAAe,EAAf,OAAO,mBAAG,KAAK,KAAA,EACf,iBAAiB,uBAAA;IAEjB,IAAM,iBAAiB,GAAG,WAAW,CACnC,UAAO,EAAkB;YAAjB,IAAI,UAAA;;;;;;wBACV,IAAI,CAAC,MAAM,CAAC,WAAW;4BAAE,sBAAO;wBACd,qBAAM,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,EAAA;;wBAAzD,SAAS,GAAG,SAA6C;wBAC/D,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;;;;;KAC7C,EACD,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAC5B,CAAC;IAEF,IAAM,oBAAoB,GAAG,WAAW,CACtC,UAAO,EAAe;;;;;oBACpB,IAAI,CAAC,MAAM,CAAC,eAAe;wBACzB,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;oBAE7C,qBAAM,MAAM,CAAC,eAAe,CAAC,EAAE,CAAC,EAAA;;oBAA3C,QAAQ,GAAG,SAAgC;oBAC3C,YAAY,GAAG,QAAQ,CAAC,SAAS,EAAE,CAAC;oBACxB,qBAAM,UAAU,CAAC,kBAAkB,CAAC,YAA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GED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Connection, Signer } from '@solana/web3.js';
|
|
3
|
+
import { OnSuccessMethod } from './IFrameWalletConnector';
|
|
4
|
+
import { SubsetWalletContextState } from './CoinflowUtils';
|
|
5
|
+
export type IFrameWalletProps = {
|
|
6
|
+
wallet: SubsetWalletContextState;
|
|
7
|
+
connection: Connection;
|
|
8
|
+
onSuccess?: OnSuccessMethod;
|
|
9
|
+
partialSigners?: Signer[];
|
|
10
|
+
debugTx?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare function useIframeWallet({ wallet, connection, onSuccess, partialSigners, debugTx, }: IFrameWalletProps): {
|
|
13
|
+
IFrameRef: import("react").RefObject<HTMLIFrameElement>;
|
|
14
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef } from 'react';
|
|
2
|
+
import { useHandleIFrameMessages, } from './IFrameWalletConnector';
|
|
3
|
+
export function useIframeWallet(_a) {
|
|
4
|
+
var wallet = _a.wallet, connection = _a.connection, onSuccess = _a.onSuccess, partialSigners = _a.partialSigners, _b = _a.debugTx, debugTx = _b === void 0 ? false : _b;
|
|
5
|
+
var IFrameRef = useRef(null);
|
|
6
|
+
var sendIFrameMessage = useCallback(function (message) {
|
|
7
|
+
var _a;
|
|
8
|
+
if (!((_a = IFrameRef === null || IFrameRef === void 0 ? void 0 : IFrameRef.current) === null || _a === void 0 ? void 0 : _a.contentWindow))
|
|
9
|
+
throw new Error('Iframe not defined');
|
|
10
|
+
IFrameRef.current.contentWindow.postMessage(message, '*');
|
|
11
|
+
}, [IFrameRef]);
|
|
12
|
+
var handleIframeMessages = useHandleIFrameMessages({
|
|
13
|
+
wallet: wallet,
|
|
14
|
+
connection: connection,
|
|
15
|
+
onSuccess: onSuccess,
|
|
16
|
+
partialSigners: partialSigners,
|
|
17
|
+
debugTx: debugTx,
|
|
18
|
+
sendIFrameMessage: sendIFrameMessage
|
|
19
|
+
}).handleIframeMessages;
|
|
20
|
+
useEffect(function () {
|
|
21
|
+
if (!window)
|
|
22
|
+
throw new Error('Window not defined');
|
|
23
|
+
window.onmessage = handleIframeMessages;
|
|
24
|
+
}, [handleIframeMessages]);
|
|
25
|
+
return { IFrameRef: IFrameRef };
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=useIframeWallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIframeWallet.js","sourceRoot":"","sources":["../../src/useIframeWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAE,SAAS,EAAE,MAAM,EAAC,MAAM,OAAO,CAAC;AAErD,OAAO,EAEL,uBAAuB,GACxB,MAAM,yBAAyB,CAAC;AAWjC,MAAM,UAAU,eAAe,CAAC,EAMZ;QALlB,MAAM,YAAA,EACN,UAAU,gBAAA,EACV,SAAS,eAAA,EACT,cAAc,oBAAA,EACd,eAAe,EAAf,OAAO,mBAAG,KAAK,KAAA;IAEf,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,WAAW,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IAC5D,CAAC,EACD,CAAC,SAAS,CAAC,CACZ,CAAC;IAEK,IAAA,oBAAoB,GAAI,uBAAuB,CAAC;QACrD,MAAM,QAAA;QACN,UAAU,YAAA;QACV,SAAS,WAAA;QACT,cAAc,gBAAA;QACd,OAAO,SAAA;QACP,iBAAiB,mBAAA;KAClB,CAAC,qBAPyB,CAOxB;IAEH,SAAS,CAAC;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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coinflowlabs/react",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.9",
|
|
4
4
|
"description": "React Component for Coinflow Withdraw",
|
|
5
5
|
"main": "./build/cjs/index.js",
|
|
6
6
|
"module": "./build/esm/index.js",
|
|
@@ -24,10 +24,11 @@
|
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"bs58": "^5.0.0",
|
|
27
|
-
"@solana/web3.js": "^1.
|
|
27
|
+
"@solana/web3.js": "^1.70.0",
|
|
28
|
+
"@solana/spl-token": "^0.3.6"
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
|
30
|
-
"@types/react": "^18.0.
|
|
31
|
+
"@types/react": "^18.0.26",
|
|
31
32
|
"eslint-config-react-app": "^7.0.1",
|
|
32
33
|
"react": "^18.2.0",
|
|
33
34
|
"react-dom": "^18.2.0",
|