@coinflowlabs/react-native 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 +49 -0
- package/build/CoinflowPurchase.d.ts +4 -0
- package/build/CoinflowPurchase.js +16 -0
- package/build/CoinflowPurchase.js.map +1 -0
- package/build/CoinflowWebView.d.ts +14 -0
- package/build/CoinflowWebView.js +21 -0
- package/build/CoinflowWebView.js.map +1 -0
- package/build/CoinflowWithdraw.d.ts +4 -0
- package/build/CoinflowWithdraw.js +14 -0
- package/build/CoinflowWithdraw.js.map +1 -0
- package/build/index.d.ts +4 -0
- package/build/index.js +5 -0
- package/build/index.js.map +1 -0
- package/build/useIframeWallet.d.ts +9 -0
- package/build/useIframeWallet.js +20 -0
- package/build/useIframeWallet.js.map +1 -0
- package/package.json +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Coinflow React Native
|
|
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
|
|
36
|
+
* `transaction` (optional): transaction for the user to run which redeems their credits with your smart contract. Create this transaction just like you would for a normal user who has USDC in their account.
|
|
37
|
+
* `partialSigners` (optional): Keypairs of Partial Signers to sign the transaction with, this is necessary when initializing new accounts as the new account Keypair must sign the transaction.
|
|
38
|
+
* `debugTx` (optional): Setting this to `true` will sign the transaction with the wallet, and send the transaction with no preflight checks allowing for easier debug of any issues.
|
|
39
|
+
|
|
40
|
+
## Utils
|
|
41
|
+
|
|
42
|
+
`CoinflowUtils`
|
|
43
|
+
|
|
44
|
+
* `getFeePayer` - Return the `PublicKey` of the Coinflow Fee Payer
|
|
45
|
+
|
|
46
|
+
# Changelog
|
|
47
|
+
|
|
48
|
+
# 0.1.0
|
|
49
|
+
Genesis 1:1
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { CoinflowPurchaseProps } from '@coinflowlabs/react';
|
|
3
|
+
import { WithStyles } from './CoinflowWebView';
|
|
4
|
+
export declare function CoinflowPurchase({ wallet, merchantId, env, connection, onSuccess, transaction, amount, partialSigners, debugTx, style, }: CoinflowPurchaseProps & WithStyles): JSX.Element | null;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { CoinflowWebView } from './CoinflowWebView';
|
|
3
|
+
import { useIframeWallet } from './useIframeWallet';
|
|
4
|
+
export function CoinflowPurchase({ wallet, merchantId, env, connection, onSuccess, transaction, amount, partialSigners, debugTx = false, style, }) {
|
|
5
|
+
const { WebViewRef, handleIframeMessages } = useIframeWallet({
|
|
6
|
+
wallet,
|
|
7
|
+
connection,
|
|
8
|
+
onSuccess,
|
|
9
|
+
partialSigners,
|
|
10
|
+
debugTx,
|
|
11
|
+
});
|
|
12
|
+
if (!wallet.publicKey || !wallet.connected)
|
|
13
|
+
return null;
|
|
14
|
+
return (React.createElement(CoinflowWebView, { publicKey: wallet.publicKey.toString(), WebViewRef: WebViewRef, route: `/purchase/${merchantId}`, env: env, transaction: transaction, amount: amount, handleIframeMessages: handleIframeMessages, style: style }));
|
|
15
|
+
}
|
|
16
|
+
//# 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;AAC1B,OAAO,EAAC,eAAe,EAAa,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAElD,MAAM,UAAU,gBAAgB,CAAC,EAC/B,MAAM,EACN,UAAU,EACV,GAAG,EACH,UAAU,EACV,SAAS,EACT,WAAW,EACX,MAAM,EACN,cAAc,EACd,OAAO,GAAG,KAAK,EACf,KAAK,GAC8B;IACnC,MAAM,EAAC,UAAU,EAAE,oBAAoB,EAAC,GAAG,eAAe,CAAC;QACzD,MAAM;QACN,UAAU;QACV,SAAS;QACT,cAAc;QACd,OAAO;KACR,CAAC,CAAC;IAEH,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,MAAM,CAAC,SAAS;QAAE,OAAO,IAAI,CAAC;IAExD,OAAO,CACL,oBAAC,eAAe,IACd,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,EACtC,UAAU,EAAE,UAAU,EACtB,KAAK,EAAE,aAAa,UAAU,EAAE,EAChC,GAAG,EAAE,GAAG,EACR,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,MAAM,EACd,oBAAoB,EAAE,oBAAoB,EAC1C,KAAK,EAAE,KAAK,GACZ,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import WebView from 'react-native-webview';
|
|
3
|
+
import { CoinflowIFrameProps } from '@coinflowlabs/react';
|
|
4
|
+
import { StyleProp, ViewStyle } from 'react-native';
|
|
5
|
+
export type CoinflowWebViewProps = Omit<CoinflowIFrameProps, 'IFrameRef'> & {
|
|
6
|
+
handleIframeMessages: ({ data }: {
|
|
7
|
+
data: string;
|
|
8
|
+
}) => Promise<void>;
|
|
9
|
+
WebViewRef: React.RefObject<WebView>;
|
|
10
|
+
};
|
|
11
|
+
export type WithStyles = {
|
|
12
|
+
style?: StyleProp<ViewStyle>;
|
|
13
|
+
};
|
|
14
|
+
export declare function CoinflowWebView({ publicKey, env, route, transaction, amount, handleIframeMessages, WebViewRef, style, }: CoinflowWebViewProps & WithStyles): JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import WebView from 'react-native-webview';
|
|
3
|
+
import { CoinflowUtils } from '@coinflowlabs/react';
|
|
4
|
+
export function CoinflowWebView({ publicKey, env, route, transaction, amount, handleIframeMessages, WebViewRef, style, }) {
|
|
5
|
+
const url = useMemo(() => {
|
|
6
|
+
return CoinflowUtils.getCoinflowUrl({
|
|
7
|
+
amount,
|
|
8
|
+
env,
|
|
9
|
+
publicKey,
|
|
10
|
+
route,
|
|
11
|
+
transaction,
|
|
12
|
+
});
|
|
13
|
+
}, [amount, env, publicKey, route, transaction]);
|
|
14
|
+
return useMemo(() => (React.createElement(WebView, { style: [
|
|
15
|
+
{
|
|
16
|
+
flex: 1,
|
|
17
|
+
},
|
|
18
|
+
style,
|
|
19
|
+
], ref: WebViewRef, source: { uri: url }, onMessage: event => handleIframeMessages({ data: event.nativeEvent.data }) })), [url]);
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=CoinflowWebView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CoinflowWebView.js","sourceRoot":"","sources":["../src/CoinflowWebView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AACrC,OAAO,OAAO,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAsB,aAAa,EAAC,MAAM,qBAAqB,CAAC;AAUvE,MAAM,UAAU,eAAe,CAAC,EAC9B,SAAS,EACT,GAAG,EACH,KAAK,EACL,WAAW,EACX,MAAM,EACN,oBAAoB,EACpB,UAAU,EACV,KAAK,GAC6B;IAClC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE;QACvB,OAAO,aAAa,CAAC,cAAc,CAAC;YAClC,MAAM;YACN,GAAG;YACH,SAAS;YACT,KAAK;YACL,WAAW;SACZ,CAAC,CAAC;IACL,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC;IAEjD,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,CACJ,oBAAC,OAAO,IACN,KAAK,EAAE;YACL;gBACE,IAAI,EAAE,CAAC;aACR;YACD,KAAK;SACN,EACD,GAAG,EAAE,UAAU,EACf,MAAM,EAAE,EAAC,GAAG,EAAE,GAAG,EAAC,EAClB,SAAS,EAAE,KAAK,CAAC,EAAE,CACjB,oBAAoB,CAAC,EAAC,IAAI,EAAE,KAAK,CAAC,WAAW,CAAC,IAAI,EAAC,CAAC,GAEtD,CACH,EACD,CAAC,GAAG,CAAC,CACN,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { CoinflowWithdrawProps } from '@coinflowlabs/react';
|
|
3
|
+
import { WithStyles } from './CoinflowWebView';
|
|
4
|
+
export declare function CoinflowWithdraw({ wallet, merchantId, env, connection, onSuccess, style, }: CoinflowWithdrawProps & WithStyles): JSX.Element | null;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CoinflowWebView } from './CoinflowWebView';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { useIframeWallet } from './useIframeWallet';
|
|
4
|
+
export function CoinflowWithdraw({ wallet, merchantId, env, connection, onSuccess, style, }) {
|
|
5
|
+
const { WebViewRef, handleIframeMessages } = useIframeWallet({
|
|
6
|
+
wallet,
|
|
7
|
+
connection,
|
|
8
|
+
onSuccess,
|
|
9
|
+
});
|
|
10
|
+
if (!wallet.publicKey || !wallet.connected)
|
|
11
|
+
return null;
|
|
12
|
+
return (React.createElement(CoinflowWebView, { publicKey: wallet.publicKey.toString(), WebViewRef: WebViewRef, handleIframeMessages: handleIframeMessages, route: `/withdraw/${merchantId}`, env: env, style: style }));
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=CoinflowWithdraw.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CoinflowWithdraw.js","sourceRoot":"","sources":["../src/CoinflowWithdraw.tsx"],"names":[],"mappings":"AACA,OAAO,EAAC,eAAe,EAAa,MAAM,mBAAmB,CAAC;AAC9D,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAElD,MAAM,UAAU,gBAAgB,CAAC,EAC/B,MAAM,EACN,UAAU,EACV,GAAG,EACH,UAAU,EACV,SAAS,EACT,KAAK,GAC8B;IACnC,MAAM,EAAC,UAAU,EAAE,oBAAoB,EAAC,GAAG,eAAe,CAAC;QACzD,MAAM;QACN,UAAU;QACV,SAAS;KACV,CAAC,CAAC;IAEH,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,MAAM,CAAC,SAAS;QAAE,OAAO,IAAI,CAAC;IAExD,OAAO,CACL,oBAAC,eAAe,IACd,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,EACtC,UAAU,EAAE,UAAU,EACtB,oBAAoB,EAAE,oBAAoB,EAC1C,KAAK,EAAE,aAAa,UAAU,EAAE,EAChC,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,KAAK,GACZ,CACH,CAAC;AACJ,CAAC"}
|
package/build/index.d.ts
ADDED
package/build/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAC,aAAa,EAAC,CAAC;AACvB,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { WebView } from 'react-native-webview';
|
|
3
|
+
import { IFrameWalletProps } from '@coinflowlabs/react';
|
|
4
|
+
export declare function useIframeWallet({ wallet, connection, onSuccess, partialSigners, debugTx, }: IFrameWalletProps): {
|
|
5
|
+
WebViewRef: import("react").RefObject<WebView<{}>>;
|
|
6
|
+
handleIframeMessages: ({ data }: {
|
|
7
|
+
data: string;
|
|
8
|
+
}) => Promise<void>;
|
|
9
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useCallback, useRef } from 'react';
|
|
2
|
+
import { useHandleIFrameMessages } from '@coinflowlabs/react';
|
|
3
|
+
export function useIframeWallet({ wallet, connection, onSuccess, partialSigners, debugTx = false, }) {
|
|
4
|
+
const WebViewRef = useRef(null);
|
|
5
|
+
const sendIFrameMessage = useCallback((message) => {
|
|
6
|
+
if (!(WebViewRef === null || WebViewRef === void 0 ? void 0 : WebViewRef.current))
|
|
7
|
+
throw new Error('WebViewRef not defined');
|
|
8
|
+
WebViewRef.current.postMessage(message);
|
|
9
|
+
}, [WebViewRef]);
|
|
10
|
+
const { handleIframeMessages } = useHandleIFrameMessages({
|
|
11
|
+
wallet,
|
|
12
|
+
connection,
|
|
13
|
+
onSuccess,
|
|
14
|
+
partialSigners,
|
|
15
|
+
debugTx,
|
|
16
|
+
sendIFrameMessage,
|
|
17
|
+
});
|
|
18
|
+
return { WebViewRef, handleIframeMessages };
|
|
19
|
+
}
|
|
20
|
+
//# 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,MAAM,EAAC,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAC,uBAAuB,EAAoB,MAAM,qBAAqB,CAAC;AAE/E,MAAM,UAAU,eAAe,CAAC,EAC9B,MAAM,EACN,UAAU,EACV,SAAS,EACT,cAAc,EACd,OAAO,GAAG,KAAK,GACG;IAClB,MAAM,UAAU,GAAG,MAAM,CAAU,IAAI,CAAC,CAAC;IAEzC,MAAM,iBAAiB,GAAG,WAAW,CACnC,CAAC,OAAe,EAAE,EAAE;QAClB,IAAI,CAAC,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,OAAO,CAAA;YAAE,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QACpE,UAAU,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC,EACD,CAAC,UAAU,CAAC,CACb,CAAC;IAEF,MAAM,EAAC,oBAAoB,EAAC,GAAG,uBAAuB,CAAC;QACrD,MAAM;QACN,UAAU;QACV,SAAS;QACT,cAAc;QACd,OAAO;QACP,iBAAiB;KAClB,CAAC,CAAC;IAEH,OAAO,EAAC,UAAU,EAAE,oBAAoB,EAAC,CAAC;AAC5C,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@coinflowlabs/react-native",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "React Native Component for Coinflow Withdraw",
|
|
5
|
+
"main": "build/index.js",
|
|
6
|
+
"types": "build/index.d.ts",
|
|
7
|
+
"license": "Apache-2.0",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"react-native",
|
|
10
|
+
"react",
|
|
11
|
+
"typescript",
|
|
12
|
+
"solana",
|
|
13
|
+
"web3"
|
|
14
|
+
],
|
|
15
|
+
"files": [
|
|
16
|
+
"build/**/*",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"clean": "rimraf build",
|
|
21
|
+
"build": "tsc"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"react": ">=16",
|
|
25
|
+
"react-native": ">=0.66.0"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@coinflowlabs/react": "*",
|
|
29
|
+
"react-native-webview": "^11.25.0",
|
|
30
|
+
"bs58": "^5.0.0",
|
|
31
|
+
"@solana/web3.js": "^1.69.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/react": "^18.0.26",
|
|
35
|
+
"@types/react-native": "^0.70.8",
|
|
36
|
+
"eslint-config-react-app": "^7.0.1",
|
|
37
|
+
"typescript": "^4.9.3"
|
|
38
|
+
}
|
|
39
|
+
}
|