@pioneer-platform/pioneer-react 0.2.34 → 0.2.36

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": "@pioneer-platform/pioneer-react",
3
- "version": "0.2.34",
3
+ "version": "0.2.36",
4
4
  "author": "highlander",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -33,12 +33,15 @@
33
33
  "@keepkey/hdwallet-keepkey-rest": "^1.40.29",
34
34
  "@keepkey/keepkey-sdk": "^0.2.48",
35
35
  "@pioneer-platform/pioneer-client": "^9.0.6",
36
- "@pioneer-sdk/sdk": "1.1.158",
36
+ "@pioneer-sdk/sdk": "1.1.160",
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/hdwallet-shapeshift-multichain": "1.50.5-alpha.70",
41
+ "@shapeshiftoss/metamask-snaps-adapter": "1.0.3",
40
42
  "@types/uuid": "^9.0.1",
41
43
  "assert": "^2.0.0",
44
+ "bip39": "^3.1.0",
42
45
  "dotenv": "^16.3.1",
43
46
  "events": "^3.3.0",
44
47
  "framer-motion": "^10.12.4",
package/src/index.tsx CHANGED
@@ -16,9 +16,7 @@ import MiddleEllipsis from "lib/components/MiddleEllipsis";
16
16
 
17
17
  import App from "./App";
18
18
 
19
- // To publish as lib uncomment
20
-
21
- // index.tsx
19
+ // To publish run as dev uncomment
22
20
 
23
21
  // const root = ReactDOM.createRoot(
24
22
  // document.getElementById("root") as HTMLElement
@@ -30,6 +28,8 @@ import App from "./App";
30
28
  // </>
31
29
  // );
32
30
 
