@pioneer-platform/pioneer-react 0.2.33 → 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 +19458 -11127
- package/dist/{index_3bde86fb.js → index_622864fe.js} +4 -4
- package/dist/{index_49fce0b0.js → index_bc632802.js} +21011 -12680
- package/package.json +2 -1
- package/src/index.tsx +4 -3
- package/src/lib/components/modals/Onboarding.tsx +67 -0
- package/src/lib/context/Pioneer/index.tsx +81 -32
- package/src/lib/components/pioneer/Pioneer/Nodes.tsx +0 -0
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,9 +16,7 @@ import MiddleEllipsis from "lib/components/MiddleEllipsis";
|
|
|
16
16
|
|
|
17
17
|
import App from "./App";
|
|
18
18
|
|
|
19
|
-
// To publish as
|
|
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
|
|
@@ -29,6 +27,9 @@ root.render(
|
|
|
29
27
|
<App />
|
|
30
28
|
</>
|
|
31
29
|
);
|
|
30
|
+
|
|
31
|
+
//end dev mode
|
|
32
|
+
|
|
32
33
|
export {
|
|
33
34
|
Pioneer,
|
|
34
35
|
PioneerProvider,
|
|
@@ -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);
|
|
@@ -240,14 +282,13 @@ export const PioneerProvider = ({
|
|
|
240
282
|
|
|
241
283
|
// @TODO add custom paths from localstorage
|
|
242
284
|
const paths: any = [];
|
|
285
|
+
console.log("VITE_PIONEER_URL_SPEC: ",)
|
|
243
286
|
const spec =
|
|
244
|
-
//@ts-ignore
|
|
245
|
-
import.meta.env.VITE_PIONEER_URL_SPEC ||
|
|
246
287
|
//@ts-ignore
|
|
247
288
|
"https://pioneers.dev/spec/swagger.json";
|
|
248
289
|
//@ts-ignore
|
|
249
290
|
console.log("spec: ", spec);
|
|
250
|
-
const wss =
|
|
291
|
+
const wss = "wss://pioneers.dev";
|
|
251
292
|
const configPioneer: any = {
|
|
252
293
|
blockchains,
|
|
253
294
|
username,
|
|
@@ -265,7 +306,18 @@ export const PioneerProvider = ({
|
|
|
265
306
|
// Example usage
|
|
266
307
|
let walletMetaMask: metaMask.MetaMaskHDWallet | undefined;
|
|
267
308
|
if (isMetaMaskAvailable()) {
|
|
268
|
-
//
|
|
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 ")
|
|
269
321
|
walletMetaMask = await metaMaskAdapter.pairDevice();
|
|
270
322
|
if (walletMetaMask) {
|
|
271
323
|
// pair metamask
|
|
@@ -291,7 +343,7 @@ export const PioneerProvider = ({
|
|
|
291
343
|
type: WalletActions.SET_PUBKEY_CONTEXT,
|
|
292
344
|
// @ts-ignore
|
|
293
345
|
payload: appInit.pubkeyContext?.master || appInit?.pubkey,
|
|
294
|
-
});
|
|
346
|
+
});
|
|
295
347
|
}
|
|
296
348
|
}
|
|
297
349
|
// @ts-ignore
|
|
@@ -301,12 +353,9 @@ export const PioneerProvider = ({
|
|
|
301
353
|
});
|
|
302
354
|
}
|
|
303
355
|
} else {
|
|
304
|
-
|
|
356
|
+
console.log("MetaMask is not available");
|
|
305
357
|
}
|
|
306
358
|
|
|
307
|
-
const isKeepkeyAvailable = await checkKeepkeyAvailability();
|
|
308
|
-
//console.log("isKeepkeyAvailable: ", isKeepkeyAvailable);
|
|
309
|
-
|
|
310
359
|
let walletKeepKey: core.HDWallet;
|
|
311
360
|
if (isKeepkeyAvailable) {
|
|
312
361
|
const config: any = {
|
|
File without changes
|