@pioneer-platform/pioneer-react 0.0.1 → 0.2.32
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/.eslintrc.js +24 -0
- package/.github/workflows/release.yml +22 -0
- package/.github/workflows/update-license.yml +11 -0
- package/.lintstagedrc.json +6 -0
- package/.prettierrc +7 -0
- package/.vscode/extensions.json +8 -0
- package/CHANGELOG.md +5 -0
- package/LICENSE +21 -0
- package/README.md +40 -0
- package/commitlint.config.js +3 -0
- package/dist/assets/404 Error-rafiki.svg +1 -0
- package/dist/assets/Building blocks-amico.svg +1 -0
- package/dist/assets/chakra-ui-logomark-colored.svg +10 -0
- package/dist/assets/favicon.svg +0 -0
- package/dist/assets/react-icon.svg +7 -0
- package/dist/assets/ts-logo-512.svg +1 -0
- package/dist/assets/vite-logo.svg +15 -0
- package/dist/index.js +384249 -0
- package/dist/index_3bde86fb.js +205 -0
- package/dist/index_49fce0b0.js +384033 -0
- package/dist/index_d01e819c.css +63 -0
- package/dist/manifest.json +12 -0
- package/dist/robots.txt +6 -0
- package/index.html +13 -0
- package/netlify.toml +10 -0
- package/package.json +70 -10
- package/public/assets/404 Error-rafiki.svg +1 -0
- package/public/assets/Building blocks-amico.svg +1 -0
- package/public/assets/chakra-ui-logomark-colored.svg +10 -0
- package/public/assets/favicon.svg +0 -0
- package/public/assets/react-icon.svg +7 -0
- package/public/assets/ts-logo-512.svg +1 -0
- package/public/assets/vite-logo.svg +15 -0
- package/public/manifest.json +12 -0
- package/public/robots.txt +6 -0
- package/renovate.json +11 -0
- package/src/App.tsx +21 -0
- package/src/index.tsx +41 -0
- package/src/lib/assets/Icons/KeepKeyIcon.tsx +13 -0
- package/src/lib/assets/Icons/KeplrIcon.tsx +140 -0
- package/src/lib/assets/Icons/MetaMaskIcon.tsx +126 -0
- package/src/lib/assets/Icons/TallyHoIcon.tsx +17 -0
- package/src/lib/assets/Icons/XDEFIIcon.tsx +32 -0
- package/src/lib/assets/favicon.ico +0 -0
- package/src/lib/assets/png/keepkey.png +0 -0
- package/src/lib/assets/png/keplr.png +0 -0
- package/src/lib/assets/png/metamask.png +0 -0
- package/src/lib/assets/png/pioneer.png +0 -0
- package/src/lib/components/AssetSelect/index.tsx +166 -0
- package/src/lib/components/BlockchainSelect/index.tsx +166 -0
- package/src/lib/components/MiddleEllipsis/index.tsx +27 -0
- package/src/lib/components/WalletSelect/index.tsx +112 -0
- package/src/lib/components/auth/RequireAuth.tsx +22 -0
- package/src/lib/components/modals/AssetModal.tsx +67 -0
- package/src/lib/components/modals/SettingsModal.tsx +76 -0
- package/src/lib/components/pioneer/Pioneer/Balances.tsx +266 -0
- package/src/lib/components/pioneer/Pioneer/MiddleEllipsis.tsx +27 -0
- package/src/lib/components/pioneer/Pioneer/Nodes.tsx +0 -0
- package/src/lib/components/pioneer/Pioneer/Paths.tsx +290 -0
- package/src/lib/components/pioneer/Pioneer/Pubkey.tsx +67 -0
- package/src/lib/components/pioneer/Pioneer/Pubkeys.tsx +265 -0
- package/src/lib/components/pioneer/Pioneer/Receive.tsx +26 -0
- package/src/lib/components/pioneer/Pioneer/Send.tsx +135 -0
- package/src/lib/components/pioneer/Pioneer/View.tsx +44 -0
- package/src/lib/components/pioneer/Pioneer/Wallets.tsx +166 -0
- package/src/lib/components/pioneer/index.tsx +525 -0
- package/src/lib/components/utils/index.tsx +47 -0
- package/src/lib/context/Pioneer/index.tsx +420 -0
- package/src/lib/layout/Footer.tsx +22 -0
- package/src/lib/layout/Header.tsx +38 -0
- package/src/lib/layout/Meta.tsx +25 -0
- package/src/lib/layout/Pioneer/Balances.tsx +290 -0
- package/src/lib/layout/Pioneer/MiddleEllipsis.tsx +27 -0
- package/src/lib/layout/Pioneer/Pubkey.tsx +67 -0
- package/src/lib/layout/Pioneer/Receive.tsx +26 -0
- package/src/lib/layout/Pioneer/Send.tsx +135 -0
- package/src/lib/layout/Pioneer/View.tsx +44 -0
- package/src/lib/layout/Pioneer/Wallets.tsx +166 -0
- package/src/lib/layout/ThemeToggle.tsx +16 -0
- package/src/lib/layout/index.tsx +29 -0
- package/src/lib/pages/404/index.tsx +36 -0
- package/src/lib/pages/home/components/CTASection.tsx +36 -0
- package/src/lib/pages/home/components/SomeImage.tsx +36 -0
- package/src/lib/pages/home/components/SomeText.tsx +16 -0
- package/src/lib/pages/home/index.tsx +87 -0
- package/src/lib/router/Routings.tsx +45 -0
- package/src/lib/router/routes.tsx +13 -0
- package/src/lib/styles/theme/config.ts +5 -0
- package/src/lib/styles/theme/index.ts +17 -0
- package/tsconfig.json +19 -9
- package/turbo.json +17 -0
- package/vercel.json +4 -0
- package/vite.config.ts +110 -0
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Pioneer SDK
|
|
3
|
+
|
|
4
|
+
A ultra-light bridge to the pioneer platform
|
|
5
|
+
|
|
6
|
+
, . , . .
|
|
7
|
+
* / \_ * / \_ .-. * * /\'__ *
|
|
8
|
+
/ \ / \, ( ₿ ) . _/ / \ *'.
|
|
9
|
+
. /\/\ /\/ :' __ \_ - _^/ ^/ `--.
|
|
10
|
+
/ \/ \ _/ \-'\ * /.' ^_ \_ .'\ *
|
|
11
|
+
/\ .- `. \/ \ /==~=-=~=-=-;. _/ \ -. `_/ \
|
|
12
|
+
/ `-.__ ^ / .-'.--\ =-=~_=-=~=^/ _ `--./ .-' `-
|
|
13
|
+
/ `. / / `.~-^=-=~=^=.-' '-._ `._
|
|
14
|
+
|
|
15
|
+
A Product of the CoinMasters Guild
|
|
16
|
+
- Highlander
|
|
17
|
+
|
|
18
|
+
Wallet Providers:
|
|
19
|
+
|
|
20
|
+
1. Metmask:
|
|
21
|
+
if metamask derivice pioneer seed from metamask
|
|
22
|
+
|
|
23
|
+
2. keepkey:
|
|
24
|
+
If keepkey detected: use it, otherwise use the native adapter
|
|
25
|
+
|
|
26
|
+
3. Native Adapter:
|
|
27
|
+
If no wallets, use the native adapter
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
Api Docs:
|
|
32
|
+
* https://pioneers.dev/docs/
|
|
33
|
+
Transaction Diagram
|
|
34
|
+
* https://github.com/BitHighlander/pioneer/blob/master/docs/pioneerTxs.png
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
*/
|
|
38
|
+
import { KkRestAdapter } from "@keepkey/hdwallet-keepkey-rest";
|
|
39
|
+
import { KeepKeySdk } from "@keepkey/keepkey-sdk";
|
|
40
|
+
import { SDK } from "@pioneer-sdk/sdk";
|
|
41
|
+
import * as core from "@shapeshiftoss/hdwallet-core";
|
|
42
|
+
// import * as keplr from "@shapeshiftoss/hdwallet-keplr";
|
|
43
|
+
import * as metaMask from "@shapeshiftoss/hdwallet-metamask";
|
|
44
|
+
import type { NativeHDWallet } from "@shapeshiftoss/hdwallet-native";
|
|
45
|
+
import { EventEmitter } from "events";
|
|
46
|
+
import { NativeAdapter } from "@shapeshiftoss/hdwallet-native";
|
|
47
|
+
import { entropyToMnemonic } from "bip39";
|
|
48
|
+
import {
|
|
49
|
+
createContext,
|
|
50
|
+
useReducer,
|
|
51
|
+
useContext,
|
|
52
|
+
useMemo,
|
|
53
|
+
useEffect,
|
|
54
|
+
useState,
|
|
55
|
+
} from "react";
|
|
56
|
+
import { v4 as uuidv4 } from "uuid";
|
|
57
|
+
|
|
58
|
+
import { checkKeepkeyAvailability, timeout } from "lib/components/utils";
|
|
59
|
+
|
|
60
|
+
const eventEmitter = new EventEmitter();
|
|
61
|
+
|
|
62
|
+
export enum WalletActions {
|
|
63
|
+
SET_STATUS = "SET_STATUS",
|
|
64
|
+
SET_USERNAME = "SET_USERNAME",
|
|
65
|
+
SET_API = "SET_API",
|
|
66
|
+
SET_APP = "SET_APP",
|
|
67
|
+
SET_WALLET = "SET_WALLET",
|
|
68
|
+
SET_WALLET_DESCRIPTIONS = "SET_WALLET_DESCRIPTIONS",
|
|
69
|
+
SET_CONTEXT = "SET_CONTEXT",
|
|
70
|
+
SET_ASSET_CONTEXT = "SET_ASSET_CONTEXT",
|
|
71
|
+
SET_BLOCKCHAIN_CONTEXT = "SET_BLOCKCHAIN_CONTEXT",
|
|
72
|
+
SET_PUBKEY_CONTEXT = "SET_PUBKEY_CONTEXT",
|
|
73
|
+
ADD_WALLET = "ADD_WALLET",
|
|
74
|
+
RESET_STATE = "RESET_STATE",
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface InitialState {
|
|
78
|
+
// keyring: Keyring;
|
|
79
|
+
status: any;
|
|
80
|
+
username: string;
|
|
81
|
+
serviceKey: string;
|
|
82
|
+
queryKey: string;
|
|
83
|
+
context: string;
|
|
84
|
+
assetContext: string;
|
|
85
|
+
blockchainContext: string;
|
|
86
|
+
pubkeyContext: string;
|
|
87
|
+
walletDescriptions: any[];
|
|
88
|
+
totalValueUsd: number;
|
|
89
|
+
app: any;
|
|
90
|
+
api: any;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const initialState: InitialState = {
|
|
94
|
+
status: "disconnected",
|
|
95
|
+
username: "",
|
|
96
|
+
serviceKey: "",
|
|
97
|
+
queryKey: "",
|
|
98
|
+
context: "",
|
|
99
|
+
assetContext: "",
|
|
100
|
+
blockchainContext: "",
|
|
101
|
+
pubkeyContext: "",
|
|
102
|
+
walletDescriptions: [],
|
|
103
|
+
totalValueUsd: 0,
|
|
104
|
+
app: null,
|
|
105
|
+
api: null,
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export interface IPioneerContext {
|
|
109
|
+
state: InitialState;
|
|
110
|
+
username: string | null;
|
|
111
|
+
context: string | null;
|
|
112
|
+
status: string | null;
|
|
113
|
+
totalValueUsd: number | null;
|
|
114
|
+
assetContext: string | null;
|
|
115
|
+
blockchainContext: string | null;
|
|
116
|
+
pubkeyContext: string | null;
|
|
117
|
+
app: any;
|
|
118
|
+
api: any;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export type ActionTypes =
|
|
122
|
+
| { type: WalletActions.SET_STATUS; payload: any }
|
|
123
|
+
| { type: WalletActions.SET_USERNAME; payload: string }
|
|
124
|
+
| { type: WalletActions.SET_APP; payload: any }
|
|
125
|
+
| { type: WalletActions.SET_API; payload: any }
|
|
126
|
+
| { type: WalletActions.SET_CONTEXT; payload: any }
|
|
127
|
+
| { type: WalletActions.SET_ASSET_CONTEXT; payload: any }
|
|
128
|
+
| { type: WalletActions.SET_BLOCKCHAIN_CONTEXT; payload: any }
|
|
129
|
+
| { type: WalletActions.SET_PUBKEY_CONTEXT; payload: any }
|
|
130
|
+
| { type: WalletActions.ADD_WALLET; payload: any }
|
|
131
|
+
| { type: WalletActions.RESET_STATE };
|
|
132
|
+
|
|
133
|
+
const reducer = (state: InitialState, action: ActionTypes) => {
|
|
134
|
+
switch (action.type) {
|
|
135
|
+
case WalletActions.SET_STATUS:
|
|
136
|
+
eventEmitter.emit("SET_STATUS", action.payload);
|
|
137
|
+
return { ...state, status: action.payload };
|
|
138
|
+
case WalletActions.SET_CONTEXT:
|
|
139
|
+
//eventEmitter.emit("SET_CONTEXT", action.payload);
|
|
140
|
+
return { ...state, context: action.payload };
|
|
141
|
+
case WalletActions.SET_ASSET_CONTEXT:
|
|
142
|
+
//eventEmitter.emit("SET_ASSET_CONTEXT", action.payload);
|
|
143
|
+
return { ...state, assetContext: action.payload };
|
|
144
|
+
case WalletActions.SET_BLOCKCHAIN_CONTEXT:
|
|
145
|
+
//eventEmitter.emit("SET_BLOCKCHAIN_CONTEXT", action.payload);
|
|
146
|
+
return { ...state, blockchainContext: action.payload };
|
|
147
|
+
case WalletActions.SET_PUBKEY_CONTEXT:
|
|
148
|
+
//eventEmitter.emit("SET_PUBKEY_CONTEXT", action.payload);
|
|
149
|
+
return { ...state, pubkeyContext: action.payload };
|
|
150
|
+
case WalletActions.SET_USERNAME:
|
|
151
|
+
//eventEmitter.emit("SET_USERNAME", action.payload);
|
|
152
|
+
return { ...state, username: action.payload };
|
|
153
|
+
case WalletActions.SET_APP:
|
|
154
|
+
return { ...state, app: action.payload };
|
|
155
|
+
case WalletActions.SET_API:
|
|
156
|
+
return { ...state, api: action.payload };
|
|
157
|
+
case WalletActions.RESET_STATE:
|
|
158
|
+
return {
|
|
159
|
+
...state,
|
|
160
|
+
api: null,
|
|
161
|
+
user: null,
|
|
162
|
+
username: null,
|
|
163
|
+
context: null,
|
|
164
|
+
status: null,
|
|
165
|
+
};
|
|
166
|
+
default:
|
|
167
|
+
return state;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const PioneerContext = createContext(initialState);
|
|
172
|
+
|
|
173
|
+
export const PioneerProvider = ({
|
|
174
|
+
children,
|
|
175
|
+
}: {
|
|
176
|
+
children: React.ReactNode;
|
|
177
|
+
}): JSX.Element => {
|
|
178
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
179
|
+
// @ts-ignore
|
|
180
|
+
const [state, dispatch] = useReducer(reducer, initialState);
|
|
181
|
+
|
|
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
|
+
// }
|
|
201
|
+
|
|
202
|
+
const onStart = async function () {
|
|
203
|
+
try {
|
|
204
|
+
// eslint-disable-next-line no-console
|
|
205
|
+
//console.log("onStart***** ");
|
|
206
|
+
const serviceKey: string | null = localStorage.getItem("serviceKey"); // KeepKey api key
|
|
207
|
+
let queryKey: string | null = localStorage.getItem("queryKey");
|
|
208
|
+
let username: string | null = localStorage.getItem("username");
|
|
209
|
+
//@ts-ignore
|
|
210
|
+
dispatch({ type: WalletActions.SET_USERNAME, payload: username });
|
|
211
|
+
|
|
212
|
+
const isMetaMaskAvailable = (): boolean => {
|
|
213
|
+
return (
|
|
214
|
+
(window as any).ethereum !== undefined &&
|
|
215
|
+
(window as any).ethereum.isMetaMask
|
|
216
|
+
);
|
|
217
|
+
};
|
|
218
|
+
const keyring = new core.Keyring();
|
|
219
|
+
const metaMaskAdapter = metaMask.MetaMaskAdapter.useKeyring(keyring);
|
|
220
|
+
|
|
221
|
+
if (!queryKey) {
|
|
222
|
+
queryKey = `key:${uuidv4()}`;
|
|
223
|
+
localStorage.setItem("queryKey", queryKey);
|
|
224
|
+
}
|
|
225
|
+
if (!username) {
|
|
226
|
+
username = `user:${uuidv4()}`;
|
|
227
|
+
username = username.substring(0, 13);
|
|
228
|
+
localStorage.setItem("username", username);
|
|
229
|
+
}
|
|
230
|
+
const blockchains = [
|
|
231
|
+
"bitcoin",
|
|
232
|
+
"ethereum",
|
|
233
|
+
"thorchain",
|
|
234
|
+
"bitcoincash",
|
|
235
|
+
"litecoin",
|
|
236
|
+
"binance",
|
|
237
|
+
"cosmos",
|
|
238
|
+
"dogecoin",
|
|
239
|
+
];
|
|
240
|
+
|
|
241
|
+
// @TODO add custom paths from localstorage
|
|
242
|
+
const paths: any = [];
|
|
243
|
+
const spec =
|
|
244
|
+
//@ts-ignore
|
|
245
|
+
import.meta.env.VITE_PIONEER_URL_SPEC ||
|
|
246
|
+
//@ts-ignore
|
|
247
|
+
"https://pioneers.dev/spec/swagger.json";
|
|
248
|
+
//@ts-ignore
|
|
249
|
+
console.log("spec: ", spec);
|
|
250
|
+
const wss = import.meta.env.VITE_PIONEER_URL_WS || "wss://pioneers.dev";
|
|
251
|
+
const configPioneer: any = {
|
|
252
|
+
blockchains,
|
|
253
|
+
username,
|
|
254
|
+
queryKey,
|
|
255
|
+
spec,
|
|
256
|
+
wss,
|
|
257
|
+
paths,
|
|
258
|
+
};
|
|
259
|
+
const appInit = new SDK(spec, configPioneer);
|
|
260
|
+
const api = await appInit.init();
|
|
261
|
+
// @ts-ignore
|
|
262
|
+
dispatch({ type: WalletActions.SET_API, payload: api });
|
|
263
|
+
// @ts-ignore
|
|
264
|
+
dispatch({ type: WalletActions.SET_APP, payload: appInit });
|
|
265
|
+
// Example usage
|
|
266
|
+
let walletMetaMask: metaMask.MetaMaskHDWallet | undefined;
|
|
267
|
+
if (isMetaMaskAvailable()) {
|
|
268
|
+
// //console.log("isMetaMaskAvailable ")
|
|
269
|
+
walletMetaMask = await metaMaskAdapter.pairDevice();
|
|
270
|
+
if (walletMetaMask) {
|
|
271
|
+
// pair metamask
|
|
272
|
+
await walletMetaMask.initialize();
|
|
273
|
+
//console.log("walletMetaMask: ", walletMetaMask);
|
|
274
|
+
|
|
275
|
+
// get all accounts
|
|
276
|
+
//@ts-ignore
|
|
277
|
+
const accounts = await window.ethereum.request({
|
|
278
|
+
method: "eth_requestAccounts",
|
|
279
|
+
});
|
|
280
|
+
//console.log("accounts: ", accounts);
|
|
281
|
+
//@ts-ignore
|
|
282
|
+
walletMetaMask.accounts = accounts;
|
|
283
|
+
|
|
284
|
+
const successMetaMask = await appInit.pairWallet(walletMetaMask);
|
|
285
|
+
console.log("successMetaMask: ", successMetaMask);
|
|
286
|
+
if(successMetaMask){
|
|
287
|
+
// @ts-ignore
|
|
288
|
+
if (appInit.pubkeyContext?.master || appInit?.pubkey){
|
|
289
|
+
// @ts-ignore
|
|
290
|
+
dispatch({
|
|
291
|
+
type: WalletActions.SET_PUBKEY_CONTEXT,
|
|
292
|
+
// @ts-ignore
|
|
293
|
+
payload: appInit.pubkeyContext?.master || appInit?.pubkey,
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
// @ts-ignore
|
|
298
|
+
dispatch({
|
|
299
|
+
type: WalletActions.SET_STATUS,
|
|
300
|
+
payload: "MetaMask connected!",
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
} else {
|
|
304
|
+
//console.log("MetaMask is not available");
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const isKeepkeyAvailable = await checkKeepkeyAvailability();
|
|
308
|
+
//console.log("isKeepkeyAvailable: ", isKeepkeyAvailable);
|
|
309
|
+
|
|
310
|
+
let walletKeepKey: core.HDWallet;
|
|
311
|
+
if (isKeepkeyAvailable) {
|
|
312
|
+
const config: any = {
|
|
313
|
+
apiKey: serviceKey || "notSet",
|
|
314
|
+
pairingInfo: {
|
|
315
|
+
name: "Pioneer",
|
|
316
|
+
imageUrl: "https://i.imgur.com/BdyyJZS.png",
|
|
317
|
+
basePath: "http://localhost:1646/spec/swagger.json",
|
|
318
|
+
url: "https://pioneer-template.vercel.com",
|
|
319
|
+
},
|
|
320
|
+
};
|
|
321
|
+
const sdkKeepKey = await KeepKeySdk.create(config);
|
|
322
|
+
if (config.apiKey !== serviceKey) {
|
|
323
|
+
localStorage.setItem("serviceKey", config.apiKey);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
try {
|
|
327
|
+
//@ts-ignore
|
|
328
|
+
walletKeepKey = await Promise.race([
|
|
329
|
+
//@ts-ignore
|
|
330
|
+
KkRestAdapter.useKeyring(keyring).pairDevice(sdkKeepKey),
|
|
331
|
+
timeout(30000),
|
|
332
|
+
]);
|
|
333
|
+
// pair keepkey
|
|
334
|
+
const successKeepKey = await appInit.pairWallet(walletKeepKey);
|
|
335
|
+
//console.log("successKeepKey: ", successKeepKey);
|
|
336
|
+
//@ts-ignore
|
|
337
|
+
dispatch({ type: WalletActions.ADD_WALLET, payload: walletKeepKey });
|
|
338
|
+
// @ts-ignore
|
|
339
|
+
dispatch({
|
|
340
|
+
type: WalletActions.SET_STATUS,
|
|
341
|
+
payload: "KeepKey connected!",
|
|
342
|
+
});
|
|
343
|
+
} catch (error) {
|
|
344
|
+
//@ts-ignore
|
|
345
|
+
console.error("Error or Timeout:", error.message);
|
|
346
|
+
alert("Please restart your KeepKey and try again.");
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
let walletSoftware: NativeHDWallet | null;
|
|
351
|
+
let mnemonic;
|
|
352
|
+
let hashStored;
|
|
353
|
+
let hash;
|
|
354
|
+
const nativeAdapter = NativeAdapter.useKeyring(keyring);
|
|
355
|
+
//is metamask available AND no KeepKey
|
|
356
|
+
hashStored = localStorage.getItem("hash");
|
|
357
|
+
|
|
358
|
+
if (hashStored) {
|
|
359
|
+
//generate software from metamask
|
|
360
|
+
//console.log('hashStored: ', hashStored);
|
|
361
|
+
const hashSplice = (str: string | any[] | null) => {
|
|
362
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
363
|
+
// @ts-ignore
|
|
364
|
+
return str.slice(0, 34);
|
|
365
|
+
};
|
|
366
|
+
// @ts-ignore
|
|
367
|
+
hash = hashSplice(hashStored);
|
|
368
|
+
// eslint-disable-next-line no-console
|
|
369
|
+
//console.log('hash (trimmed): ', hash);
|
|
370
|
+
// @ts-ignore
|
|
371
|
+
const hashBytes = hash.replace("0x", "");
|
|
372
|
+
//console.log('hashBytes', hashBytes);
|
|
373
|
+
//console.log('hashBytes', hashBytes.length);
|
|
374
|
+
mnemonic = entropyToMnemonic(hashBytes.toString(`hex`));
|
|
375
|
+
|
|
376
|
+
// get walletSoftware
|
|
377
|
+
walletSoftware = await nativeAdapter.pairDevice("testid");
|
|
378
|
+
await nativeAdapter.initialize();
|
|
379
|
+
// @ts-ignore
|
|
380
|
+
await walletSoftware.loadDevice({ mnemonic });
|
|
381
|
+
const successSoftware = await appInit.pairWallet(walletSoftware);
|
|
382
|
+
//console.log("successSoftware: ", successSoftware);
|
|
383
|
+
|
|
384
|
+
//events!
|
|
385
|
+
const events = await appInit.startSocket();
|
|
386
|
+
|
|
387
|
+
events.on("message", (event: any) => {
|
|
388
|
+
//console.log("message: ", event);
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
events.on("blocks", (event: any) => {
|
|
392
|
+
//console.log("blocks: ", event);
|
|
393
|
+
// @ts-ignore
|
|
394
|
+
dispatch({
|
|
395
|
+
type: WalletActions.SET_STATUS,
|
|
396
|
+
payload: "Block Scanned!",
|
|
397
|
+
});
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
} catch (e) {
|
|
401
|
+
// eslint-disable-next-line no-console
|
|
402
|
+
console.error(e);
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
// onstart get data
|
|
407
|
+
useEffect(() => {
|
|
408
|
+
onStart();
|
|
409
|
+
}, []);
|
|
410
|
+
|
|
411
|
+
// end
|
|
412
|
+
const value: any = useMemo(() => ({ state, dispatch }), [state]);
|
|
413
|
+
|
|
414
|
+
return (
|
|
415
|
+
<PioneerContext.Provider value={value}>{children}</PioneerContext.Provider>
|
|
416
|
+
);
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
export const usePioneer = (): any =>
|
|
420
|
+
useContext(PioneerContext as unknown as React.Context<IPioneerContext>);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Flex, Link, Text } from "@chakra-ui/react";
|
|
2
|
+
|
|
3
|
+
const Footer = () => {
|
|
4
|
+
return (
|
|
5
|
+
<Flex
|
|
6
|
+
as="footer"
|
|
7
|
+
width="full"
|
|
8
|
+
align="center"
|
|
9
|
+
alignSelf="flex-end"
|
|
10
|
+
justifyContent="center"
|
|
11
|
+
>
|
|
12
|
+
<Text fontSize="xs">
|
|
13
|
+
{new Date().getFullYear()} -{" "}
|
|
14
|
+
<Link href="https://pioneers.dev" isExternal>
|
|
15
|
+
pioneers.dev
|
|
16
|
+
</Link>
|
|
17
|
+
</Text>
|
|
18
|
+
</Flex>
|
|
19
|
+
);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default Footer;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Box, Flex, HStack, Text } from "@chakra-ui/react";
|
|
2
|
+
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
import { Link as RouterLink } from "react-router-dom";
|
|
6
|
+
|
|
7
|
+
import Pioneer from "lib/components/pioneer";
|
|
8
|
+
|
|
9
|
+
const PROJECT_NAME = "*Your Project name here*";
|
|
10
|
+
// eslint-disable-next-line no-console
|
|
11
|
+
const HeaderNew = () => {
|
|
12
|
+
return (
|
|
13
|
+
<Flex
|
|
14
|
+
as="header"
|
|
15
|
+
width="full"
|
|
16
|
+
alignSelf="flex-start"
|
|
17
|
+
gridGap={2}
|
|
18
|
+
justifyContent={"space-between"}
|
|
19
|
+
alignItems="center"
|
|
20
|
+
p={5}
|
|
21
|
+
bg="gray.900" // change background color
|
|
22
|
+
borderBottom="1px solid" // add a border at the bottom
|
|
23
|
+
borderColor="gray.200" // set border color
|
|
24
|
+
>
|
|
25
|
+
<HStack spacing={8}>
|
|
26
|
+
<RouterLink to="/">
|
|
27
|
+
<Box>
|
|
28
|
+
<Text fontSize="3xl">{PROJECT_NAME}</Text>
|
|
29
|
+
</Box>
|
|
30
|
+
</RouterLink>
|
|
31
|
+
</HStack>
|
|
32
|
+
<br />
|
|
33
|
+
<Pioneer />
|
|
34
|
+
</Flex>
|
|
35
|
+
);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export default HeaderNew;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Helmet } from "react-helmet";
|
|
2
|
+
|
|
3
|
+
const APP_NAME = "Pioneer Template";
|
|
4
|
+
|
|
5
|
+
const Meta = () => {
|
|
6
|
+
return (
|
|
7
|
+
<Helmet>
|
|
8
|
+
<title>{APP_NAME}</title>
|
|
9
|
+
<meta name="description" content="Pioneer Template" />
|
|
10
|
+
|
|
11
|
+
<meta name="application-name" content={APP_NAME} />
|
|
12
|
+
<meta name="apple-mobile-web-app-capable" content="yes" />
|
|
13
|
+
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
|
|
14
|
+
<meta name="apple-mobile-web-app-title" content={APP_NAME} />
|
|
15
|
+
<meta name="format-detection" content="telephone=no" />
|
|
16
|
+
<meta name="mobile-web-app-capable" content="yes" />
|
|
17
|
+
<meta name="theme-color" content="#228B22" />
|
|
18
|
+
|
|
19
|
+
<link rel="shortcut icon" href="/assets/favicon.svg" />
|
|
20
|
+
<link rel="manifest" href="/manifest.json" />
|
|
21
|
+
</Helmet>
|
|
22
|
+
);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default Meta;
|