@pioneer-platform/pioneer-react 0.2.36 → 0.2.38

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.
@@ -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
- }