@pioneer-platform/pioneer-react 0.2.36 → 0.2.37

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 CHANGED
@@ -102719,7 +102719,7 @@ CAUSE: ${cause === null || cause === void 0 ? void 0 : cause.stack}`;
102719
102719
  };
102720
102720
  var REGISTRATION_IN_PROGRESS = "REGISTRATION_IN_PROGRESS";
102721
102721
  var FORWARDER_ID = "FORWARDER_ID";
102722
- var Onboarding = (
102722
+ var Onboarding$1 = (
102723
102723
  /** @class */
102724
102724
  function() {
102725
102725
  function Onboarding2(_a2) {
@@ -102877,7 +102877,7 @@ CAUSE: ${cause === null || cause === void 0 ? void 0 : cause.stack}`;
102877
102877
  );
102878
102878
  const metamaskOnboarding_es = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
102879
102879
  __proto__: null,
102880
- default: Onboarding
102880
+ default: Onboarding$1
102881
102881
  }, Symbol.toStringTag, { value: "Module" }));
102882
102882
  const require$$1$9 = /* @__PURE__ */ getAugmentedNamespace(metamaskOnboarding_es);
102883
102883
  var dist$7 = {};
@@ -149764,7 +149764,7 @@ CAUSE: ${cause === null || cause === void 0 ? void 0 : cause.stack}`;
149764
149764
  rng2 = rng2 || ((size2) => buffer$2.Buffer.from(utils_1$l.randomBytes(size2)));
149765
149765
  return entropyToMnemonic(rng2(strength / 8), wordlist2);
149766
149766
  }
149767
- src$3.generateMnemonic = generateMnemonic;
149767
+ var generateMnemonic_1 = src$3.generateMnemonic = generateMnemonic;
149768
149768
  function validateMnemonic(mnemonic, wordlist2) {
149769
149769
  try {
149770
149770
  mnemonicToEntropy(mnemonic, wordlist2);
@@ -393793,14 +393793,116 @@ Proven: ${(0, encoding_1$e.toHex)(op2.key)}`);
393793
393793
  ] })
393794
393794
  ] });
393795
393795
  }
