@coinflowlabs/react 0.2.6 → 0.2.8
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 +1 -1
- package/build/cjs/CoinflowIFrame.d.ts +1 -1
- package/build/cjs/CoinflowIFrame.js +1 -0
- package/build/cjs/CoinflowIFrame.js.map +1 -1
- package/build/cjs/CoinflowPurchase.d.ts +1 -1
- package/build/cjs/CoinflowPurchase.js.map +1 -1
- package/build/cjs/CoinflowUtils.d.ts +3 -2
- package/build/cjs/CoinflowUtils.js +73 -1
- package/build/cjs/CoinflowUtils.js.map +1 -1
- package/build/cjs/CoinflowWithdraw.d.ts +1 -1
- package/build/cjs/CoinflowWithdraw.js.map +1 -1
- package/build/esm/CoinflowIFrame.d.ts +1 -1
- package/build/esm/CoinflowIFrame.js +1 -0
- package/build/esm/CoinflowIFrame.js.map +1 -1
- package/build/esm/CoinflowPurchase.d.ts +1 -1
- package/build/esm/CoinflowPurchase.js.map +1 -1
- package/build/esm/CoinflowUtils.d.ts +3 -2
- package/build/esm/CoinflowUtils.js +73 -1
- package/build/esm/CoinflowUtils.js.map +1 -1
- package/build/esm/CoinflowWithdraw.d.ts +1 -1
- package/build/esm/CoinflowWithdraw.js.map +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Transaction } from '@solana/web3.js';
|
|
3
|
-
|
|
3
|
+
import { CoinflowEnvs } from './CoinflowUtils';
|
|
4
4
|
type CoinflowIFrameProps = {
|
|
5
5
|
publicKey: string;
|
|
6
6
|
IFrameRef: React.RefObject<HTMLIFrameElement>;
|
|
@@ -5,6 +5,7 @@ var tslib_1 = require("tslib");
|
|
|
5
5
|
var react_1 = tslib_1.__importStar(require("react"));
|
|
6
6
|
var bs58_1 = tslib_1.__importDefault(require("bs58"));
|
|
7
7
|
function getCoinflowUrl(env) {
|
|
8
|
+
console.log('getCoinflowUrl', { env: env });
|
|
8
9
|
if (!env || env === 'prod')
|
|
9
10
|
return 'https://coinflow.cash';
|
|
10
11
|
if (env === 'local')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CoinflowIFrame.js","sourceRoot":"","sources":["../../src/CoinflowIFrame.tsx"],"names":[],"mappings":";;;;AAAA,qDAAqC;AAErC,sDAA0B;
|
|
1
|
+
{"version":3,"file":"CoinflowIFrame.js","sourceRoot":"","sources":["../../src/CoinflowIFrame.tsx"],"names":[],"mappings":";;;;AAAA,qDAAqC;AAErC,sDAA0B;AAY1B,SAAS,cAAc,CAAC,GAAkB;IACxC,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,EAAC,GAAG,KAAA,EAAC,CAAC,CAAC;IACrC,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,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,IAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC;QAChD,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QAC7C,IAAI,WAAW,EAAE;YACf,IAAM,YAAY,GAAG,iBAAM,CAAC,MAAM,CAChC,WAAW,CAAC,SAAS,CAAC;gBACpB,oBAAoB,EAAE,KAAK;gBAC3B,gBAAgB,EAAE,KAAK;aACxB,CAAC,CACH,CAAC;YACF,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC;SACtD;QACD,IAAI,MAAM,EAAE;YACV,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;SACtD;QACD,OAAO,GAAG,CAAC;IACb,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,CAAC,QAAQ,EAAE,GACnB,CACH,EAXK,CAWL,EACD,CAAC,SAAS,EAAE,GAAG,CAAC,CACjB,CAAC;AACJ,CAAC;AAzCD,wCAyCC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { WalletContextState } from '@solana/wallet-adapter-react';
|
|
3
3
|
import { Connection, Signer, Transaction } from '@solana/web3.js';
|
|
4
|
-
import { CoinflowEnvs } from './CoinflowIFrame';
|
|
5
4
|
import { OnSuccessMethod } from './IFrameWalletConnector';
|
|
5
|
+
import { CoinflowEnvs } from './CoinflowUtils';
|
|
6
6
|
type Props = {
|
|
7
7
|
wallet: WalletContextState;
|
|
8
8
|
merchantId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CoinflowPurchase.js","sourceRoot":"","sources":["../../src/CoinflowPurchase.tsx"],"names":[],"mappings":";;;;AACA,wDAA0B;AAE1B,
|
|
1
|
+
{"version":3,"file":"CoinflowPurchase.js","sourceRoot":"","sources":["../../src/CoinflowPurchase.tsx"],"names":[],"mappings":";;;;AACA,wDAA0B;AAE1B,mDAAgD;AAChD,iEAAyE;AAezE,SAAgB,gBAAgB,CAAC,EAUzB;QATN,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,uCAAe,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,9 @@
|
|
|
1
|
-
import { PublicKey } from '@solana/web3.js';
|
|
2
|
-
|
|
1
|
+
import { Connection, PublicKey } from '@solana/web3.js';
|
|
2
|
+
export type CoinflowEnvs = 'prod' | 'staging' | 'sandbox' | 'local';
|
|
3
3
|
export declare class CoinflowUtils {
|
|
4
4
|
env: CoinflowEnvs;
|
|
5
5
|
url: string;
|
|
6
6
|
constructor(env?: CoinflowEnvs);
|
|
7
7
|
getFeePayer(): Promise<PublicKey>;
|
|
8
|
+
getCoinflowCreditsBalance(publicKey: PublicKey, connection: Connection): Promise<number>;
|
|
8
9
|
}
|
|
@@ -4,6 +4,7 @@ exports.CoinflowUtils = void 0;
|
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var web3_js_1 = require("@solana/web3.js");
|
|
6
6
|
var axios_1 = tslib_1.__importDefault(require("axios"));
|
|
7
|
+
var spl_token_1 = require("@solana/spl-token");
|
|
7
8
|
var CoinflowUtils = /** @class */ (function () {
|
|
8
9
|
function CoinflowUtils(env) {
|
|
9
10
|
this.env = env !== null && env !== void 0 ? env : 'prod';
|
|
@@ -19,7 +20,7 @@ var CoinflowUtils = /** @class */ (function () {
|
|
|
19
20
|
var data;
|
|
20
21
|
return tslib_1.__generator(this, function (_a) {
|
|
21
22
|
switch (_a.label) {
|
|
22
|
-
case 0: return [4 /*yield*/, axios_1["default"].
|
|
23
|
+
case 0: return [4 /*yield*/, axios_1["default"].get(this.url + '/v1/redeem/fee-payer')];
|
|
23
24
|
case 1:
|
|
24
25
|
data = (_a.sent()).data;
|
|
25
26
|
return [2 /*return*/, new web3_js_1.PublicKey(data)];
|
|
@@ -27,6 +28,77 @@ var CoinflowUtils = /** @class */ (function () {
|
|
|
27
28
|
});
|
|
28
29
|
});
|
|
29
30
|
};
|
|
31
|
+
CoinflowUtils.prototype.getCoinflowCreditsBalance = function (publicKey, connection) {
|
|
32
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
33
|
+
function getCreditBalance(wallet) {
|
|
34
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
35
|
+
var ataInfo;
|
|
36
|
+
return tslib_1.__generator(this, function (_a) {
|
|
37
|
+
switch (_a.label) {
|
|
38
|
+
case 0: return [4 /*yield*/, getCreditAtaInfo(wallet)];
|
|
39
|
+
case 1:
|
|
40
|
+
ataInfo = _a.sent();
|
|
41
|
+
if (!ataInfo)
|
|
42
|
+
return [2 /*return*/, 0];
|
|
43
|
+
return [2 /*return*/, Number(ataInfo.amount) / Math.pow(10, 6)];
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function getCreditAtaInfo(wallet) {
|
|
49
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
50
|
+
var ata, e_1;
|
|
51
|
+
return tslib_1.__generator(this, function (_a) {
|
|
52
|
+
switch (_a.label) {
|
|
53
|
+
case 0:
|
|
54
|
+
_a.trys.push([0, 3, , 4]);
|
|
55
|
+
return [4 /*yield*/, getCreditAtaAddress(wallet)];
|
|
56
|
+
case 1:
|
|
57
|
+
ata = _a.sent();
|
|
58
|
+
return [4 /*yield*/, (0, spl_token_1.getAccount)(connection, ata)];
|
|
59
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
60
|
+
case 3:
|
|
61
|
+
e_1 = _a.sent();
|
|
62
|
+
return [2 /*return*/, undefined];
|
|
63
|
+
case 4: return [2 /*return*/];
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function getCreditAtaAddress(wallet) {
|
|
69
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
70
|
+
var _a;
|
|
71
|
+
return tslib_1.__generator(this, function (_b) {
|
|
72
|
+
switch (_b.label) {
|
|
73
|
+
case 0:
|
|
74
|
+
_a = spl_token_1.getAssociatedTokenAddress;
|
|
75
|
+
return [4 /*yield*/, creditsMint()];
|
|
76
|
+
case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent(), wallet])];
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function creditsMint() {
|
|
82
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
83
|
+
return tslib_1.__generator(this, function (_a) {
|
|
84
|
+
switch (_a.label) {
|
|
85
|
+
case 0: return [4 /*yield*/, web3_js_1.PublicKey.findProgramAddress([Buffer.from('usdc-credits-mint-2')], new web3_js_1.PublicKey('FD1amxhTsDpwzoVX41dxp2ygAESURV2zdUACzxM1Dfw9'))];
|
|
86
|
+
case 1: return [2 /*return*/, (_a.sent())[0]];
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return tslib_1.__generator(this, function (_a) {
|
|
92
|
+
switch (_a.label) {
|
|
93
|
+
case 0:
|
|
94
|
+
if (!publicKey)
|
|
95
|
+
return [2 /*return*/, 0];
|
|
96
|
+
return [4 /*yield*/, getCreditBalance(publicKey)];
|
|
97
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
};
|
|
30
102
|
return CoinflowUtils;
|
|
31
103
|
}());
|
|
32
104
|
exports.CoinflowUtils = CoinflowUtils;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CoinflowUtils.js","sourceRoot":"","sources":["../../src/CoinflowUtils.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"CoinflowUtils.js","sourceRoot":"","sources":["../../src/CoinflowUtils.ts"],"names":[],"mappings":";;;;AAAA,2CAAsD;AACtD,wDAA0B;AAC1B,+CAI2B;AAI3B;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;;;;;4BACiB,qBAAM,kBAAK,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,GAAG,sBAAsB,CAAC,EAAA;;wBAA1D,IAAI,GAAI,CAAA,SAAkD,CAAA,KAAtD;wBACX,sBAAO,IAAI,mBAAS,CAAC,IAAI,CAAC,EAAC;;;;KAC5B;IAEK,iDAAyB,GAA/B,UACE,SAAoB,EACpB,UAAsB;;YAItB,SAAe,gBAAgB,CAAC,MAAiB;;;;;oCAC/B,qBAAM,gBAAgB,CAAC,MAAM,CAAC,EAAA;;gCAAxC,OAAO,GAAG,SAA8B;gCAC9C,IAAI,CAAC,OAAO;oCAAE,sBAAO,CAAC,EAAC;gCACvB,sBAAO,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,EAAC;;;;aACjD;YAED,SAAe,gBAAgB,CAC7B,MAAiB;;;;;;;gCAGH,qBAAM,mBAAmB,CAAC,MAAM,CAAC,EAAA;;gCAAvC,GAAG,GAAG,SAAiC;gCACtC,qBAAM,IAAA,sBAAU,EAAC,UAAU,EAAE,GAAG,CAAC,EAAA;oCAAxC,sBAAO,SAAiC,EAAC;;;gCAEzC,sBAAO,SAAS,EAAC;;;;;aAEpB;YAED,SAAe,mBAAmB,CAAC,MAAiB;;;;;;gCAC3C,KAAA,qCAAyB,CAAA;gCAAC,qBAAM,WAAW,EAAE,EAAA;oCAApD,sBAAO,kBAA0B,SAAmB,EAAE,MAAM,EAAC,EAAC;;;;aAC/D;YAED,SAAe,WAAW;;;;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,AAtDD,IAsDC;AAtDY,sCAAa"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { WalletContextState } from '@solana/wallet-adapter-react';
|
|
3
3
|
import { Connection } from '@solana/web3.js';
|
|
4
|
-
import { CoinflowEnvs } from './CoinflowIFrame';
|
|
5
4
|
import { OnSuccessMethod } from './IFrameWalletConnector';
|
|
5
|
+
import { CoinflowEnvs } from './CoinflowUtils';
|
|
6
6
|
type Props = {
|
|
7
7
|
wallet: WalletContextState;
|
|
8
8
|
merchantId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CoinflowWithdraw.js","sourceRoot":"","sources":["../../src/CoinflowWithdraw.tsx"],"names":[],"mappings":";;;;AACA,wDAA0B;AAE1B,
|
|
1
|
+
{"version":3,"file":"CoinflowWithdraw.js","sourceRoot":"","sources":["../../src/CoinflowWithdraw.tsx"],"names":[],"mappings":";;;;AACA,wDAA0B;AAE1B,mDAAgD;AAChD,iEAAyE;AAWzE,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"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Transaction } from '@solana/web3.js';
|
|
3
|
-
|
|
3
|
+
import { CoinflowEnvs } from './CoinflowUtils';
|
|
4
4
|
type CoinflowIFrameProps = {
|
|
5
5
|
publicKey: string;
|
|
6
6
|
IFrameRef: React.RefObject<HTMLIFrameElement>;
|
|
@@ -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,MAAM,MAAM,MAAM,CAAC;
|
|
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,MAAM,MAAM,MAAM,CAAC;AAY1B,SAAS,cAAc,CAAC,GAAkB;IACxC,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,EAAC,GAAG,KAAA,EAAC,CAAC,CAAC;IACrC,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,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,IAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC;QAChD,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QAC7C,IAAI,WAAW,EAAE;YACf,IAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAChC,WAAW,CAAC,SAAS,CAAC;gBACpB,oBAAoB,EAAE,KAAK;gBAC3B,gBAAgB,EAAE,KAAK;aACxB,CAAC,CACH,CAAC;YACF,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC;SACtD;QACD,IAAI,MAAM,EAAE;YACV,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;SACtD;QACD,OAAO,GAAG,CAAC;IACb,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,CAAC,QAAQ,EAAE,GACnB,CACH,EAXK,CAWL,EACD,CAAC,SAAS,EAAE,GAAG,CAAC,CACjB,CAAC;AACJ,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { WalletContextState } from '@solana/wallet-adapter-react';
|
|
3
3
|
import { Connection, Signer, Transaction } from '@solana/web3.js';
|
|
4
|
-
import { CoinflowEnvs } from './CoinflowIFrame';
|
|
5
4
|
import { OnSuccessMethod } from './IFrameWalletConnector';
|
|
5
|
+
import { CoinflowEnvs } from './CoinflowUtils';
|
|
6
6
|
type Props = {
|
|
7
7
|
wallet: WalletContextState;
|
|
8
8
|
merchantId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CoinflowPurchase.js","sourceRoot":"","sources":["../../src/CoinflowPurchase.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,
|
|
1
|
+
{"version":3,"file":"CoinflowPurchase.js","sourceRoot":"","sources":["../../src/CoinflowPurchase.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAkB,eAAe,EAAC,MAAM,yBAAyB,CAAC;AAezE,MAAM,UAAU,gBAAgB,CAAC,EAUzB;QATN,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,9 @@
|
|
|
1
|
-
import { PublicKey } from '@solana/web3.js';
|
|
2
|
-
|
|
1
|
+
import { Connection, PublicKey } from '@solana/web3.js';
|
|
2
|
+
export type CoinflowEnvs = 'prod' | 'staging' | 'sandbox' | 'local';
|
|
3
3
|
export declare class CoinflowUtils {
|
|
4
4
|
env: CoinflowEnvs;
|
|
5
5
|
url: string;
|
|
6
6
|
constructor(env?: CoinflowEnvs);
|
|
7
7
|
getFeePayer(): Promise<PublicKey>;
|
|
8
|
+
getCoinflowCreditsBalance(publicKey: PublicKey, connection: Connection): Promise<number>;
|
|
8
9
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { __awaiter, __generator } from "tslib";
|
|
2
2
|
import { PublicKey } from '@solana/web3.js';
|
|
3
3
|
import axios from 'axios';
|
|
4
|
+
import { getAccount, getAssociatedTokenAddress, } from '@solana/spl-token';
|
|
4
5
|
var CoinflowUtils = /** @class */ (function () {
|
|
5
6
|
function CoinflowUtils(env) {
|
|
6
7
|
this.env = env !== null && env !== void 0 ? env : 'prod';
|
|
@@ -16,7 +17,7 @@ var CoinflowUtils = /** @class */ (function () {
|
|
|
16
17
|
var data;
|
|
17
18
|
return __generator(this, function (_a) {
|
|
18
19
|
switch (_a.label) {
|
|
19
|
-
case 0: return [4 /*yield*/, axios.
|
|
20
|
+
case 0: return [4 /*yield*/, axios.get(this.url + '/v1/redeem/fee-payer')];
|
|
20
21
|
case 1:
|
|
21
22
|
data = (_a.sent()).data;
|
|
22
23
|
return [2 /*return*/, new PublicKey(data)];
|
|
@@ -24,6 +25,77 @@ var CoinflowUtils = /** @class */ (function () {
|
|
|
24
25
|
});
|
|
25
26
|
});
|
|
26
27
|
};
|
|
28
|
+
CoinflowUtils.prototype.getCoinflowCreditsBalance = function (publicKey, connection) {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
30
|
+
function getCreditBalance(wallet) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
32
|
+
var ataInfo;
|
|
33
|
+
return __generator(this, function (_a) {
|
|
34
|
+
switch (_a.label) {
|
|
35
|
+
case 0: return [4 /*yield*/, getCreditAtaInfo(wallet)];
|
|
36
|
+
case 1:
|
|
37
|
+
ataInfo = _a.sent();
|
|
38
|
+
if (!ataInfo)
|
|
39
|
+
return [2 /*return*/, 0];
|
|
40
|
+
return [2 /*return*/, Number(ataInfo.amount) / Math.pow(10, 6)];
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function getCreditAtaInfo(wallet) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
47
|
+
var ata, e_1;
|
|
48
|
+
return __generator(this, function (_a) {
|
|
49
|
+
switch (_a.label) {
|
|
50
|
+
case 0:
|
|
51
|
+
_a.trys.push([0, 3, , 4]);
|
|
52
|
+
return [4 /*yield*/, getCreditAtaAddress(wallet)];
|
|
53
|
+
case 1:
|
|
54
|
+
ata = _a.sent();
|
|
55
|
+
return [4 /*yield*/, getAccount(connection, ata)];
|
|
56
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
57
|
+
case 3:
|
|
58
|
+
e_1 = _a.sent();
|
|
59
|
+
return [2 /*return*/, undefined];
|
|
60
|
+
case 4: return [2 /*return*/];
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
function getCreditAtaAddress(wallet) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
67
|
+
var _a;
|
|
68
|
+
return __generator(this, function (_b) {
|
|
69
|
+
switch (_b.label) {
|
|
70
|
+
case 0:
|
|
71
|
+
_a = getAssociatedTokenAddress;
|
|
72
|
+
return [4 /*yield*/, creditsMint()];
|
|
73
|
+
case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent(), wallet])];
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function creditsMint() {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
80
|
+
return __generator(this, function (_a) {
|
|
81
|
+
switch (_a.label) {
|
|
82
|
+
case 0: return [4 /*yield*/, PublicKey.findProgramAddress([Buffer.from('usdc-credits-mint-2')], new PublicKey('FD1amxhTsDpwzoVX41dxp2ygAESURV2zdUACzxM1Dfw9'))];
|
|
83
|
+
case 1: return [2 /*return*/, (_a.sent())[0]];
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return __generator(this, function (_a) {
|
|
89
|
+
switch (_a.label) {
|
|
90
|
+
case 0:
|
|
91
|
+
if (!publicKey)
|
|
92
|
+
return [2 /*return*/, 0];
|
|
93
|
+
return [4 /*yield*/, getCreditBalance(publicKey)];
|
|
94
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
};
|
|
27
99
|
return CoinflowUtils;
|
|
28
100
|
}());
|
|
29
101
|
export { CoinflowUtils };
|
|
@@ -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;AACtD,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAEL,UAAU,EACV,yBAAyB,GAC1B,MAAM,mBAAmB,CAAC;AAI3B;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;;;;;4BACiB,qBAAM,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,GAAG,sBAAsB,CAAC,EAAA;;wBAA1D,IAAI,GAAI,CAAA,SAAkD,CAAA,KAAtD;wBACX,sBAAO,IAAI,SAAS,CAAC,IAAI,CAAC,EAAC;;;;KAC5B;IAEK,iDAAyB,GAA/B,UACE,SAAoB,EACpB,UAAsB;;YAItB,SAAe,gBAAgB,CAAC,MAAiB;;;;;oCAC/B,qBAAM,gBAAgB,CAAC,MAAM,CAAC,EAAA;;gCAAxC,OAAO,GAAG,SAA8B;gCAC9C,IAAI,CAAC,OAAO;oCAAE,sBAAO,CAAC,EAAC;gCACvB,sBAAO,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,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,AAtDD,IAsDC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { WalletContextState } from '@solana/wallet-adapter-react';
|
|
3
3
|
import { Connection } from '@solana/web3.js';
|
|
4
|
-
import { CoinflowEnvs } from './CoinflowIFrame';
|
|
5
4
|
import { OnSuccessMethod } from './IFrameWalletConnector';
|
|
5
|
+
import { CoinflowEnvs } from './CoinflowUtils';
|
|
6
6
|
type Props = {
|
|
7
7
|
wallet: WalletContextState;
|
|
8
8
|
merchantId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CoinflowWithdraw.js","sourceRoot":"","sources":["../../src/CoinflowWithdraw.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,
|
|
1
|
+
{"version":3,"file":"CoinflowWithdraw.js","sourceRoot":"","sources":["../../src/CoinflowWithdraw.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAkB,eAAe,EAAC,MAAM,yBAAyB,CAAC;AAWzE,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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coinflowlabs/react",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
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.69.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",
|