@pioneer-platform/pioneer-react 0.2.34 → 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.
@@ -0,0 +1,205 @@
1
+ import { u as usePioneer, j as jsxRuntimeExports, S as Search2Icon, M as MiddleEllipsis, W as WalletSelect, A as AssetSelect } from "./index_bc632802.js";
2
+ import { Stack, InputGroup, InputLeftElement, Input, Box, Text, Checkbox, HStack, Avatar, Button, useDisclosure, Modal, ModalOverlay, ModalContent, ModalHeader, ModalCloseButton, ModalBody, ModalFooter } from "@chakra-ui/react";
3
+ import { useState, useEffect } from "react";
4
+ import "react-dom";
5
+ import "@emotion/react";
6
+ function BlockchainSelect({ onClose }) {
7
+ const { state, dispatch } = usePioneer();
8
+ const { api, app, user } = state;
9
+ const [searchQuery, setSearchQuery] = useState("");
10
+ const [currentPage, setCurrentPage] = useState([]);
11
+ const [currentPageIndex, setCurrentPageIndex] = useState(0);
12
+ const [showOwnedAssets, setShowOwnedAssets] = useState(false);
13
+ const [timeOut, setTimeOut] = useState(null);
14
+ const itemsPerPage = 6;
15
+ const handleSelectClick = async (asset) => {
16
+ try {
17
+ const changeAssetContext = await app.setAssetContext(asset);
18
+ onClose();
19
+ } catch (e) {
20
+ console.error(e);
21
+ }
22
+ };
23
+ const onSearch = async function(searchQuery2) {
24
+ try {
25
+ if (!api) {
26
+ alert("Failed to init API!");
27
+ return;
28
+ }
29
+ const search = {
30
+ limit: itemsPerPage,
31
+ skip: currentPageIndex * itemsPerPage,
32
+ // Use currentPageIndex for pagination
33
+ collection: "blockchains",
34
+ searchQuery: searchQuery2,
35
+ searchFields: ["name", "symbol"]
36
+ };
37
+ const info = await api.SearchAtlas(search);
38
+ const currentPageData = info.data.results;
39
+ setCurrentPage(currentPageData);
40
+ setTotalBlockchains(info.data.total);
41
+ } catch (e) {
42
+ console.error(e);
43
+ }
44
+ };
45
+ const fetchPage = async (pageIndex) => {
46
+ try {
47
+ if (!api) {
48
+ alert("Failed to init API!");
49
+ return;
50
+ }
51
+ const search = {
52
+ limit: itemsPerPage,
53
+ skip: pageIndex * itemsPerPage,
54
+ collection: "blockchains",
55
+ ownedBy: showOwnedAssets ? user.id : void 0
56
+ };
57
+ const info = await api.SearchAtlas(search);
58
+ const currentPageData = info.data.results;
59
+ setCurrentPage(currentPageData);
60
+ setTotalBlockchains(info.data.total);
61
+ } catch (e) {
62
+ console.error(e);
63
+ }
64
+ };
65
+ useEffect(() => {
66
+ fetchPage(currentPageIndex);
67
+ }, [currentPageIndex, showOwnedAssets]);
68
+ const [totalBlockchains, setTotalBlockchains] = useState(0);
69
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs(Stack, { spacing: 4, children: [
70
+ /* @__PURE__ */ jsxRuntimeExports.jsxs(InputGroup, { children: [
71
+ /* @__PURE__ */ jsxRuntimeExports.jsx(InputLeftElement, { pointerEvents: "none", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Search2Icon, { color: "gray.300" }) }),
72
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
73
+ Input,
74
+ {
75
+ placeholder: "Bitcoin...",
76
+ type: "text",
77
+ value: searchQuery,
78
+ onChange: (e) => {
79
+ setSearchQuery(e.target.value);
80
+ if (timeOut) {
81
+ clearTimeout(timeOut);
82
+ }
83
+ setTimeOut(
84
+ // @ts-ignore
85
+ setTimeout(() => {
86
+ setCurrentPageIndex(0);
87
+ onSearch(e.target.value);
88
+ }, 1e3)
89
+ );
90
+ }
91
+ }
92
+ )
93
+ ] }),
94
+ /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { children: [
95
+ /* @__PURE__ */ jsxRuntimeExports.jsxs(Text, { fontSize: "2xl", children: [
96
+ "Total Chains: ",
97
+ totalBlockchains
98
+ ] }),
99
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
100
+ Checkbox,
101
+ {
102
+ isChecked: showOwnedAssets,
103
+ onChange: () => setShowOwnedAssets(!showOwnedAssets),
104
+ children: "Show only blockchains you have assets on"
105
+ }
106
+ ),
107
+ currentPage.map((blockchain, index) => /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { children: [
108
+ /* @__PURE__ */ jsxRuntimeExports.jsxs(HStack, { spacing: 4, alignItems: "center", children: [
109
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Avatar, { src: blockchain == null ? void 0 : blockchain.image }),
110
+ /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { children: [
111
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("small", { children: [
112
+ "blockchain: ",
113
+ /* @__PURE__ */ jsxRuntimeExports.jsx(MiddleEllipsis, { text: blockchain == null ? void 0 : blockchain.caip })
114
+ ] }),
115
+ /* @__PURE__ */ jsxRuntimeExports.jsx("br", {}),
116
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("small", { children: [
117
+ "name: ",
118
+ blockchain.name
119
+ ] })
120
+ ] })
121
+ ] }),
122
+ /* @__PURE__ */ jsxRuntimeExports.jsx(HStack, { mt: 2, spacing: 2, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
123
+ Button,
124
+ {
125
+ size: "sm",
126
+ variant: "outline",
127
+ onClick: () => handleSelectClick(blockchain),
128
+ children: "Select"
129
+ }
130
+ ) })
131
+ ] }, index))
132
+ ] }),
133
+ /* @__PURE__ */ jsxRuntimeExports.jsxs(HStack, { mt: 4, children: [
134
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
135
+ Button,
136
+ {
137
+ isDisabled: currentPageIndex === 0,
138
+ onClick: () => setCurrentPageIndex(currentPageIndex - 1),
139
+ children: "Previous Page"
140
+ }
141
+ ),
142
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
143
+ Button,
144
+ {
145
+ isDisabled: currentPage.length < itemsPerPage,
146
+ onClick: () => setCurrentPageIndex(currentPageIndex + 1),
147
+ children: "Next Page"
148
+ }
149
+ )
150
+ ] })
151
+ ] });
152
+ }
153
+ const Home = () => {
154
+ const { state } = usePioneer();
155
+ const { api, app, context, assetContext, blockchainContext, pubkeyContext } = state;
156
+ const [address, setAddress] = useState("");
157
+ const [modalType, setModalType] = useState("");
158
+ const { isOpen, onOpen, onClose } = useDisclosure();
159
+ useEffect(() => {
160
+ console.log("2 pubkeyContext: ", pubkeyContext);
161
+ setAddress(pubkeyContext.master || pubkeyContext.pubkey || pubkeyContext);
162
+ }, [pubkeyContext]);
163
+ const openModal = (type) => {
164
+ setModalType(type);
165
+ onOpen();
166
+ };
167
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
168
+ /* @__PURE__ */ jsxRuntimeExports.jsxs(Modal, { isOpen, onClose: () => onClose(), size: "xl", children: [
169
+ /* @__PURE__ */ jsxRuntimeExports.jsx(ModalOverlay, {}),
170
+ /* @__PURE__ */ jsxRuntimeExports.jsxs(ModalContent, { children: [
171
+ /* @__PURE__ */ jsxRuntimeExports.jsx(ModalHeader, { children: modalType }),
172
+ /* @__PURE__ */ jsxRuntimeExports.jsx(ModalCloseButton, {}),
173
+ /* @__PURE__ */ jsxRuntimeExports.jsxs(ModalBody, { children: [
174
+ modalType === "Select wallet" && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: /* @__PURE__ */ jsxRuntimeExports.jsx(WalletSelect, { onClose }) }),
175
+ modalType === "Select Asset" && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: /* @__PURE__ */ jsxRuntimeExports.jsx(AssetSelect, { onClose }) }),
176
+ modalType === "Select Blockchain" && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: /* @__PURE__ */ jsxRuntimeExports.jsx(BlockchainSelect, { onClose }) }),
177
+ modalType === "View Address" && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
178
+ "address: ",
179
+ address
180
+ ] })
181
+ ] }),
182
+ /* @__PURE__ */ jsxRuntimeExports.jsx(ModalFooter, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { colorScheme: "blue", onClick: onClose, children: "Close" }) })
183
+ ] })
184
+ ] }),
185
+ "Context: ",
186
+ context,
187
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { onClick: () => openModal("Select wallet"), children: "Select wallet" }),
188
+ /* @__PURE__ */ jsxRuntimeExports.jsx("br", {}),
189
+ "Asset Context: ",
190
+ assetContext == null ? void 0 : assetContext.name,
191
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { onClick: () => openModal("Select Asset"), children: "Select Asset" }),
192
+ /* @__PURE__ */ jsxRuntimeExports.jsx("br", {}),
193
+ "Blockchain Context: ",
194
+ blockchainContext == null ? void 0 : blockchainContext.name,
195
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { onClick: () => openModal("Select Blockchain"), children: "Select Blockchain" }),
196
+ /* @__PURE__ */ jsxRuntimeExports.jsx("br", {}),
197
+ "Address: ",
198
+ address,
199
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { onClick: () => openModal("View Address"), children: "View Address" }),
200
+ /* @__PURE__ */ jsxRuntimeExports.jsx("br", {})
201
+ ] });
202
+ };
203
+ export {
204
+ Home as default
205
+ };