393796
+ const Onboarding = ({ onClose }) => {
393797
+ const { state: state2, dispatch: dispatch2 } = usePioneer();
393798
+ const { api: api2, app, user, context: context2 } = state2;
393799
+ const [walletDescriptions, setWalletDescriptions] = React.useState([]);
393800
+ const [balances, setBalances] = React.useState([]);
393801
+ React.useState(false);
393802
+ React.useState(false);
393803
+ React.useState(false);
393804
+ React.useState("");
393805
+ React.useState("");
393806
+ const [seedPhrase, setSeedPhrase] = React.useState("");
393807
+ const [error2, setError] = React.useState(null);
393808
+ const [isValid, setIsValid] = React.useState(false);
393809
+ const [action, setAction] = React.useState(null);
393810
+ const setUser = async function() {
393811
+ try {
393812
+ if (user && user.wallets) {
393813
+ const { wallets, walletDescriptions: walletDescriptions2, balances: balances2, pubkeys: pubkeys2 } = user;
393814
+ setWalletDescriptions(walletDescriptions2);
393815
+ setBalances(balances2);
393816
+ }
393817
+ } catch (e2) {
393818
+ console.error("header e: ", e2);
393819
+ }
393820
+ };
393821
+ React.useEffect(() => {
393822
+ setUser();
393823
+ }, [user]);
393824
+ React.useEffect(() => {
393825
+ const words2 = seedPhrase.trim().split(" ");
393826
+ if (words2.length === 12 && words2.every((word) => word.length > 0)) {
393827
+ setError(null);
393828
+ setIsValid(true);
393829
+ } else {
393830
+ setError("Seed phrase must be exactly 12 words");
393831
+ setIsValid(false);
393832
+ }
393833
+ }, [seedPhrase]);
393834
+ const handleSubmit = (event2) => {
393835
+ event2.preventDefault();
393836
+ if (isValid) {
393837
+ console.log("Seed Phrase Submitted:", seedPhrase);
393838
+ localStorage.setItem("seedPhrase", seedPhrase);
393839
+ localStorage.setItem("isOnboarded", "true");
393840
+ alert("Wallet Saved to localstorage. please restart app /n (Note: this is not secure! use a hardware wallet!)");
393841
+ onClose();
393842
+ }
393843
+ };
393844
+ const handleImport = () => {
393845
+ setSeedPhrase("");
393846
+ setAction("import");
393847
+ };
393848
+ const handleGenerate = () => {
393849
+ const newSeedPhrase = generateMnemonic_1();
393850
+ setSeedPhrase(newSeedPhrase);
393851
+ setAction("generate");
393852
+ };
393853
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs(react.Box, { children: [
393854
+ "Welcome to Pioneer SDK! Please select a wallet to continue.",
393855
+ /* @__PURE__ */ jsxRuntimeExports.jsx("br", {}),
393856
+ /* @__PURE__ */ jsxRuntimeExports.jsx(react.Avatar, { size: "lg", src: PIONEER_ICON }),
393857
+ action ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
393858
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("form", { onSubmit: handleSubmit, children: [
393859
+ /* @__PURE__ */ jsxRuntimeExports.jsxs(react.FormControl, { isInvalid: !!error2, children: [
393860
+ /* @__PURE__ */ jsxRuntimeExports.jsx(react.FormLabel, { htmlFor: "seedPhrase", children: "Seed Phrase" }),
393861
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
393862
+ react.Input,
393863
+ {
393864
+ id: "seedPhrase",
393865
+ name: "seedPhrase",
393866
+ type: "text",
393867
+ value: seedPhrase,
393868
+ onChange: (e2) => setSeedPhrase(e2.target.value),
393869
+ borderColor: isValid ? "green.500" : "red.500"
393870
+ }
393871
+ ),
393872
+ /* @__PURE__ */ jsxRuntimeExports.jsx(react.FormErrorMessage, { children: error2 })
393873
+ ] }),
393874
+ /* @__PURE__ */ jsxRuntimeExports.jsx(react.Button, { mt: 4, colorScheme: "teal", type: "submit", children: "Submit" })
393875
+ ] }),
393876
+ /* @__PURE__ */ jsxRuntimeExports.jsx(react.Button, { mt: 4, onClick: () => setAction(null), children: "Go Back" })
393877
+ ] }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(react.VStack, { spacing: 4, children: [
393878
+ /* @__PURE__ */ jsxRuntimeExports.jsx(react.Button, { colorScheme: "teal", onClick: handleGenerate, children: "Generate New Seed Phrase" }),
393879
+ /* @__PURE__ */ jsxRuntimeExports.jsx(react.Button, { colorScheme: "teal", onClick: handleImport, children: "Import Seed Phrase" })
393880
+ ] })
393881
+ ] });
393882
+ };
393796
393883
  const SettingsModal = ({ isOpen, onClose }) => {
393797
393884
  const { state: state2 } = usePioneer();
393798
393885
  const { app, status: status2 } = state2;
393886
+ const [isOnboarded, setIsOnboarded] = React.useState(false);
393887
+ const onStart = async function() {
393888
+ try {
393889
+ console.log("onStart");
393890
+ let isOnboarded2 = await localStorage.getItem("isOnboarded");
393891
+ if (!isOnboarded2) {
393892
+ console.log("Starting onboarding process");
393893
+ }
393894
+ } catch (e2) {
393895
+ console.error(e2);
393896
+ }
393897
+ };
393898
+ React.useEffect(() => {
393899
+ onStart();
393900
+ }, []);
393799
393901
  React.useEffect(() => {
393800
393902
  }, [app, app == null ? void 0 : app.balances, app == null ? void 0 : app.pubkeys, app == null ? void 0 : app.wallets, app == null ? void 0 : app.paths, status2]);
393801
393903
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(react.Modal, { isOpen, onClose, size: "xl", children: [
393802
393904
  /* @__PURE__ */ jsxRuntimeExports.jsx(react.ModalOverlay, {}),
393803
- /* @__PURE__ */ jsxRuntimeExports.jsxs(react.ModalContent, { children: [
393905
+ /* @__PURE__ */ jsxRuntimeExports.jsx(react.ModalContent, { children: !isOnboarded ? /* @__PURE__ */ jsxRuntimeExports.jsx(Onboarding, { onClose }) : /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
393804
393906
  /* @__PURE__ */ jsxRuntimeExports.jsx(react.ModalHeader, { children: "Pioneer Settings" }),
393805
393907
  /* @__PURE__ */ jsxRuntimeExports.jsx(react.ModalCloseButton, {}),
393806
393908
  /* @__PURE__ */ jsxRuntimeExports.jsx(react.ModalBody, { children: /* @__PURE__ */ jsxRuntimeExports.jsxs(react.Tabs, { variant: "enclosed", children: [
@@ -393817,7 +393919,7 @@ Proven: ${(0, encoding_1$e.toHex)(op2.key)}`);
393817
393919
  ] })
393818
393920
  ] }) }),
393819
393921
  /* @__PURE__ */ jsxRuntimeExports.jsx(react.ModalFooter, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(react.Button, { colorScheme: "blue", mr: 3, onClick: onClose, children: "Close" }) })
393820
- ] })
393922
+ ] }) })
393821
393923
  ] });
393822
393924
  };
393823
393925
  const getWalletBadgeContent = (walletType) => {
@@ -393866,6 +393968,21 @@ Proven: ${(0, encoding_1$e.toHex)(op2.key)}`);
393866
393968
  React.useState(false);
393867
393969
  React.useState([]);
393868
393970
  const [balances, setBalances] = React.useState([]);
393971
+ const onStart = async function() {
393972
+ try {
393973
+ console.log("onStart");
393974
+ let isOnboarded = await localStorage.getItem("isOnboarded");
393975
+ if (!isOnboarded) {
393976
+ console.log("Starting onboarding process");
393977
+ onOpen();
393978
+ }
393979
+ } catch (e2) {
393980
+ console.error(e2);
393981
+ }
393982
+ };
393983
+ React.useEffect(() => {
393984
+ onStart();
393985
+ }, []);
393869
393986
  const settingsSelected = async function() {
393870
393987
  try {
393871
393988
  onOpen();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pioneer-platform/pioneer-react",
3
- "version": "0.2.36",
3
+ "version": "0.2.37",
4
4
  "author": "highlander",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -128,6 +128,8 @@ const Onboarding: React.FC<ModalProps> = ({ onClose }) => {
128
128
  localStorage.setItem("seedPhrase", seedPhrase);
129
129
  // @ts-ignore
130
130
  localStorage.setItem("isOnboarded", "true");
131
+ alert("Wallet Saved to localstorage. please restart app /n (Note: this is not secure! use a hardware wallet!)");
132
+ onClose()
131
133
  }
132
134
  };
133
135
 
@@ -18,6 +18,7 @@ import Balances from "lib/components/pioneer/Pioneer/Balances";
18
18
  import Wallets from "lib/components/pioneer/Pioneer/Wallets";
19
19
  import Paths from "lib/components/pioneer/Pioneer/Paths";
20
20
  import Pubkeys from "lib/components/pioneer/Pioneer/Pubkeys";
21
+ import Onboarding from "lib/components/Onboarding";
21
22
  import { usePioneer } from "lib/context/Pioneer";
22
23
 
23
24
  interface SettingsModalProps {
@@ -28,6 +29,22 @@ interface SettingsModalProps {
28
29
  const SettingsModal: React.FC<SettingsModalProps> = ({ isOpen, onClose }) => {
29
30
  const { state } = usePioneer();
30
31
  const { app, status } = state;
32
+ const [isOnboarded, setIsOnboarded] = useState(false);
33
+
34
+ const onStart = async function(){
35
+ try{
36
+ console.log("onStart")
37
+ let isOnboarded = await localStorage.getItem("isOnboarded")
38
+ if(!isOnboarded){
39
+ console.log("Starting onboarding process")
40
+ }
41
+ }catch(e){
42
+ console.error(e)
43
+ }
44
+ }
45
+ useEffect(() => {
46
+ onStart()
47
+ }, []);
31
48
 
32
49
  useEffect(() => {
33
50
  //console.log("app: ", app);
@@ -37,37 +54,39 @@ const SettingsModal: React.FC<SettingsModalProps> = ({ isOpen, onClose }) => {
37
54
  <Modal isOpen={isOpen} onClose={onClose} size={"xl"}>
38
55
  <ModalOverlay />
39
56
  <ModalContent>
40
- <ModalHeader>Pioneer Settings</ModalHeader>
41
- <ModalCloseButton />
42
- <ModalBody>
43
- <Tabs variant="enclosed">
44
- <TabList>
45
- <Tab>Wallets</Tab>
46
- <Tab>Nodes</Tab>
47
- <Tab>PubKeys</Tab>
48
- <Tab>Balances</Tab>
49
- </TabList>
50
- <TabPanels>
51
- <TabPanel>
52
- <Wallets wallets={app?.wallets || []} />
53
- </TabPanel>
54
- {/*<TabPanel>*/}
55
- {/* <Paths paths={app?.paths || []} />*/}
56
- {/*</TabPanel>*/}
57
- <TabPanel>
58
- <Pubkeys pubkeys={app?.pubkeys || []} />
59
- </TabPanel>
60
- <TabPanel>
61
- <Balances balances={app?.balances || []} />
62
- </TabPanel>
63
- </TabPanels>
64
- </Tabs>
65
- </ModalBody>
66
- <ModalFooter>
67
- <Button colorScheme="blue" mr={3} onClick={onClose}>
68
- Close
69
- </Button>
70
- </ModalFooter>
57
+ {!isOnboarded ? (<Onboarding onClose={onClose} />) : (<div>
58
+ <ModalHeader>Pioneer Settings</ModalHeader>
59
+ <ModalCloseButton />
60
+ <ModalBody>
61
+ <Tabs variant="enclosed">
62
+ <TabList>
63
+ <Tab>Wallets</Tab>
64
+ <Tab>Nodes</Tab>
65
+ <Tab>PubKeys</Tab>
66
+ <Tab>Balances</Tab>
67
+ </TabList>
68
+ <TabPanels>
69
+ <TabPanel>
70
+ <Wallets wallets={app?.wallets || []} />
71
+ </TabPanel>
72
+ {/*<TabPanel>*/}
73
+ {/* <Paths paths={app?.paths || []} />*/}
74
+ {/*</TabPanel>*/}
75
+ <TabPanel>
76
+ <Pubkeys pubkeys={app?.pubkeys || []} />
77
+ </TabPanel>
78
+ <TabPanel>
79
+ <Balances balances={app?.balances || []} />
80
+ </TabPanel>
81
+ </TabPanels>
82
+ </Tabs>
83
+ </ModalBody>
84
+ <ModalFooter>
85
+ <Button colorScheme="blue" mr={3} onClick={onClose}>
86
+ Close
87
+ </Button>
88
+ </ModalFooter>
89
+ </div>)}
71
90
  </ModalContent>
72
91
  </Modal>
73
92
  );
@@ -136,6 +136,22 @@ const Pioneer = () => {
136
136
  const [pubkeys, setPubkeys] = useState([]);
137
137
  const [balances, setBalances] = useState([]);
138
138
 
139
+ const onStart = async function(){
140
+ try{
141
+ console.log("onStart")
142
+ let isOnboarded = await localStorage.getItem("isOnboarded")
143
+ if(!isOnboarded){
144
+ console.log("Starting onboarding process")
145
+ onOpen();
146
+ }
147
+ }catch(e){
148
+ console.error(e)
149
+ }
150
+ }
151
+ useEffect(() => {
152
+ onStart()
153
+ }, []);
154
+
139
155
  const settingsSelected = async function () {
140
156
  try {
141
157
  //console.log("settingsSelected");
@@ -248,9 +264,12 @@ const Pioneer = () => {
248
264
  dispatch({ type: "SET_PUBKEY_CONTEXT", payload: pubkeyContext });
249
265
  }
250
266
  }
267
+
251
268
  //if address[0] !== pubkey
252
269
 
253
- // re-register metamask with more pubkeys
270
+ //
271
+
272
+
254
273
  });
255
274
  }
256
275
  } catch (e) {
@@ -14,7 +14,6 @@ import { usePioneer } from "lib/context/Pioneer";
14
14
  import AssetSelect from "lib/components/AssetSelect";
15
15
  import BlockchainSelect from "lib/components/BlockchainSelect";
16
16
  import WalletSelect from "lib/components/WalletSelect";
17
- import Onboarding from "lib/components/Onboarding";
18
17
 
19
18
  const Home = () => {
20
19
  const { state } = usePioneer();
@@ -24,22 +23,6 @@ const Home = () => {
24
23
  const [modalType, setModalType] = useState("");
25
24
  const { isOpen, onOpen, onClose } = useDisclosure();
26
25
 
27
- const onStart = async function(){
28
- try{
29
- console.log("onStart")
30
- let isOnboarded = await localStorage.getItem("isOnboarded")
31
- if(!isOnboarded){
32
- console.log("Starting onboarding process")
33
- openModal("Onboarding")
34
- }
35
- }catch(e){
36
- console.error(e)
37
- }
38
- }
39
- useEffect(() => {
40
- onStart()
41
- }, []);
42
-
43
26
 
44
27
  useEffect(() => {
45
28
  console.log("2 pubkeyContext: ", pubkeyContext);
@@ -88,11 +71,6 @@ const Home = () => {
88
71
  <BlockchainSelect onClose={onClose}></BlockchainSelect>
89
72
  </div>
90
73
  )}
91
- {modalType === "Onboarding" && (
92
- <div>
93
- <Onboarding onClose={onClose}></Onboarding>
94
- </div>
95
- )}
96
74
  </ModalBody>
97
75
  <ModalFooter>
98
76
  <Button colorScheme="blue" onClick={onClose}>
@@ -1,290 +0,0 @@
1
- import { Search2Icon } from "@chakra-ui/icons";
2
- import {
3
- Avatar,
4
- AvatarBadge,
5
- Box,
6
- Button,
7
- HStack,
8
- Stack,
9
- Image,
10
- Modal,
11
- ModalOverlay,
12
- ModalContent,
13
- ModalHeader,
14
- ModalCloseButton,
15
- ModalBody,
16
- ModalFooter,
17
- useDisclosure,
18
- InputGroup,
19
- InputLeftElement,
20
- Input,
21
- } from "@chakra-ui/react";
22
- import React, { useState, useEffect } from "react";
23
-
24
- //@ts-ignore
25
- import KEEPKEY_ICON from "lib/assets/png/keepkey.png";
26
- //@ts-ignore
27
- import METAMASK_ICON from "lib/assets/png/metamask.png";
28
- //@ts-ignore
29
- import PIONEER_ICON from "lib/assets/png/pioneer.png";
30
- import { usePioneer } from "lib/context/Pioneer";
31
-
32
- import Receive from "./Receive";
33
- import Send from "./Send";
34
- import View from "./View";
35
-
36
- // Import icons
37
- // @ts-ignore
38
- // @ts-ignore
39
- // @ts-ignore
40
-
41
- interface Balance {
42
- image?: string;
43
- symbol: string;
44
- name?: string;
45
- balance?: any;
46
- size?: string;
47
- context?: string; // Added context field
48
- }
49
-
50
- const getWalletType = (user: { walletDescriptions: any[] }, context: any) => {
51
- if (user && user.walletDescriptions) {
52
- const wallet = user.walletDescriptions.find((w) => w.id === context);
53
- return wallet ? wallet.type : null;
54
- }
55
- return null;
56
- };
57
-
58
- const getWalletBadgeContent = (walletType: string) => {
59
- const icons: any = {
60
- metamask: METAMASK_ICON,
61
- keepkey: KEEPKEY_ICON,
62
- native: PIONEER_ICON,
63
- };
64
-
65
- const icon = icons[walletType];
66
-
67
- if (!icon) {
68
- return null;
69
- }
70
-
71
- return (
72
- <AvatarBadge boxSize="1.25em" bg="green.500">
73
- <Image rounded="full" src={icon} />
74
- </AvatarBadge>
75
- );
76
- };
77
-
78
- export default function Balances({ balances }: { balances: Balance[] }) {
79
- const { state, dispatch } = usePioneer();
80
- const { user } = state;
81
- const [currentPage, setCurrentPage] = useState(1);
82
- const [selectedBalance, setSelectedBalance] = useState<Balance | null>(null);
83
- const [selectedAction, setSelectedAction] = useState<string | null>(null);
84
- const { isOpen, onOpen, onClose } = useDisclosure();
85
- const [searchQuery, setSearchQuery] = useState("");
86
- const balancesPerPage = 3;
87
-
88
- const handlePageChange = (pageNumber: any) => {
89
- setCurrentPage(pageNumber);
90
- };
91
-
92
- const handleSendClick = (balance: Balance) => {
93
- setSelectedBalance(balance);
94
- setSelectedAction("send");
95
- onOpen();
96
- };
97
-
98
- const handleReceiveClick = (balance: Balance) => {
99
- setSelectedBalance(balance);
100
- setSelectedAction("receive");
101
- onOpen();
102
- };
103
-
104
- const handleViewClick = (balance: Balance) => {
105
- setSelectedBalance(balance);
106
- setSelectedAction("view");
107
- onOpen();
108
- };
109
-
110
- useEffect(() => {
111
- const setUser = async () => {
112
- try {
113
- if (user && user.wallets) {
114
- const { walletDescriptions, balances } = user;
115
- // console.log("walletDescriptions: ", walletDescriptions);
116
- const updatedBalances = balances.map((balance: Balance) => {
117
- const walletType = getWalletType(user, balance.context);
118
- const badgeContent = getWalletBadgeContent(walletType);
119
- // @ts-ignore
120
- return {
121
- ...balance,
122
- context: {
123
- // @ts-ignore
124
- ...balance.context,
125
- badge: badgeContent,
126
- },
127
- };
128
- });
129
- dispatch({ type: "SET_BALANCES", payload: updatedBalances });
130
- }
131
- } catch (e) {
132
- console.error("Error: ", e);
133
- }
134
- };
135
-
136
- setUser();
137
- }, [user]);
138
-
139
- // Filter and sort balances based on search query
140
- const filteredBalances = balances.filter((balance: Balance) => {
141
- // Convert the search query and balance symbol/name to lowercase for case-insensitive search
142
- const query = searchQuery.toLowerCase();
143
- const symbol = balance.symbol.toLowerCase();
144
- const name = balance.name ? balance.name.toLowerCase() : "";
145
-
146
- // Check if the symbol or name contains the search query
147
- return symbol.includes(query) || name.includes(query);
148
- });
149
-
150
- const sortedBalances = filteredBalances.sort(
151
- (a: Balance, b: Balance) => b.balance - a.balance
152
- );
153
- const currentBalances = sortedBalances.slice(
154
- (currentPage - 1) * balancesPerPage,
155
- currentPage * balancesPerPage
156
- );
157
- const totalPages = Math.ceil(filteredBalances.length / balancesPerPage);
158
-
159
- // Function to generate custom pagination array
160
- const generatePaginationArray = () => {
161
- const paginationArray = [];
162
- const totalPageButtons = 5; // Number of page buttons to display around the current page
163
-
164
- if (totalPages <= totalPageButtons) {
165
- // If total pages are less than or equal to totalPageButtons, show all page numbers
166
- for (let i = 1; i <= totalPages; i++) {
167
- paginationArray.push(i);
168
- }
169
- } else {
170
- // If total pages are more than totalPageButtons, generate custom pagination
171
- const middleButton = Math.floor(totalPageButtons / 2);
172
- const startPage = Math.max(currentPage - middleButton, 1);
173
- const endPage = Math.min(currentPage + middleButton, totalPages);
174
-
175
- if (startPage > 1) {
176
- // Add the first page and ellipsis if the current page is far enough from the first page
177
- paginationArray.push(1, "...");
178
- }
179
-
180
- // Add page numbers between startPage and endPage (inclusive)
181
- for (let i = startPage; i <= endPage; i++) {
182
- paginationArray.push(i);
183
- }
184
-
185
- if (endPage < totalPages) {
186
- // Add the last page and ellipsis if the current page is far enough from the last page
187
- paginationArray.push("...", totalPages);
188
- }
189
- }
190
-
191
- return paginationArray;
192
- };
193
-
194
- return (
195
- <Stack spacing={4}>
196
- <InputGroup>
197
- <InputLeftElement pointerEvents="none">
198
- <Search2Icon color="gray.300" />
199
- </InputLeftElement>
200
- <Input
201
- placeholder="Bitcoin..."
202
- type="text"
203
- value={searchQuery}
204
- onChange={(e) => setSearchQuery(e.target.value)}
205
- />
206
- </InputGroup>
207
- {currentBalances.map((balance: Balance, index: number) => (
208
- <Box key={index}>
209
- <HStack spacing={4} alignItems="center">
210
- <Avatar src={balance.image} />
211
- <Box>
212
- <small>asset: {balance.symbol}</small>
213
- <br />
214
- <small>balance: {balance.balance}</small>
215
- </Box>
216
- </HStack>
217
- <HStack mt={2} spacing={2}>
218
- <Button
219
- size="sm"
220
- variant="outline"
221
- onClick={() => handleSendClick(balance)}
222
- >
223
- Send
224
- </Button>
225
- <Button
226
- size="sm"
227
- variant="outline"
228
- onClick={() => handleReceiveClick(balance)}
229
- >
230
- Receive
231
- </Button>
232
- <Button
233
- size="sm"
234
- variant="outline"
235
- onClick={() => handleViewClick(balance)}
236
- >
237
- View
238
- </Button>
239
- </HStack>
240
- </Box>
241
- ))}
242
- <Box mt={4}>
243
- {generatePaginationArray().map((page, index) => (
244
- <Button
245
- key={index}
246
- size="sm"
247
- variant={currentPage === page ? "solid" : "outline"}
248
- onClick={() => handlePageChange(page)}
249
- >
250
- {page === "..." ? "..." : page}
251
- </Button>
252
- ))}
253
- </Box>
254
-
255
- <Modal isOpen={isOpen} onClose={onClose} isCentered blockScrollOnMount>
256
- <ModalOverlay />
257
- <ModalContent>
258
- <ModalHeader>{selectedAction}</ModalHeader>
259
- <ModalCloseButton />
260
- {selectedAction === "send" && (
261
- <div>
262
- <h3>Selected Action: Send</h3>
263
- <p>Selected Asset: {selectedBalance?.symbol}</p>
264
- <Send asset={selectedBalance} />
265
- </div>
266
- )}
267
- {selectedAction === "receive" && (
268
- <div>
269
- <h3>Selected Action: Receive</h3>
270
- <p>Selected Asset: {selectedBalance?.symbol}</p>
271
- <Receive />
272
- </div>
273
- )}
274
- {selectedAction === "view" && (
275
- <div>
276
- <h3>Selected Action: View</h3>
277
- <p>Selected Asset: {selectedBalance?.symbol}</p>
278
- <View />
279
- </div>
280
- )}
281
- <ModalFooter>
282
- <Button colorScheme="blue" onClick={onClose}>
283
- Cancel
284
- </Button>
285
- </ModalFooter>
286
- </ModalContent>
287
- </Modal>
288
- </Stack>
289
- );
290
- }
@@ -1,27 +0,0 @@
1
- import type React from "react";
2
-
3
- interface MiddleEllipsisProps {
4
- text: string;
5
- }
6
-
7
- const MiddleEllipsis: React.FC<MiddleEllipsisProps> = ({ text }) => {
8
- const maxLength = 20;
9
- const ellipsis = "...";
10
-
11
- if (!text || text.length <= maxLength) {
12
- return <span>{text}</span>;
13
- }
14
-
15
- const frontPart = text.slice(0, 7);
16
- const backPart = text.slice(-10);
17
-
18
- return (
19
- <span>
20
- {frontPart}
21
- {ellipsis}
22
- {backPart}
23
- </span>
24
- );
25
- };
26
-
27
- export default MiddleEllipsis;
@@ -1,67 +0,0 @@
1
- import {
2
- chakra,
3
- Stack,
4
- CircularProgress,
5
- Drawer,
6
- DrawerOverlay,
7
- DrawerContent,
8
- DrawerHeader,
9
- DrawerBody,
10
- Tabs,
11
- TabList,
12
- TabPanels,
13
- Tab,
14
- TabPanel,
15
- Avatar,
16
- AvatarBadge,
17
- Box,
18
- Button,
19
- Flex,
20
- HStack,
21
- IconButton,
22
- Link,
23
- Menu,
24
- Image,
25
- MenuButton,
26
- MenuDivider,
27
- Icon,
28
- MenuItem,
29
- MenuList,
30
- Spacer,
31
- Text,
32
- useDisclosure,
33
- Accordion,
34
- AccordionItem,
35
- AccordionButton,
36
- AccordionIcon,
37
- AccordionPanel,
38
- SimpleGrid,
39
- Card,
40
- CardHeader,
41
- Heading,
42
- CardBody,
43
- CardFooter,
44
- Modal,
45
- ModalOverlay,
46
- ModalContent,
47
- ModalHeader,
48
- ModalCloseButton,
49
- ModalBody,
50
- ModalFooter,
51
- } from "@chakra-ui/react";
52
- import React, { useState } from "react";
53
-
54
- import MiddleEllipsis from "./MiddleEllipsis";
55
-
56
- interface Balance {
57
- rating: number;
58
- setRating: (rating: number) => void;
59
- count?: number;
60
- size?: number;
61
- }
62
-
63
- export default function Pubkey(Balance: any) {
64
- const [hover, setHover] = useState<number | null>(null);
65
-
66
- return <div>{JSON.stringify(Balance)}</div>;
67
- }
@@ -1,26 +0,0 @@
1
- import { FormControl, FormLabel, Input, Text } from "@chakra-ui/react";
2
- import React, { useState } from "react";
3
- import QRCode from "react-qr-code";
4
-
5
- const Receive = () => {
6
- const [address, setAddress] = useState("");
7
-
8
- return (
9
- <>
10
- <FormControl>
11
- <FormLabel>Address:</FormLabel>
12
- <Input value={address} onChange={(e) => setAddress(e.target.value)} />
13
- </FormControl>
14
-
15
- {address && (
16
- <>
17
- <Text mt={4}>QR Code:</Text>
18
- <QRCode value={address} size={128} />
19
- <Text mt={2}>{address}</Text>
20
- </>
21
- )}
22
- </>
23
- );
24
- };
25
-
26
- export default Receive;
@@ -1,135 +0,0 @@
1
- import {
2
- Card,
3
- Button,
4
- FormControl,
5
- FormLabel,
6
- Input,
7
- Spinner,
8
- Avatar,
9
- } from "@chakra-ui/react";
10
- import React, { useState, useEffect } from "react";
11
-
12
- import { usePioneer } from "lib/context/Pioneer";
13
-
14
- const Send = (Asset: any) => {
15
- const { state, dispatch } = usePioneer();
16
- const { user, app, api, wallet } = state;
17
- const [amount, setAmount] = useState("");
18
- const [address, setAddress] = useState("");
19
- const [balance, setBalance] = useState("");
20
- const [blockchain, setBlockchain] = useState("");
21
- const [caip, setCaip] = useState(null);
22
- const [txid, setTxid] = useState(null);
23
- const [isLoading, setIsLoading] = useState(false);
24
-
25
- const handleSend = async () => {
26
- try {
27
- setIsLoading(true);
28
- //console.log("Asset: ", Asset.asset);
29
- //console.log("Address: ", address);
30
- //console.log("amount: ", amount);
31
- const ASSET = Asset.asset.symbol;
32
- if (!address) alert("Must set an address!");
33
- if (!amount) alert("Must set an amount!");
34
- const send: any = {
35
- blockchain,
36
- network: Asset.asset.network,
37
- asset: Asset.asset.symbol,
38
- balance: Asset.asset.balance,
39
- address,
40
- amount,
41
- noBroadcast: false,
42
- };
43
- if (Asset.asset.contract) send.contract = Asset.asset.contract;
44
- const tx = {
45
- type: "sendToAddress",
46
- payload: send,
47
- };
48
- // console.log("tx: ", tx);
49
- let invocation = await app.build(tx);
50
- // console.log("invocation: ", invocation);
51
- // sign
52
- invocation = await app.sign(invocation, wallet);
53
- // console.log("invocation: ", invocation);
54
- invocation.network = ASSET; // TODO dont do this bullshit, use caip
55
- invocation.noBroadcast = false;
56
- invocation.sync = true;
57
- invocation = await app.broadcast(invocation);
58
- // console.log("invocation: ", invocation);
59
- if (invocation && invocation.broadcast && invocation.broadcast.txid) {
60
- setIsLoading(false);
61
- setTxid(invocation.broadcast.txid);
62
- // TODO open block explorer link
63
- // window.open('https://example.com', '_blank'); // Open link in a new tab
64
- }
65
- } catch (error) {
66
- console.error(error);
67
- }
68
- };
69
-
70
- // onStart get balance of asset
71
- // get max amount able to send
72
- const onStart = async () => {
73
- try {
74
- // console.log("Asset: ", Asset.asset.caip);
75
- // console.log("Asset: ", Asset.asset);
76
- setCaip(Asset.asset.caip);
77
- setBalance(Asset.asset.balance);
78
-
79
- // get asset by caip
80
- const asset = await api.AssetByCaip({ caip: Asset.asset.caip });
81
- // console.log("asset: ",asset.data)
82
- // console.log("asset: ",asset.data[0].blockchain)
83
- setBlockchain(asset.data[0].blockchain);
84
- // @ts-ignore
85
- if (!asset.data[0].blockchain)
86
- alert(`unknown asset! ciap: ${Asset.asset.caip}`);
87
- } catch (error) {
88
- console.error(error);
89
- }
90
- };
91
-
92
- useEffect(() => {
93
- onStart(); // Call the onStart function when the component mounts
94
- }, []);
95
-
96
- return (
97
- <Card>
98
- <h2>Balance: {balance}</h2>
99
- <Avatar src={Asset.asset.image} />
100
- <small>caip: {caip}</small>
101
- <br />
102
- {txid ? (
103
- <div>
104
- txid: <small> {txid} </small>
105
- <Button>view on block explorer</Button>
106
- </div>
107
- ) : (
108
- <div>
109
- <FormControl>
110
- <FormLabel>Amount:</FormLabel>
111
- <Input
112
- type="number"
113
- value={amount}
114
- onChange={(e) => setAmount(e.target.value)}
115
- />
116
- </FormControl>
117
-
118
- <FormControl mt={4}>
119
- <FormLabel>Address:</FormLabel>
120
- <Input
121
- value={address}
122
- onChange={(e) => setAddress(e.target.value)}
123
- />
124
- </FormControl>
125
-
126
- <Button mt={4} colorScheme="blue" onClick={handleSend}>
127
- {isLoading ? <Spinner /> : "Send"}
128
- </Button>
129
- </div>
130
- )}
131
- </Card>
132
- );
133
- };
134
-
135
- export default Send;
@@ -1,44 +0,0 @@
1
- import { List, ListItem, Text } from "@chakra-ui/react";
2
- import React from "react";
3
-
4
- const View = () => {
5
- // Mocked transaction history data
6
- const transactions = [
7
- {
8
- id: 1,
9
- date: "2023-07-01",
10
- amount: "0.5 BTC",
11
- sender: "Sender A",
12
- receiver: "Receiver B",
13
- },
14
- {
15
- id: 2,
16
- date: "2023-07-02",
17
- amount: "1 ETH",
18
- sender: "Sender C",
19
- receiver: "Receiver D",
20
- },
21
- {
22
- id: 3,
23
- date: "2023-07-03",
24
- amount: "0.2 LTC",
25
- sender: "Sender E",
26
- receiver: "Receiver F",
27
- },
28
- ];
29
-
30
- return (
31
- <List spacing={4}>
32
- {transactions.map((transaction) => (
33
- <ListItem key={transaction.id}>
34
- <Text>Date: {transaction.date}</Text>
35
- <Text>Amount: {transaction.amount}</Text>
36
- <Text>Sender: {transaction.sender}</Text>
37
- <Text>Receiver: {transaction.receiver}</Text>
38
- </ListItem>
39
- ))}
40
- </List>
41
- );
42
- };
43
-
44
- export default View;
@@ -1,166 +0,0 @@
1
- import {
2
- Avatar,
3
- AvatarBadge,
4
- Box,
5
- Button,
6
- HStack,
7
- Stack,
8
- Image,
9
- Modal,
10
- ModalOverlay,
11
- ModalContent,
12
- ModalHeader,
13
- ModalCloseButton,
14
- ModalBody,
15
- ModalFooter,
16
- useDisclosure,
17
- InputGroup,
18
- InputLeftElement,
19
- Input,
20
- Text,
21
- } from "@chakra-ui/react";
22
- import React, { useState, useEffect } from "react";
23
-
24
- // Import icons
25
- // @ts-ignore
26
- import KEEPKEY_ICON from "lib/assets/png/keepkey.png";
27
- // @ts-ignore
28
- import METAMASK_ICON from "lib/assets/png/metamask.png";
29
- // @ts-ignore
30
- import PIONEER_ICON from "lib/assets/png/pioneer.png";
31
- import { usePioneer } from "lib/context/Pioneer";
32
-
33
- import MiddleEllipsis from "./MiddleEllipsis";
34
-
35
- interface Wallet {
36
- context: string;
37
- type: string;
38
- valueUsdContext: number;
39
- icon: any; // @ts-ignore
40
- paired: boolean;
41
- }
42
-
43
- const getWalletBadgeContent = (walletType: string) => {
44
- const icons: any = {
45
- metamask: METAMASK_ICON,
46
- keepkey: KEEPKEY_ICON,
47
- native: PIONEER_ICON,
48
- };
49
-
50
- const icon = icons[walletType];
51
-
52
- if (!icon) {
53
- return null;
54
- }
55
-
56
- return (
57
- <AvatarBadge boxSize="1.25em" bg="green.500">
58
- <Image rounded="full" src={icon} />
59
- </AvatarBadge>
60
- );
61
- };
62
-
63
- export default function Wallets({ wallets }: { wallets: Wallet[] }) {
64
- const { state, dispatch } = usePioneer();
65
- const { user } = state;
66
- const [currentPage, setCurrentPage] = useState(1);
67
- const [walletsWithIcons, setWalletsWithIcons] = useState([]);
68
- const { isOpen, onOpen, onClose } = useDisclosure();
69
- const walletsPerPage = 3;
70
-
71
- const handlePageChange = (pageNumber: any) => {
72
- setCurrentPage(pageNumber);
73
- };
74
-
75
- for (let i = 0; i < wallets.length; i++) {
76
- const wallet = wallets[i];
77
- if (wallet.type === "native") {
78
- wallets[i].icon = PIONEER_ICON;
79
- } else if (wallet.type === "metamask") {
80
- wallets[i].icon = METAMASK_ICON;
81
- } else if (wallet.type === "keepkey") {
82
- wallets[i].icon = KEEPKEY_ICON;
83
- }
84
- }
85
-
86
- const currentWallets = wallets.slice(
87
- (currentPage - 1) * walletsPerPage,
88
- currentPage * walletsPerPage
89
- );
90
- const totalPages = Math.ceil(wallets.length / walletsPerPage);
91
-
92
- // Function to generate custom pagination array
93
- const generatePaginationArray = () => {
94
- const paginationArray = [];
95
- const totalPageButtons = 5; // Number of page buttons to display around the current page
96
-
97
- if (totalPages <= totalPageButtons) {
98
- // If total pages are less than or equal to totalPageButtons, show all page numbers
99
- for (let i = 1; i <= totalPages; i++) {
100
- paginationArray.push(i);
101
- }
102
- } else {
103
- // If total pages are more than totalPageButtons, generate custom pagination
104
- const middleButton = Math.floor(totalPageButtons / 2);
105
- const startPage = Math.max(currentPage - middleButton, 1);
106
- const endPage = Math.min(currentPage + middleButton, totalPages);
107
-
108
- if (startPage > 1) {
109
- // Add the first page and ellipsis if the current page is far enough from the first page
110
- paginationArray.push(1, "...");
111
- }
112
-
113
- // Add page numbers between startPage and endPage (inclusive)
114
- for (let i = startPage; i <= endPage; i++) {
115
- paginationArray.push(i);
116
- }
117
-
118
- if (endPage < totalPages) {
119
- // Add the last page and ellipsis if the current page is far enough from the last page
120
- paginationArray.push("...", totalPages);
121
- }
122
- }
123
-
124
- return paginationArray;
125
- };
126
-
127
- return (
128
- <Stack spacing={4}>
129
- {/* <Text fontSize='xl'>Wallets Tracked</Text> */}
130
- {currentWallets.map((wallet: Wallet, index: number) => (
131
- <Box key={index}>
132
- <HStack spacing={4} alignItems="center">
133
- <Avatar src={wallet.icon} />
134
- <Box>
135
- <small>
136
- Context: <MiddleEllipsis text={wallet?.context} />
137
- </small>
138
- <br />
139
- <small>Type: {wallet.type}</small>
140
- <br />
141
- <small>Value (USD): {wallet.valueUsdContext}</small>
142
- <br />
143
- <small>Paired: {wallet.paired ? "Yes" : "No"}</small>
144
- <br />
145
- </Box>
146
- </HStack>
147
- <HStack mt={2} spacing={2}>
148
- {/* ... (rest of the buttons and click handlers) */}
149
- </HStack>
150
- </Box>
151
- ))}
152
- <Box mt={4}>
153
- {generatePaginationArray().map((page, index) => (
154
- <Button
155
- key={index}
156
- size="sm"
157
- variant={currentPage === page ? "solid" : "outline"}
158
- onClick={() => handlePageChange(page)}
159
- >
160
- {page === "..." ? "..." : page}
161
- </Button>
162
- ))}
163
- </Box>
164
- </Stack>
165
- );
166
- }