@coinflowlabs/react-native 0.2.0-sandbox2 → 0.2.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coinflowlabs/react-native",
3
- "version": "0.2.0-sandbox2",
3
+ "version": "0.2.1",
4
4
  "description": "React Native Component for Coinflow Withdraw",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -1,21 +0,0 @@
1
- import { Connection, Signer } from '@solana/web3.js';
2
- import { SubsetWalletContextState } from './ReactNativeCoinflowUtils';
3
- export type WalletCall = {
4
- method: string;
5
- data: string;
6
- };
7
- export type OnSuccessMethod = (params: string) => void | Promise<void>;
8
- type Props = {
9
- wallet: SubsetWalletContextState;
10
- connection: Connection;
11
- onSuccess?: OnSuccessMethod;
12
- partialSigners?: Signer[];
13
- debugTx?: boolean;
14
- sendIFrameMessage: (message: string) => void;
15
- };
16
- export declare function useHandleIFrameMessages({ wallet, connection, onSuccess, partialSigners, debugTx, sendIFrameMessage, }: Props): {
17
- handleIframeMessages: ({ data }: {
18
- data: string;
19
- }) => Promise<void>;
20
- };
21
- export {};
@@ -1,133 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import React from 'react';
11
- import base58 from 'bs58';
12
- import { Transaction } from '@solana/web3.js';
13
- export function useHandleIFrameMessages({ wallet, connection, onSuccess, partialSigners, debugTx = false, sendIFrameMessage, }) {
14
- const handleSignMessage = React.useCallback(({ data }) => __awaiter(this, void 0, void 0, function* () {
15
- if (!wallet.signMessage)
16
- return;
17
- const signature = yield wallet.signMessage(base58.decode(data));
18
- sendIFrameMessage(base58.encode(signature));
19
- }), [sendIFrameMessage, wallet]);
20
- const sendTransactionDebug = React.useCallback((tx) => __awaiter(this, void 0, void 0, function* () {
21
- if (!wallet.signTransaction)
22
- throw new Error('Wallet does not support sign transaction');
23
- const signedTx = yield wallet.signTransaction(tx);
24
- const serializedTx = signedTx.serialize();
25
- const signature = yield connection.sendRawTransaction(serializedTx, {
26
- skipPreflight: true,
27
- });
28
- sendIFrameMessage(signature);
29
- }), [connection, sendIFrameMessage, wallet]);
30
- const handleSendTransaction = React.useCallback(({ data }) => __awaiter(this, void 0, void 0, function* () {
31
- const tx = Transaction.from(base58.decode(data));
32
- // Partially sign the transaction with any partial signers if needed
33
- const partiallySign = (signer) => {
34
- const requiredSignatures = tx.signatures.map(sig => sig.publicKey.toString());
35
- const shouldSign = requiredSignatures.includes(signer.publicKey.toString());
36
- if (shouldSign)
37
- tx.partialSign(signer);
38
- };
39
- if (partialSigners) {
40
- partialSigners.forEach(partiallySign);
41
- }
42
- if (debugTx) {
43
- yield sendTransactionDebug(tx);
44
- return;
45
- }
46
- const signature = yield wallet.sendTransaction(tx, connection);
47
- sendIFrameMessage(signature);
48
- }), [
49
- connection,
50
- debugTx,
51
- partialSigners,
52
- sendIFrameMessage,
53
- sendTransactionDebug,
54
- wallet,
55
- ]);
56
- const handleSignTransaction = React.useCallback(({ data }) => __awaiter(this, void 0, void 0, function* () {
57
- if (!wallet.signTransaction) {
58
- throw new Error('signTransaction is not supported by this wallet');
59
- }
60
- const tx = Transaction.from(base58.decode(data));
61
- // Partially sign the transaction with any partial signers if needed
62
- const partiallySign = (signer) => {
63
- const requiredSignatures = tx.signatures.map(sig => sig.publicKey.toString());
64
- const shouldSign = requiredSignatures.includes(signer.publicKey.toString());
65
- if (shouldSign)
66
- tx.partialSign(signer);
67
- };
68
- if (partialSigners) {
69
- partialSigners.forEach(partiallySign);
70
- }
71
- const signedTransaction = yield wallet.signTransaction(tx);
72
- sendIFrameMessage(base58.encode(signedTransaction.serialize({
73
- requireAllSignatures: false,
74
- verifySignatures: false,
75
- })));
76
- }), [partialSigners, sendIFrameMessage, wallet]);
77
- const handleIframeMessages = React.useCallback(({ data }) => __awaiter(this, void 0, void 0, function* () {
78
- try {
79
- if (!wallet)
80
- return;
81
- const parsedData = parseJSON(data);
82
- if (!parsedData)
83
- return;
84
- switch (parsedData.method) {
85
- case 'signMessage': {
86
- yield handleSignMessage(parsedData);
87
- break;
88
- }
89
- case 'sendTransaction': {
90
- yield handleSendTransaction(parsedData);
91
- break;
92
- }
93
- case 'signTransaction': {
94
- yield handleSignTransaction(parsedData);
95
- break;
96
- }
97
- case 'success': {
98
- if (onSuccess)
99
- onSuccess(data);
100
- break;
101
- }
102
- default: {
103
- throw new Error(`Unsupported Wallet Method ${parsedData.method}, must be signMessage or signTransaction`);
104
- }
105
- }
106
- }
107
- catch (e) {
108
- console.error('handleIframeMessages', e);
109
- sendIFrameMessage('ERROR');
110
- }
111
- }), [
112
- handleSignMessage,
113
- handleSendTransaction,
114
- onSuccess,
115
- sendIFrameMessage,
116
- wallet,
117
- ]);
118
- return { handleIframeMessages };
119
- }
120
- function parseJSON(data) {
121
- try {
122
- const res = JSON.parse(data);
123
- if (!res.method)
124
- return null;
125
- if (!res.data)
126
- return null;
127
- return res;
128
- }
129
- catch (e) {
130
- return null;
131
- }
132
- }
133
- //# sourceMappingURL=IFrameWalletConnector.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IFrameWalletConnector.js","sourceRoot":"","sources":["../src/IFrameWalletConnector.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,MAAM,MAAM,MAAM,CAAC;AAC1B,OAAO,EAAqB,WAAW,EAAC,MAAM,iBAAiB,CAAC;AAgBhE,MAAM,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OAAO,CAAC,CAAC;oBACP,MAAM,IAAI,KAAK,CACb,6BAA6B,UAAU,CAAC,MAAM,0CAA0C,CACzF,CAAC;iBACH;aACF;SACF;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,KAAK,CAAC,sBAAsB,EAAE,CAAC,CAAC,CAAC;YACzC,iBAAiB,CAAC,OAAO,CAAC,CAAC;SAC5B;IACH,CAAC,CAAA,EACD;QACE,iBAAiB;QACjB,qBAAqB;QACrB,SAAS;QACT,iBAAiB;QACjB,MAAM;KACP,CACF,CAAC;IAEF,OAAO,EAAC,oBAAoB,EAAC,CAAC;AAChC,CAAC;AAED,SAAS,SAAS,CAAC,IAAY;IAC7B,IAAI;QACF,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC7B,IAAI,CAAC,GAAG,CAAC,MAAM;YAAE,OAAO,IAAI,CAAC;QAC7B,IAAI,CAAC,GAAG,CAAC,IAAI;YAAE,OAAO,IAAI,CAAC;QAC3B,OAAO,GAAG,CAAC;KACZ;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,IAAI,CAAC;KACb;AACH,CAAC"}
@@ -1,19 +0,0 @@
1
- import React from 'react';
2
- import { WebView } from 'react-native-webview';
3
- import { OnSuccessMethod } from './IFrameWalletConnector';
4
- import { Connection, Signer } from '@solana/web3.js';
5
- import { SubsetWalletContextState } from './ReactNativeCoinflowUtils';
6
- type IFrameWalletProps = {
7
- wallet: SubsetWalletContextState;
8
- connection: Connection;
9
- onSuccess?: OnSuccessMethod;
10
- partialSigners?: Signer[];
11
- debugTx?: boolean;
12
- };
13
- export declare function useIframeWallet({ wallet, connection, onSuccess, partialSigners, debugTx, }: IFrameWalletProps): {
14
- WebViewRef: React.RefObject<WebView<{}>>;
15
- handleIframeMessages: ({ data }: {
16
- data: string;
17
- }) => Promise<void>;
18
- };
19
- export {};
@@ -1,20 +0,0 @@
1
- import React from 'react';
2
- import { useHandleIFrameMessages, } from './IFrameWalletConnector';
3
- export function useIframeWallet({ wallet, connection, onSuccess, partialSigners, debugTx = false, }) {
4
- const WebViewRef = React.useRef(null);
5
- const sendIFrameMessage = React.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
@@ -1 +0,0 @@
1
- {"version":3,"file":"useIframeWallet.js","sourceRoot":"","sources":["../src/useIframeWallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAEL,uBAAuB,GACxB,MAAM,yBAAyB,CAAC;AAYjC,MAAM,UAAU,eAAe,CAAC,EAC9B,MAAM,EACN,UAAU,EACV,SAAS,EACT,cAAc,EACd,OAAO,GAAG,KAAK,GACG;IAClB,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAU,IAAI,CAAC,CAAC;IAE/C,MAAM,iBAAiB,GAAG,KAAK,CAAC,WAAW,CACzC,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"}