@pioneer-platform/pioneer-react 0.2.35 → 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/dist/index.js +15981 -14210
- package/package.json +5 -3
- package/src/index.tsx +9 -9
- package/src/lib/components/AssetSelect/index.tsx +3 -3
- package/src/lib/components/Onboarding/index.tsx +249 -0
- package/src/lib/components/pioneer/Pioneer/Balances.tsx +1 -1
- package/src/lib/components/pioneer/index.tsx +4 -4
- package/src/lib/components/utils/index.tsx +3 -3
- package/src/lib/context/Pioneer/index.tsx +72 -69
- package/src/lib/pages/home/index.tsx +42 -3
- package/dist/index_622864fe.js +0 -205
- package/dist/index_bc632802.js +0 -392364
- package/src/lib/components/modals/Onboarding.tsx +0 -67
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.36",
|
|
4
4
|
"author": "highlander",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -33,13 +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.
|
|
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/
|
|
40
|
+
"@shapeshiftoss/hdwallet-shapeshift-multichain": "1.50.5-alpha.70",
|
|
41
|
+
"@shapeshiftoss/metamask-snaps-adapter": "1.0.3",
|
|
41
42
|
"@types/uuid": "^9.0.1",
|
|
42
43
|
"assert": "^2.0.0",
|
|
44
|
+
"bip39": "^3.1.0",
|
|
43
45
|
"dotenv": "^16.3.1",
|
|
44
46
|
"events": "^3.3.0",
|
|
45
47
|
"framer-motion": "^10.12.4",
|
package/src/index.tsx
CHANGED
|
@@ -18,15 +18,15 @@ import App from "./App";
|
|
|
18
18
|
|
|
19
19
|
// To publish run as dev uncomment
|
|
20
20
|
|
|
21
|
-
const root = ReactDOM.createRoot(
|
|
22
|
-
|
|
23
|
-
);
|
|
24
|
-
root.render(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
);
|
|
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
|
+
// );
|
|
30
30
|
|
|
31
31
|
//end dev mode
|
|
32
32
|
|
|
@@ -28,9 +28,9 @@ export default function AssetSelect({ onClose }) {
|
|
|
28
28
|
|
|
29
29
|
const handleSelectClick = async (asset: any) => {
|
|
30
30
|
try {
|
|
31
|
-
|
|
31
|
+
//console.log("asset select: ", asset.name);
|
|
32
32
|
const changeAssetContext = await app.setAssetContext(asset);
|
|
33
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
238
|
+
console.log("MetaMask is in context");
|
|
239
239
|
const addressMetaMask = accounts[0];
|
|
240
|
-
|
|
240
|
+
console.log("addressMetaMask: ", addressMetaMask);
|
|
241
241
|
setPubkeyContext(addressMetaMask);
|
|
242
242
|
if (addressMetaMask !== app.pubkey) {
|
|
243
243
|
//push event
|
|
@@ -39,9 +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 {
|
|
42
|
+
import {
|
|
43
|
+
enableShapeShiftSnap,
|
|
44
|
+
shapeShiftSnapInstalled,
|
|
45
|
+
} from "@shapeshiftoss/metamask-snaps-adapter";
|
|
43
46
|
// import * as keplr from "@shapeshiftoss/hdwallet-keplr";
|
|
44
|
-
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'
|
|
45
51
|
import type { NativeHDWallet } from "@shapeshiftoss/hdwallet-native";
|
|
46
52
|
import { EventEmitter } from "events";
|
|
47
53
|
import { NativeAdapter } from "@shapeshiftoss/hdwallet-native";
|
|
@@ -60,11 +66,12 @@ import { checkKeepkeyAvailability, timeout } from "lib/components/utils";
|
|
|
60
66
|
|
|
61
67
|
const eventEmitter = new EventEmitter();
|
|
62
68
|
|
|
63
|
-
const SNAP_ID = "npm:@shapeshiftoss/metamask-snaps"
|
|
69
|
+
const SNAP_ID = "npm:@shapeshiftoss/metamask-snaps";
|
|
64
70
|
|
|
65
71
|
export enum WalletActions {
|
|
66
72
|
SET_STATUS = "SET_STATUS",
|
|
67
73
|
SET_USERNAME = "SET_USERNAME",
|
|
74
|
+
OPEN_MODAL = "OPEN_MODAL",
|
|
68
75
|
SET_API = "SET_API",
|
|
69
76
|
SET_APP = "SET_APP",
|
|
70
77
|
SET_WALLET = "SET_WALLET",
|
|
@@ -124,6 +131,7 @@ export interface IPioneerContext {
|
|
|
124
131
|
export type ActionTypes =
|
|
125
132
|
| { type: WalletActions.SET_STATUS; payload: any }
|
|
126
133
|
| { type: WalletActions.SET_USERNAME; payload: string }
|
|
134
|
+
| { type: WalletActions.OPEN_MODAL; payload: string }
|
|
127
135
|
| { type: WalletActions.SET_APP; payload: any }
|
|
128
136
|
| { type: WalletActions.SET_API; payload: any }
|
|
129
137
|
| { type: WalletActions.SET_CONTEXT; payload: any }
|
|
@@ -153,6 +161,8 @@ const reducer = (state: InitialState, action: ActionTypes) => {
|
|
|
153
161
|
case WalletActions.SET_USERNAME:
|
|
154
162
|
//eventEmitter.emit("SET_USERNAME", action.payload);
|
|
155
163
|
return { ...state, username: action.payload };
|
|
164
|
+
case WalletActions.OPEN_MODAL:
|
|
165
|
+
return { ...state, payload: action.payload };
|
|
156
166
|
case WalletActions.SET_APP:
|
|
157
167
|
return { ...state, app: action.payload };
|
|
158
168
|
case WalletActions.SET_API:
|
|
@@ -181,13 +191,24 @@ export const PioneerProvider = ({
|
|
|
181
191
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
182
192
|
// @ts-ignore
|
|
183
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
|
+
};
|
|
184
205
|
|
|
185
206
|
//TODO add wallet to state
|
|
186
|
-
const connectWallet = async function(wallet:string){
|
|
187
|
-
try{
|
|
188
|
-
console.log("connectWallet: ",wallet)
|
|
207
|
+
const connectWallet = async function (wallet: string) {
|
|
208
|
+
try {
|
|
209
|
+
console.log("connectWallet: ", wallet);
|
|
189
210
|
|
|
190
|
-
if(wallet === "metamask"){
|
|
211
|
+
if (wallet === "metamask") {
|
|
191
212
|
// walletMetaMask = await metaMaskAdapter.pairDevice();
|
|
192
213
|
// if (walletMetaMask) {
|
|
193
214
|
// // pair metamask
|
|
@@ -222,16 +243,13 @@ export const PioneerProvider = ({
|
|
|
222
243
|
// payload: "MetaMask connected!",
|
|
223
244
|
// });
|
|
224
245
|
// }
|
|
225
|
-
}else if (wallet === "keepkey"){
|
|
246
|
+
} else if (wallet === "keepkey") {
|
|
226
247
|
|
|
227
248
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}catch(e){
|
|
232
|
-
console.error(e)
|
|
249
|
+
} catch (e) {
|
|
250
|
+
console.error(e);
|
|
233
251
|
}
|
|
234
|
-
}
|
|
252
|
+
};
|
|
235
253
|
|
|
236
254
|
const onStart = async function () {
|
|
237
255
|
try {
|
|
@@ -242,8 +260,11 @@ export const PioneerProvider = ({
|
|
|
242
260
|
dispatch({ type: WalletActions.SET_USERNAME, payload: username });
|
|
243
261
|
|
|
244
262
|
//if auto connecting
|
|
245
|
-
|
|
246
|
-
console.log("
|
|
263
|
+
const isOnboarded = localStorage.getItem("userOnboarded");
|
|
264
|
+
console.log("isOnboarded: ", isOnboarded);
|
|
265
|
+
|
|
266
|
+
//
|
|
267
|
+
|
|
247
268
|
|
|
248
269
|
const isKeepkeyAvailable = await checkKeepkeyAvailability();
|
|
249
270
|
console.log("isKeepkeyAvailable: ", isKeepkeyAvailable);
|
|
@@ -251,15 +272,13 @@ export const PioneerProvider = ({
|
|
|
251
272
|
//is metamask available?
|
|
252
273
|
const isMetaMaskAvailable = (): boolean => {
|
|
253
274
|
return (
|
|
254
|
-
|
|
255
|
-
|
|
275
|
+
(window as any).ethereum !== undefined &&
|
|
276
|
+
(window as any).ethereum.isMetaMask
|
|
256
277
|
);
|
|
257
278
|
};
|
|
258
279
|
const keyring = new core.Keyring();
|
|
259
280
|
const metaMaskAdapter = metaMask.MetaMaskAdapter.useKeyring(keyring);
|
|
260
281
|
|
|
261
|
-
|
|
262
|
-
|
|
263
282
|
if (!queryKey) {
|
|
264
283
|
queryKey = `key:${uuidv4()}`;
|
|
265
284
|
localStorage.setItem("queryKey", queryKey);
|
|
@@ -282,7 +301,7 @@ export const PioneerProvider = ({
|
|
|
282
301
|
|
|
283
302
|
// @TODO add custom paths from localstorage
|
|
284
303
|
const paths: any = [];
|
|
285
|
-
console.log("VITE_PIONEER_URL_SPEC: "
|
|
304
|
+
console.log("VITE_PIONEER_URL_SPEC: ");
|
|
286
305
|
const spec =
|
|
287
306
|
//@ts-ignore
|
|
288
307
|
"https://pioneers.dev/spec/swagger.json";
|
|
@@ -304,17 +323,18 @@ export const PioneerProvider = ({
|
|
|
304
323
|
// @ts-ignore
|
|
305
324
|
dispatch({ type: WalletActions.SET_APP, payload: appInit });
|
|
306
325
|
// Example usage
|
|
326
|
+
// @ts-ignore
|
|
307
327
|
let walletMetaMask: metaMask.MetaMaskHDWallet | undefined;
|
|
308
328
|
if (isMetaMaskAvailable()) {
|
|
309
329
|
//is snap enabled?
|
|
310
|
-
|
|
311
|
-
console.log(isSnapInstalled)
|
|
330
|
+
const isSnapInstalled = await shapeShiftSnapInstalled(SNAP_ID);
|
|
331
|
+
console.log(isSnapInstalled);
|
|
312
332
|
|
|
313
333
|
//if not installed install snap
|
|
314
|
-
if(!isSnapInstalled){
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
334
|
+
if (!isSnapInstalled) {
|
|
335
|
+
//install it
|
|
336
|
+
const result = await enableShapeShiftSnap(SNAP_ID,"1.0.0");
|
|
337
|
+
console.log("result: ", result);
|
|
318
338
|
}
|
|
319
339
|
|
|
320
340
|
//console.log("isMetaMaskAvailable ")
|
|
@@ -322,7 +342,7 @@ export const PioneerProvider = ({
|
|
|
322
342
|
if (walletMetaMask) {
|
|
323
343
|
// pair metamask
|
|
324
344
|
await walletMetaMask.initialize();
|
|
325
|
-
|
|
345
|
+
console.log("walletMetaMask: ", walletMetaMask);
|
|
326
346
|
|
|
327
347
|
// get all accounts
|
|
328
348
|
//@ts-ignore
|
|
@@ -335,9 +355,9 @@ export const PioneerProvider = ({
|
|
|
335
355
|
|
|
336
356
|
const successMetaMask = await appInit.pairWallet(walletMetaMask);
|
|
337
357
|
console.log("successMetaMask: ", successMetaMask);
|
|
338
|
-
if(successMetaMask){
|
|
358
|
+
if (successMetaMask) {
|
|
339
359
|
// @ts-ignore
|
|
340
|
-
if (appInit.pubkeyContext?.master || appInit?.pubkey){
|
|
360
|
+
if (appInit.pubkeyContext?.master || appInit?.pubkey) {
|
|
341
361
|
// @ts-ignore
|
|
342
362
|
dispatch({
|
|
343
363
|
type: WalletActions.SET_PUBKEY_CONTEXT,
|
|
@@ -395,57 +415,35 @@ export const PioneerProvider = ({
|
|
|
395
415
|
alert("Please restart your KeepKey and try again.");
|
|
396
416
|
}
|
|
397
417
|
}
|
|
398
|
-
|
|
418
|
+
|
|
399
419
|
let walletSoftware: NativeHDWallet | null;
|
|
400
|
-
|
|
401
|
-
let
|
|
402
|
-
let hash;
|
|
420
|
+
//if native wallet saved
|
|
421
|
+
let mnemonic = localStorage.getItem("seedPhrase");
|
|
403
422
|
const nativeAdapter = NativeAdapter.useKeyring(keyring);
|
|
404
|
-
//is metamask available AND no KeepKey
|
|
405
|
-
hashStored = localStorage.getItem("hash");
|
|
406
|
-
|
|
407
|
-
if (hashStored) {
|
|
408
|
-
//generate software from metamask
|
|
409
|
-
//console.log('hashStored: ', hashStored);
|
|
410
|
-
const hashSplice = (str: string | any[] | null) => {
|
|
411
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
412
|
-
// @ts-ignore
|
|
413
|
-
return str.slice(0, 34);
|
|
414
|
-
};
|
|
415
|
-
// @ts-ignore
|
|
416
|
-
hash = hashSplice(hashStored);
|
|
417
|
-
// eslint-disable-next-line no-console
|
|
418
|
-
//console.log('hash (trimmed): ', hash);
|
|
419
|
-
// @ts-ignore
|
|
420
|
-
const hashBytes = hash.replace("0x", "");
|
|
421
|
-
//console.log('hashBytes', hashBytes);
|
|
422
|
-
//console.log('hashBytes', hashBytes.length);
|
|
423
|
-
mnemonic = entropyToMnemonic(hashBytes.toString(`hex`));
|
|
424
423
|
|
|
424
|
+
if(mnemonic){
|
|
425
|
+
console.log("mnemonic: ", mnemonic);
|
|
426
|
+
|
|
427
|
+
//if no metamask AND no keepkey
|
|
425
428
|
// get walletSoftware
|
|
426
429
|
walletSoftware = await nativeAdapter.pairDevice("testid");
|
|
427
430
|
await nativeAdapter.initialize();
|
|
428
431
|
// @ts-ignore
|
|
429
432
|
await walletSoftware.loadDevice({ mnemonic });
|
|
433
|
+
console.log("walletSoftware: ", walletSoftware);
|
|
430
434
|
const successSoftware = await appInit.pairWallet(walletSoftware);
|
|
431
|
-
|
|
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
|
+
}
|
|
432
444
|
|
|
433
|
-
//events!
|
|
434
|
-
const events = await appInit.startSocket();
|
|
435
445
|
|
|
436
|
-
events.on("message", (event: any) => {
|
|
437
|
-
//console.log("message: ", event);
|
|
438
|
-
});
|
|
439
446
|
|
|
440
|
-
events.on("blocks", (event: any) => {
|
|
441
|
-
//console.log("blocks: ", event);
|
|
442
|
-
// @ts-ignore
|
|
443
|
-
dispatch({
|
|
444
|
-
type: WalletActions.SET_STATUS,
|
|
445
|
-
payload: "Block Scanned!",
|
|
446
|
-
});
|
|
447
|
-
});
|
|
448
|
-
}
|
|
449
447
|
} catch (e) {
|
|
450
448
|
// eslint-disable-next-line no-console
|
|
451
449
|
console.error(e);
|
|
@@ -454,6 +452,7 @@ export const PioneerProvider = ({
|
|
|
454
452
|
|
|
455
453
|
// onstart get data
|
|
456
454
|
useEffect(() => {
|
|
455
|
+
showModal('foo');
|
|
457
456
|
onStart();
|
|
458
457
|
}, []);
|
|
459
458
|
|
|
@@ -465,5 +464,9 @@ export const PioneerProvider = ({
|
|
|
465
464
|
);
|
|
466
465
|
};
|
|
467
466
|
|
|
467
|
+
type ModalProps = {
|
|
468
|
+
onClose: () => void;
|
|
469
|
+
};
|
|
470
|
+
|
|
468
471
|
export const usePioneer = (): any =>
|
|
469
472
|
useContext(PioneerContext as unknown as React.Context<IPioneerContext>);
|