31
+ //end dev mode
32
+
33
33
  export {
34
34
  Pioneer,
35
35
  PioneerProvider,
@@ -28,9 +28,9 @@ export default function AssetSelect({ onClose }) {
28
28
 
29
29
  const handleSelectClick = async (asset: any) => {
30
30
  try {
31
- //console.log("asset select: ", asset.name);
31
+ //console.log("asset select: ", asset.name);
32
32
  const changeAssetContext = await app.setAssetContext(asset);
33
- //console.log("changeAssetContext: ", changeAssetContext);
33
+ //console.log("changeAssetContext: ", changeAssetContext);
34
34
  onClose();
35
35
  } catch (e) {
36
36
  console.error(e);
@@ -43,7 +43,7 @@ export default function AssetSelect({ onClose }) {
43
43
  alert("Failed to init API!");
44
44
  return;
45
45
  }
46
- //console.log("searchQuery: ", searchQuery);
46
+ //console.log("searchQuery: ", searchQuery);
47
47
  const search = {
48
48
  limit: itemsPerPage,
49
49
  skip: currentPageIndex * itemsPerPage, // Use currentPageIndex for pagination
@@ -0,0 +1,249 @@
1
+ import {
2
+ Box,
3
+ Text,
4
+ Button,
5
+ Modal,
6
+ ModalOverlay,
7
+ ModalContent,
8
+ ModalHeader,
9
+ ModalCloseButton,
10
+ ModalBody,
11
+ ModalFooter,
12
+ Tabs,
13
+ TabList,
14
+ Tab,
15
+ TabPanels,
16
+ Card,
17
+ CardBody,
18
+ TabPanel,
19
+ Avatar,
20
+ SimpleGrid,
21
+ AvatarBadge,
22
+ Input,
23
+ FormControl,
24
+ FormLabel,
25
+ FormErrorMessage,
26
+ VStack,
27
+ Radio,
28
+ RadioGroup
29
+ } from "@chakra-ui/react";
30
+ import { useState, useEffect } from "react";
31
+ import * as bip39 from 'bip39';
32
+ // @ts-ignore
33
+ import KEEPKEY_ICON from "lib/assets/png/keepkey.png";
34
+ // @ts-ignore
35
+ import METAMASK_ICON from "lib/assets/png/metamask.png";
36
+ // @ts-ignore
37
+ import PIONEER_ICON from "lib/assets/png/pioneer.png";
38
+
39
+ import { usePioneer } from "lib/context/Pioneer";
40
+
41
+ interface ModalProps {
42
+ onClose: () => void;
43
+ }
44
+ //@ts-ignore
45
+ const Onboarding: React.FC<ModalProps> = ({ onClose }) => {
46
+ const { state, dispatch } = usePioneer();
47
+ const { api, app, user, context } = state;
48
+ const [walletDescriptions, setWalletDescriptions] = useState([]);
49
+ const [balances, setBalances] = useState([]);
50
+ const [metamaskPaired, setMetamaskPaired] = useState(false);
51
+ const [keepkeyPaired, setKeepkeyPaired] = useState(false);
52
+ const [nativePaired, setNativePaired] = useState(false);
53
+ const [walletType, setWalletType] = useState("");
54
+ const [pubkeyContext, setPubkeyContext] = useState("");
55
+ const [seedPhrase, setSeedPhrase] = useState('');
56
+ const [error, setError] = useState(null);
57
+ const [isValid, setIsValid] = useState(false);
58
+ const [action, setAction] = useState(null);
59
+
60
+ const setUser = async function () {
61
+ try {
62
+ if (user && user.wallets) {
63
+ const { wallets, walletDescriptions, balances, pubkeys } = user;
64
+ setWalletDescriptions(walletDescriptions);
65
+ setBalances(balances);
66
+ }
67
+ } catch (e) {
68
+ console.error("header e: ", e);
69
+ }
70
+ };
71
+
72
+ const setContextWallet = async function (wallet: string) {
73
+ try {
74
+ //console.log("setContextWallet: ", wallet);
75
+ // eslint-disable-next-line no-console
76
+ //console.log("wallets: ", app.wallets);
77
+ const matchedWallet = app.wallets.find(
78
+ (w: { type: string }) => w.type === wallet
79
+ );
80
+ //console.log("matchedWallet: ", matchedWallet);
81
+ if (matchedWallet) {
82
+ setWalletType(matchedWallet.type);
83
+ const context = await app.setContext(matchedWallet.wallet);
84
+ //console.log("result change: ", context);
85
+ //console.log("app.context: ", app.context);
86
+
87
+ //console.log(
88
+ // "app.pubkeyContext: ",
89
+ // app.pubkeyContext.master || app.pubkeyContext.pubkey
90
+ // );
91
+
92
+ const pubkeyContext =
93
+ app.pubkeyContext.master || app.pubkeyContext.pubkey;
94
+
95
+ setPubkeyContext(pubkeyContext);
96
+ dispatch({ type: "SET_CONTEXT", payload: app.context });
97
+ dispatch({ type: "SET_PUBKEY_CONTEXT", payload: app.pubkeyContext });
98
+ // dispatch({ type: "SET_WALLET", payload: wallet });
99
+ } else {
100
+ //console.log("No wallet matched the type of the context");
101
+ }
102
+ } catch (e) {
103
+ console.error("header e: ", e);
104
+ }
105
+ };
106
+
107
+ useEffect(() => {
108
+ setUser();
109
+ }, [user]); // once on startup
110
+
111
+ useEffect(() => {
112
+ const words = seedPhrase.trim().split(' ');
113
+ if (words.length === 12 && words.every(word => word.length > 0)) {
114
+ setError(null);
115
+ setIsValid(true);
116
+ } else {
117
+ // @ts-ignore
118
+ setError('Seed phrase must be exactly 12 words');
119
+ setIsValid(false);
120
+ }
121
+ }, [seedPhrase]);
122
+
123
+ const handleSubmit = (event: { preventDefault: () => void; }) => {
124
+ event.preventDefault();
125
+ if (isValid) {
126
+ console.log('Seed Phrase Submitted:', seedPhrase);
127
+ //save to local storage
128
+ localStorage.setItem("seedPhrase", seedPhrase);
129
+ // @ts-ignore
130
+ localStorage.setItem("isOnboarded", "true");
131
+ }
132
+ };
133
+
134
+ const handleActionSelection = (value: string) => {
135
+ console.log("value: ", value);
136
+ // @ts-ignore
137
+ setAction(value);
138
+ if (value === 'import'){
139
+ setSeedPhrase('');
140
+ }
141
+ };
142
+
143
+ const handleImport = () => {
144
+ setSeedPhrase("");
145
+ // @ts-ignore
146
+ setAction('import')
147
+ };
148
+
149
+ const handleGenerate = () => {
150
+ const newSeedPhrase = bip39.generateMnemonic();
151
+ setSeedPhrase(newSeedPhrase);
152
+ // @ts-ignore
153
+ setAction('generate');
154
+ };
155
+
156
+ return (
157
+ <Box>
158
+ Welcome to Pioneer SDK! Please select a wallet to continue.
159
+ <br/>
160
+ <Avatar size="lg" src={PIONEER_ICON}>
161
+ </Avatar>
162
+ {action ? (
163
+ <>
164
+ <form onSubmit={handleSubmit}>
165
+ <FormControl isInvalid={!!error}>
166
+ <FormLabel htmlFor="seedPhrase">Seed Phrase</FormLabel>
167
+ <Input
168
+ id="seedPhrase"
169
+ name="seedPhrase"
170
+ type="text"
171
+ value={seedPhrase}
172
+ onChange={(e) => setSeedPhrase(e.target.value)}
173
+ borderColor={isValid ? 'green.500' : 'red.500'}
174
+ />
175
+ <FormErrorMessage>{error}</FormErrorMessage>
176
+ </FormControl>
177
+ <Button mt={4} colorScheme="teal" type="submit">
178
+ Submit
179
+ </Button>
180
+ </form>
181
+ <Button mt={4} onClick={() => setAction(null)}>
182
+ Go Back
183
+ </Button>
184
+ </>
185
+ ) : (
186
+ <VStack spacing={4}>
187
+ <Button colorScheme="teal" onClick={handleGenerate}>
188
+ Generate New Seed Phrase
189
+ </Button>
190
+ <Button colorScheme="teal" onClick={handleImport}>
191
+ Import Seed Phrase
192
+ </Button>
193
+ </VStack>
194
+ )}
195
+ {/*<SimpleGrid columns={3} row={1}>*/}
196
+ {/* <Card align="center" onClick={() => setContextWallet("native")}>*/}
197
+ {/* <CardBody>*/}
198
+ {/* <Avatar src={PIONEER_ICON}>*/}
199
+ {/* {nativePaired ? (*/}
200
+ {/* <div>*/}
201
+ {/* <AvatarBadge boxSize="1.25em" bg="green.500" />*/}
202
+ {/* </div>*/}
203
+ {/* ) : (*/}
204
+ {/* <div>*/}
205
+ {/* <AvatarBadge boxSize="1.25em" bg="red.500" />*/}
206
+ {/* </div>*/}
207
+ {/* )}*/}
208
+ {/* </Avatar>*/}
209
+ {/* </CardBody>*/}
210
+ {/* <small>Pioneer</small>*/}
211
+ {/* </Card>*/}
212
+ {/* <Card align="center" onClick={() => setContextWallet("metamask")}>*/}
213
+ {/* <CardBody>*/}
214
+ {/* <Avatar src={METAMASK_ICON}>*/}
215
+ {/* {metamaskPaired ? (*/}
216
+ {/* <div>*/}
217
+ {/* <AvatarBadge boxSize="1.25em" bg="green.500" />*/}
218
+ {/* </div>*/}
219
+ {/* ) : (*/}
220
+ {/* <div>*/}
221
+ {/* <AvatarBadge boxSize="1.25em" bg="red.500" />*/}
222
+ {/* </div>*/}
223
+ {/* )}*/}
224
+ {/* </Avatar>*/}
225
+ {/* </CardBody>*/}
226
+ {/* <small>MetaMask</small>*/}
227
+ {/* </Card>*/}
228
+ {/* <Card align="center" onClick={() => setContextWallet("keepkey")}>*/}
229
+ {/* <CardBody>*/}
230
+ {/* <Avatar src={KEEPKEY_ICON}>*/}
231
+ {/* {keepkeyPaired ? (*/}
232
+ {/* <div>*/}
233
+ {/* <AvatarBadge boxSize="1.25em" bg="green.500" />*/}
234
+ {/* </div>*/}
235
+ {/* ) : (*/}
236
+ {/* <div>*/}
237
+ {/* <AvatarBadge boxSize="1.25em" bg="red.500" />*/}
238
+ {/* </div>*/}
239
+ {/* )}*/}
240
+ {/* </Avatar>*/}
241
+ {/* </CardBody>*/}
242
+ {/* <small>KeepKey</small>*/}
243
+ {/* </Card>*/}
244
+ {/*</SimpleGrid>*/}
245
+ </Box>
246
+ );
247
+ };
248
+
249
+ export default Onboarding;
@@ -123,7 +123,7 @@ export default function Balances({ balances }: { balances: Balance[] }) {
123
123
  useEffect(() => {
124
124
  const setUser = async () => {
125
125
  try {
126
- console.log("balances: ",app.balances)
126
+ console.log("balances: ", app.balances);
127
127
  if (app && app.wallets) {
128
128
  const { wallets, balances } = app;
129
129
  const updatedBalances = balances.map((balance: Balance) => {
@@ -224,20 +224,20 @@ const Pioneer = () => {
224
224
  if (balances) {
225
225
  setBalances(balances);
226
226
  }
227
-
227
+
228
228
  // @ts-ignore
229
229
  window.ethereum.on("accountsChanged", async function (accounts: any) {
230
230
  // Time to reload your interface with accounts[0]!
231
- // //console.log('accountsChanged: ', accounts);
231
+ console.log('accountsChanged: ', accounts);
232
232
  // TODO register new pubkeys
233
233
  const walletsPaired = app.wallets;
234
234
  //console.log("walletsPaired: ", walletsPaired);
235
235
  //console.log("pioneer context: ", app?.context);
236
236
  //if context is metamask
237
237
  if (app?.context === "metamask.wallet") {
238
- //console.log("MetaMask is in context");
238
+ console.log("MetaMask is in context");
239
239
  const addressMetaMask = accounts[0];
240
- //console.log("addressMetaMask: ", addressMetaMask);
240
+ console.log("addressMetaMask: ", addressMetaMask);
241
241
  setPubkeyContext(addressMetaMask);
242
242
  if (addressMetaMask !== app.pubkey) {
243
243
  //push event
@@ -38,10 +38,10 @@ export const MiddleEllipsis: React.FC<MiddleEllipsisProps> = ({ text }) => {
38
38
  const backPart = text.slice(-10);
39
39
 
40
40
  return (
41
- <span>
41
+ <span>
42
42
  {frontPart}
43
- {ellipsis}
44
- {backPart}
43
+ {ellipsis}
44
+ {backPart}
45
45
  </span>
46
46
  );
47
47
  };
@@ -39,8 +39,15 @@ 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 {
43
+ enableShapeShiftSnap,
44
+ shapeShiftSnapInstalled,
45
+ } from "@shapeshiftoss/metamask-snaps-adapter";
42
46
  // import * as keplr from "@shapeshiftoss/hdwallet-keplr";
43
- import * as metaMask from "@shapeshiftoss/hdwallet-metamask";
47
+ // import * as metaMask from "@shapeshiftoss/hdwallet-metamask";
48
+ import * as metaMask from "@shapeshiftoss/hdwallet-shapeshift-multichain";
49
+ import { MetaMaskAdapter as MetaMaskSnapAdapter } from '@shapeshiftoss/hdwallet-shapeshift-multichain'
50
+ import { MetaMaskShapeShiftMultiChainHDWallet } from '@shapeshiftoss/hdwallet-shapeshift-multichain'
44
51
  import type { NativeHDWallet } from "@shapeshiftoss/hdwallet-native";
45
52
  import { EventEmitter } from "events";
46
53
  import { NativeAdapter } from "@shapeshiftoss/hdwallet-native";
@@ -59,9 +66,12 @@ import { checkKeepkeyAvailability, timeout } from "lib/components/utils";
59
66
 
60
67
  const eventEmitter = new EventEmitter();
61
68
 
69
+ const SNAP_ID = "npm:@shapeshiftoss/metamask-snaps";
70
+
62
71
  export enum WalletActions {
63
72
  SET_STATUS = "SET_STATUS",
64
73
  SET_USERNAME = "SET_USERNAME",
74
+ OPEN_MODAL = "OPEN_MODAL",
65
75
  SET_API = "SET_API",
66
76
  SET_APP = "SET_APP",
67
77
  SET_WALLET = "SET_WALLET",
@@ -121,6 +131,7 @@ export interface IPioneerContext {
121
131
  export type ActionTypes =
122
132
  | { type: WalletActions.SET_STATUS; payload: any }
123
133
  | { type: WalletActions.SET_USERNAME; payload: string }
134
+ | { type: WalletActions.OPEN_MODAL; payload: string }
124
135
  | { type: WalletActions.SET_APP; payload: any }
125
136
  | { type: WalletActions.SET_API; payload: any }
126
137
  | { type: WalletActions.SET_CONTEXT; payload: any }
@@ -150,6 +161,8 @@ const reducer = (state: InitialState, action: ActionTypes) => {
150
161
  case WalletActions.SET_USERNAME:
151
162
  //eventEmitter.emit("SET_USERNAME", action.payload);
152
163
  return { ...state, username: action.payload };
164
+ case WalletActions.OPEN_MODAL:
165
+ return { ...state, payload: action.payload };
153
166
  case WalletActions.SET_APP:
154
167
  return { ...state, app: action.payload };
155
168
  case WalletActions.SET_API:
@@ -178,37 +191,85 @@ export const PioneerProvider = ({
178
191
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
179
192
  // @ts-ignore
180
193
  const [state, dispatch] = useReducer(reducer, initialState);
194
+ const [isModalOpen, setIsModalOpen] = useState(false);
195
+
196
+ const showModal = (message:string) => {
197
+ console.log("OPEN MODAL: modal: ", message)
198
+ setIsModalOpen(true);
199
+ // Optional: You can also set a message to be displayed in the modal
200
+ };
201
+
202
+ const hideModal = () => {
203
+ setIsModalOpen(false);
204
+ };
181
205
 
182
- //@TODO build Native Wallet from Metamask
183
- // if (!hashStored) {
184
- // //generate from MM
185
- // const message = 'Pioneers:0xD9B4BEF9:gen1';
186
- // const { hardenedPath, relPath } = walletMetaMask.ethGetAccountPaths({
187
- // coin: 'Ethereum',
188
- // accountIdx: 0,
189
- // })[0];
190
- // const sig = await walletMetaMask.ethSignMessage({
191
- // addressNList: hardenedPath.concat(relPath),
192
- // message,
193
- // });
194
- // // @ts-ignore
195
- // //console.log('sig: ', sig.signature);
196
- // // @ts-ignore
197
- // localStorage.setItem('hash', sig.signature);
198
- // // @ts-ignore
199
- // hashStored = sig.signature;
200
- // }
206
+ //TODO add wallet to state
207
+ const connectWallet = async function (wallet: string) {
208
+ try {
209
+ console.log("connectWallet: ", wallet);
210
+
211
+ if (wallet === "metamask") {
212
+ // walletMetaMask = await metaMaskAdapter.pairDevice();
213
+ // if (walletMetaMask) {
214
+ // // pair metamask
215
+ // await walletMetaMask.initialize();
216
+ // //console.log("walletMetaMask: ", walletMetaMask);
217
+ //
218
+ // // get all accounts
219
+ // //@ts-ignore
220
+ // const accounts = await window.ethereum.request({
221
+ // method: "eth_requestAccounts",
222
+ // });
223
+ // //console.log("accounts: ", accounts);
224
+ // //@ts-ignore
225
+ // walletMetaMask.accounts = accounts;
226
+ //
227
+ // const successMetaMask = await appInit.pairWallet(walletMetaMask);
228
+ // console.log("successMetaMask: ", successMetaMask);
229
+ // if(successMetaMask){
230
+ // // @ts-ignore
231
+ // if (appInit.pubkeyContext?.master || appInit?.pubkey){
232
+ // // @ts-ignore
233
+ // dispatch({
234
+ // type: WalletActions.SET_PUBKEY_CONTEXT,
235
+ // // @ts-ignore
236
+ // payload: appInit.pubkeyContext?.master || appInit?.pubkey,
237
+ // });
238
+ // }
239
+ // }
240
+ // // @ts-ignore
241
+ // dispatch({
242
+ // type: WalletActions.SET_STATUS,
243
+ // payload: "MetaMask connected!",
244
+ // });
245
+ // }
246
+ } else if (wallet === "keepkey") {
247
+
248
+ }
249
+ } catch (e) {
250
+ console.error(e);
251
+ }
252
+ };
201
253
 
202
254
  const onStart = async function () {
203
255
  try {
204
- // eslint-disable-next-line no-console
205
- //console.log("onStart***** ");
206
256
  const serviceKey: string | null = localStorage.getItem("serviceKey"); // KeepKey api key
207
257
  let queryKey: string | null = localStorage.getItem("queryKey");
208
258
  let username: string | null = localStorage.getItem("username");
209
259
  //@ts-ignore
210
260
  dispatch({ type: WalletActions.SET_USERNAME, payload: username });
211
261
 
262
+ //if auto connecting
263
+ const isOnboarded = localStorage.getItem("userOnboarded");
264
+ console.log("isOnboarded: ", isOnboarded);
265
+
266
+ //
267
+
268
+
269
+ const isKeepkeyAvailable = await checkKeepkeyAvailability();
270
+ console.log("isKeepkeyAvailable: ", isKeepkeyAvailable);
271
+
272
+ //is metamask available?
212
273
  const isMetaMaskAvailable = (): boolean => {
213
274
  return (
214
275
  (window as any).ethereum !== undefined &&
@@ -240,7 +301,7 @@ export const PioneerProvider = ({
240
301
 
241
302
  // @TODO add custom paths from localstorage
242
303
  const paths: any = [];
243
- console.log("VITE_PIONEER_URL_SPEC: ",)
304
+ console.log("VITE_PIONEER_URL_SPEC: ");
244
305
  const spec =
245
306
  //@ts-ignore
246
307
  "https://pioneers.dev/spec/swagger.json";
@@ -262,14 +323,26 @@ export const PioneerProvider = ({
262
323
  // @ts-ignore
263
324
  dispatch({ type: WalletActions.SET_APP, payload: appInit });
264
325
  // Example usage
326
+ // @ts-ignore
265
327
  let walletMetaMask: metaMask.MetaMaskHDWallet | undefined;
266
328
  if (isMetaMaskAvailable()) {
267
- // //console.log("isMetaMaskAvailable ")
329
+ //is snap enabled?
330
+ const isSnapInstalled = await shapeShiftSnapInstalled(SNAP_ID);
331
+ console.log(isSnapInstalled);
332
+
333
+ //if not installed install snap
334
+ if (!isSnapInstalled) {
335
+ //install it
336
+ const result = await enableShapeShiftSnap(SNAP_ID,"1.0.0");
337
+ console.log("result: ", result);
338
+ }
339
+
340
+ //console.log("isMetaMaskAvailable ")
268
341
  walletMetaMask = await metaMaskAdapter.pairDevice();
269
342
  if (walletMetaMask) {
270
343
  // pair metamask
271
344
  await walletMetaMask.initialize();
272
- //console.log("walletMetaMask: ", walletMetaMask);
345
+ console.log("walletMetaMask: ", walletMetaMask);
273
346
 
274
347
  // get all accounts
275
348
  //@ts-ignore
@@ -282,15 +355,15 @@ export const PioneerProvider = ({
282
355
 
283
356
  const successMetaMask = await appInit.pairWallet(walletMetaMask);
284
357
  console.log("successMetaMask: ", successMetaMask);
285
- if(successMetaMask){
358
+ if (successMetaMask) {
286
359
  // @ts-ignore
287
- if (appInit.pubkeyContext?.master || appInit?.pubkey){
360
+ if (appInit.pubkeyContext?.master || appInit?.pubkey) {
288
361
  // @ts-ignore
289
362
  dispatch({
290
363
  type: WalletActions.SET_PUBKEY_CONTEXT,
291
364
  // @ts-ignore
292
365
  payload: appInit.pubkeyContext?.master || appInit?.pubkey,
293
- });
366
+ });
294
367
  }
295
368
  }
296
369
  // @ts-ignore
@@ -300,12 +373,9 @@ export const PioneerProvider = ({
300
373
  });
301
374
  }
302
375
  } else {
303
- //console.log("MetaMask is not available");
376
+ console.log("MetaMask is not available");
304
377
  }
305
378
 
306
- const isKeepkeyAvailable = await checkKeepkeyAvailability();
307
- //console.log("isKeepkeyAvailable: ", isKeepkeyAvailable);
308
-
309
379
  let walletKeepKey: core.HDWallet;
310
380
  if (isKeepkeyAvailable) {
311
381
  const config: any = {
@@ -345,57 +415,35 @@ export const PioneerProvider = ({
345
415
  alert("Please restart your KeepKey and try again.");
346
416
  }
347
417
  }
348
-
418
+
349
419
  let walletSoftware: NativeHDWallet | null;
350
- let mnemonic;
351
- let hashStored;
352
- let hash;
420
+ //if native wallet saved
421
+ let mnemonic = localStorage.getItem("seedPhrase");
353
422
  const nativeAdapter = NativeAdapter.useKeyring(keyring);
354
- //is metamask available AND no KeepKey
355
- hashStored = localStorage.getItem("hash");
356
-
357
- if (hashStored) {
358
- //generate software from metamask
359
- //console.log('hashStored: ', hashStored);
360
- const hashSplice = (str: string | any[] | null) => {
361
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
362
- // @ts-ignore
363
- return str.slice(0, 34);
364
- };
365
- // @ts-ignore
366
- hash = hashSplice(hashStored);
367
- // eslint-disable-next-line no-console
368
- //console.log('hash (trimmed): ', hash);
369
- // @ts-ignore
370
- const hashBytes = hash.replace("0x", "");
371
- //console.log('hashBytes', hashBytes);
372
- //console.log('hashBytes', hashBytes.length);
373
- mnemonic = entropyToMnemonic(hashBytes.toString(`hex`));
374
423
 
424
+ if(mnemonic){
425
+ console.log("mnemonic: ", mnemonic);
426
+
427
+ //if no metamask AND no keepkey
375
428
  // get walletSoftware
376
429
  walletSoftware = await nativeAdapter.pairDevice("testid");
377
430
  await nativeAdapter.initialize();
378
431
  // @ts-ignore
379
432
  await walletSoftware.loadDevice({ mnemonic });
433
+ console.log("walletSoftware: ", walletSoftware);
380
434
  const successSoftware = await appInit.pairWallet(walletSoftware);
381
- //console.log("successSoftware: ", successSoftware);
435
+ console.log("successSoftware: ", successSoftware);
436
+ // @ts-ignore
437
+ dispatch({ type: WalletActions.ADD_WALLET, payload: walletSoftware });
438
+ // @ts-ignore
439
+ dispatch({
440
+ type: WalletActions.SET_STATUS,
441
+ payload: "Software wallet connected!",
442
+ });
443
+ }
382
444
 
383
- //events!
384
- const events = await appInit.startSocket();
385
445
 
386
- events.on("message", (event: any) => {
387
- //console.log("message: ", event);
388
- });
389
446
 
390
- events.on("blocks", (event: any) => {
391
- //console.log("blocks: ", event);
392
- // @ts-ignore
393
- dispatch({
394
- type: WalletActions.SET_STATUS,
395
- payload: "Block Scanned!",
396
- });
397
- });
398
- }
399
447
  } catch (e) {
400
448
  // eslint-disable-next-line no-console
401
449
  console.error(e);
@@ -404,6 +452,7 @@ export const PioneerProvider = ({
404
452
 
405
453
  // onstart get data
406
454
  useEffect(() => {
455
+ showModal('foo');
407
456
  onStart();
408
457
  }, []);
409
458
 
@@ -415,5 +464,9 @@ export const PioneerProvider = ({
415
464
  );
416
465
  };
417
466
 
467
+ type ModalProps = {
468
+ onClose: () => void;
469
+ };
470
+
418
471
  export const usePioneer = (): any =>
419
472
  useContext(PioneerContext as unknown as React.Context<IPioneerContext>);