@pioneer-platform/pioneer-react 0.2.34 → 0.2.35
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/dist/index.js +20342 -8833
- package/dist/index_622864fe.js +205 -0
- package/dist/index_bc632802.js +392364 -0
- package/package.json +2 -1
- package/src/index.tsx +11 -11
- package/src/lib/components/modals/Onboarding.tsx +67 -0
- package/src/lib/context/Pioneer/index.tsx +79 -29
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pioneer-platform/pioneer-react",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.35",
|
|
4
4
|
"author": "highlander",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"@shapeshiftoss/hdwallet-core": "^1.50.0",
|
|
38
38
|
"@shapeshiftoss/hdwallet-metamask": "^1.50.0",
|
|
39
39
|
"@shapeshiftoss/hdwallet-native": "^1.50.3",
|
|
40
|
+
"@shapeshiftoss/metamask-snaps-adapter": "^1.0.1",
|
|
40
41
|
"@types/uuid": "^9.0.1",
|
|
41
42
|
"assert": "^2.0.0",
|
|
42
43
|
"dotenv": "^16.3.1",
|
package/src/index.tsx
CHANGED
|
@@ -16,19 +16,19 @@ import MiddleEllipsis from "lib/components/MiddleEllipsis";
|
|
|
16
16
|
|
|
17
17
|
import App from "./App";
|
|
18
18
|
|
|
19
|
-
// To publish as
|
|
19
|
+
// To publish run as dev uncomment
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
const root = ReactDOM.createRoot(
|
|
22
|
+
document.getElementById("root") as HTMLElement
|
|
23
|
+
);
|
|
24
|
+
root.render(
|
|
25
|
+
<>
|
|
26
|
+
<ColorModeScript initialColorMode={theme.config?.initialColorMode} />
|
|
27
|
+
<App />
|
|
28
|
+
</>
|
|
29
|
+
);
|
|
22
30
|
|
|
23
|
-
//
|
|
24
|
-
// document.getElementById("root") as HTMLElement
|
|
25
|
-
// );
|
|
26
|
-
// root.render(
|
|
27
|
-
// <>
|
|
28
|
-
// <ColorModeScript initialColorMode={theme.config?.initialColorMode} />
|
|
29
|
-
// <App />
|
|
30
|
-
// </>
|
|
31
|
-
// );
|
|
31
|
+
//end dev mode
|
|
32
32
|
|
|
33
33
|
export {
|
|
34
34
|
Pioneer,
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Button,
|
|
3
|
+
Modal,
|
|
4
|
+
ModalOverlay,
|
|
5
|
+
ModalContent,
|
|
6
|
+
ModalHeader,
|
|
7
|
+
ModalCloseButton,
|
|
8
|
+
ModalBody,
|
|
9
|
+
ModalFooter,
|
|
10
|
+
Tabs,
|
|
11
|
+
TabList,
|
|
12
|
+
Tab,
|
|
13
|
+
TabPanels,
|
|
14
|
+
Card,
|
|
15
|
+
CardBody,
|
|
16
|
+
TabPanel,
|
|
17
|
+
} from "@chakra-ui/react";
|
|
18
|
+
import { useState, useEffect } from "react";
|
|
19
|
+
|
|
20
|
+
import { usePioneer } from "lib/context/Pioneer";
|
|
21
|
+
|
|
22
|
+
interface ModalProps {
|
|
23
|
+
isOpen: boolean;
|
|
24
|
+
onClose: () => void;
|
|
25
|
+
}
|
|
26
|
+
//@ts-ignore
|
|
27
|
+
const OnboardingModal: React.FC<ModalProps> = ({ isOpen, onClose }) => {
|
|
28
|
+
const { state, dispatch } = usePioneer();
|
|
29
|
+
const { api, app, user, context } = state;
|
|
30
|
+
const [walletDescriptions, setWalletDescriptions] = useState([]);
|
|
31
|
+
const [balances, setBalances] = useState([]);
|
|
32
|
+
|
|
33
|
+
const setUser = async function () {
|
|
34
|
+
try {
|
|
35
|
+
if (user && user.wallets) {
|
|
36
|
+
const { wallets, walletDescriptions, balances, pubkeys } = user;
|
|
37
|
+
setWalletDescriptions(walletDescriptions);
|
|
38
|
+
setBalances(balances);
|
|
39
|
+
}
|
|
40
|
+
} catch (e) {
|
|
41
|
+
console.error("header e: ", e);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
setUser();
|
|
47
|
+
}, [user]); // once on startup
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<Modal isOpen={isOpen} onClose={onClose} size="xl">
|
|
51
|
+
<ModalOverlay />
|
|
52
|
+
<ModalContent>
|
|
53
|
+
<ModalHeader>Wallet Select</ModalHeader>
|
|
54
|
+
<ModalCloseButton />
|
|
55
|
+
<ModalBody></ModalBody>
|
|
56
|
+
<ModalFooter>
|
|
57
|
+
<Button colorScheme="blue" mr={3} onClick={onClose}>
|
|
58
|
+
Close
|
|
59
|
+
</Button>
|
|
60
|
+
<Button variant="ghost">Secondary Action</Button>
|
|
61
|
+
</ModalFooter>
|
|
62
|
+
</ModalContent>
|
|
63
|
+
</Modal>
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export default OnboardingModal;
|
|
@@ -39,6 +39,7 @@ import { KkRestAdapter } from "@keepkey/hdwallet-keepkey-rest";
|
|
|
39
39
|
import { KeepKeySdk } from "@keepkey/keepkey-sdk";
|
|
40
40
|
import { SDK } from "@pioneer-sdk/sdk";
|
|
41
41
|
import * as core from "@shapeshiftoss/hdwallet-core";
|
|
42
|
+
import { enableShapeShiftSnap, shapeShiftSnapInstalled } from '@shapeshiftoss/metamask-snaps-adapter'
|
|
42
43
|
// import * as keplr from "@shapeshiftoss/hdwallet-keplr";
|
|
43
44
|
import * as metaMask from "@shapeshiftoss/hdwallet-metamask";
|
|
44
45
|
import type { NativeHDWallet } from "@shapeshiftoss/hdwallet-native";
|
|
@@ -59,6 +60,8 @@ import { checkKeepkeyAvailability, timeout } from "lib/components/utils";
|
|
|
59
60
|
|
|
60
61
|
const eventEmitter = new EventEmitter();
|
|
61
62
|
|
|
63
|
+
const SNAP_ID = "npm:@shapeshiftoss/metamask-snaps"
|
|
64
|
+
|
|
62
65
|
export enum WalletActions {
|
|
63
66
|
SET_STATUS = "SET_STATUS",
|
|
64
67
|
SET_USERNAME = "SET_USERNAME",
|
|
@@ -179,45 +182,84 @@ export const PioneerProvider = ({
|
|
|
179
182
|
// @ts-ignore
|
|
180
183
|
const [state, dispatch] = useReducer(reducer, initialState);
|
|
181
184
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
185
|
+
//TODO add wallet to state
|
|
186
|
+
const connectWallet = async function(wallet:string){
|
|
187
|
+
try{
|
|
188
|
+
console.log("connectWallet: ",wallet)
|
|
189
|
+
|
|
190
|
+
if(wallet === "metamask"){
|
|
191
|
+
// walletMetaMask = await metaMaskAdapter.pairDevice();
|
|
192
|
+
// if (walletMetaMask) {
|
|
193
|
+
// // pair metamask
|
|
194
|
+
// await walletMetaMask.initialize();
|
|
195
|
+
// //console.log("walletMetaMask: ", walletMetaMask);
|
|
196
|
+
//
|
|
197
|
+
// // get all accounts
|
|
198
|
+
// //@ts-ignore
|
|
199
|
+
// const accounts = await window.ethereum.request({
|
|
200
|
+
// method: "eth_requestAccounts",
|
|
201
|
+
// });
|
|
202
|
+
// //console.log("accounts: ", accounts);
|
|
203
|
+
// //@ts-ignore
|
|
204
|
+
// walletMetaMask.accounts = accounts;
|
|
205
|
+
//
|
|
206
|
+
// const successMetaMask = await appInit.pairWallet(walletMetaMask);
|
|
207
|
+
// console.log("successMetaMask: ", successMetaMask);
|
|
208
|
+
// if(successMetaMask){
|
|
209
|
+
// // @ts-ignore
|
|
210
|
+
// if (appInit.pubkeyContext?.master || appInit?.pubkey){
|
|
211
|
+
// // @ts-ignore
|
|
212
|
+
// dispatch({
|
|
213
|
+
// type: WalletActions.SET_PUBKEY_CONTEXT,
|
|
214
|
+
// // @ts-ignore
|
|
215
|
+
// payload: appInit.pubkeyContext?.master || appInit?.pubkey,
|
|
216
|
+
// });
|
|
217
|
+
// }
|
|
218
|
+
// }
|
|
219
|
+
// // @ts-ignore
|
|
220
|
+
// dispatch({
|
|
221
|
+
// type: WalletActions.SET_STATUS,
|
|
222
|
+
// payload: "MetaMask connected!",
|
|
223
|
+
// });
|
|
224
|
+
// }
|
|
225
|
+
}else if (wallet === "keepkey"){
|
|
226
|
+
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
}catch(e){
|
|
232
|
+
console.error(e)
|
|
233
|
+
}
|
|
234
|
+
}
|
|
201
235
|
|
|
202
236
|
const onStart = async function () {
|
|
203
237
|
try {
|
|
204
|
-
// eslint-disable-next-line no-console
|
|
205
|
-
//console.log("onStart***** ");
|
|
206
238
|
const serviceKey: string | null = localStorage.getItem("serviceKey"); // KeepKey api key
|
|
207
239
|
let queryKey: string | null = localStorage.getItem("queryKey");
|
|
208
240
|
let username: string | null = localStorage.getItem("username");
|
|
209
241
|
//@ts-ignore
|
|
210
242
|
dispatch({ type: WalletActions.SET_USERNAME, payload: username });
|
|
211
243
|
|
|
244
|
+
//if auto connecting
|
|
245
|
+
let metamaskPaired = localStorage.getItem("metamaskPaired");
|
|
246
|
+
console.log("metamaskPaired: ", metamaskPaired);
|
|
247
|
+
|
|
248
|
+
const isKeepkeyAvailable = await checkKeepkeyAvailability();
|
|
249
|
+
console.log("isKeepkeyAvailable: ", isKeepkeyAvailable);
|
|
250
|
+
|
|
251
|
+
//is metamask available?
|
|
212
252
|
const isMetaMaskAvailable = (): boolean => {
|
|
213
253
|
return (
|
|
214
|
-
|
|
215
|
-
|
|
254
|
+
(window as any).ethereum !== undefined &&
|
|
255
|
+
(window as any).ethereum.isMetaMask
|
|
216
256
|
);
|
|
217
257
|
};
|
|
218
258
|
const keyring = new core.Keyring();
|
|
219
259
|
const metaMaskAdapter = metaMask.MetaMaskAdapter.useKeyring(keyring);
|
|
220
260
|
|
|
261
|
+
|
|
262
|
+
|
|
221
263
|
if (!queryKey) {
|
|
222
264
|
queryKey = `key:${uuidv4()}`;
|
|
223
265
|
localStorage.setItem("queryKey", queryKey);
|
|
@@ -264,7 +306,18 @@ export const PioneerProvider = ({
|
|
|
264
306
|
// Example usage
|
|
265
307
|
let walletMetaMask: metaMask.MetaMaskHDWallet | undefined;
|
|
266
308
|
if (isMetaMaskAvailable()) {
|
|
267
|
-
//
|
|
309
|
+
//is snap enabled?
|
|
310
|
+
let isSnapInstalled = await shapeShiftSnapInstalled(SNAP_ID);
|
|
311
|
+
console.log(isSnapInstalled)
|
|
312
|
+
|
|
313
|
+
//if not installed install snap
|
|
314
|
+
if(!isSnapInstalled){
|
|
315
|
+
//install it
|
|
316
|
+
let result = await enableShapeShiftSnap(SNAP_ID);
|
|
317
|
+
console.log("result: ", result)
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
//console.log("isMetaMaskAvailable ")
|
|
268
321
|
walletMetaMask = await metaMaskAdapter.pairDevice();
|
|
269
322
|
if (walletMetaMask) {
|
|
270
323
|
// pair metamask
|
|
@@ -290,7 +343,7 @@ export const PioneerProvider = ({
|
|
|
290
343
|
type: WalletActions.SET_PUBKEY_CONTEXT,
|
|
291
344
|
// @ts-ignore
|
|
292
345
|
payload: appInit.pubkeyContext?.master || appInit?.pubkey,
|
|
293
|
-
});
|
|
346
|
+
});
|
|
294
347
|
}
|
|
295
348
|
}
|
|
296
349
|
// @ts-ignore
|
|
@@ -300,12 +353,9 @@ export const PioneerProvider = ({
|
|
|
300
353
|
});
|
|
301
354
|
}
|
|
302
355
|
} else {
|
|
303
|
-
|
|
356
|
+
console.log("MetaMask is not available");
|
|
304
357
|
}
|
|
305
358
|
|
|
306
|
-
const isKeepkeyAvailable = await checkKeepkeyAvailability();
|
|
307
|
-
//console.log("isKeepkeyAvailable: ", isKeepkeyAvailable);
|
|
308
|
-
|
|
309
359
|
let walletKeepKey: core.HDWallet;
|
|
310
360
|
if (isKeepkeyAvailable) {
|
|
311
361
|
const config: any = {
|