Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[in progress] Recent transactions in account modal #57

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions src/components/account/AccountModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Identicon from "./Identicon";
import { useYobot } from "src/contexts/YobotContext";
import { NoShadowButton, NoShadowLink } from "src/components";
import { getNetworkPrefix } from "src/utils";
import TransactionsModalFooter from "./TransactionsModalFooter";

type AccountModalProps = {
isOpen: any;
Expand Down Expand Up @@ -176,23 +177,7 @@ const AccountModal = ({ isOpen, onClose }: AccountModalProps) => {
</Box>
</ModalBody>

<ModalFooter
justifyContent="begin"
background="gray.700"
borderBottomLeftRadius="3xl"
borderBottomRightRadius="3xl"
p={6}
>
<Text
color="white"
textAlign="left"
fontWeight="medium"
fontSize="md"
width="100%"
>
Your transactions will appear here...
</Text>
</ModalFooter>
<TransactionsModalFooter />
</ModalContent>
</Modal>
);
Expand Down
127 changes: 127 additions & 0 deletions src/components/account/TransactionsModalFooter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// TransactionsModalFooter.tsx
import React, { useEffect, useMemo } from "react";
import {
Box,
Button,
Flex,
Link as ChakraLink,
Modal,
ModalOverlay,
ModalContent,
ModalHeader,
ModalFooter,
ModalBody,
ModalCloseButton,
Stack,
Text,
} from "@chakra-ui/react";
import { getNetworkPrefix } from "src/utils";
import { ExternalLinkIcon, CopyIcon } from "@chakra-ui/icons";
import styled from "@emotion/styled";
import { useYobot } from "src/contexts";

const TransactionListWrapper = styled.div`
`;

const pendingTransactions : (mapping string[]) = [];
// "{action} bid for {_quantity} of {_token_address} NFTs at {priceInEth} ETH each."

const addPendingTx = (tx) => {
pendingTransactions.push(tx);
};

const addSuccessfulTx = (tx) => {
pendingTransactions.remove(tx);

};

const TransactionsModalFooter = () => {
const { chainId, actions } = useYobot();

const fetchTransactions = async () => {
for (const action of actions) {
let values = action["returnValues"];
if (values !== undefined) {
let _address = values["0"];
let _token_address = values["1"];
let _action = values["4"];
console.log(values);
}
}
}

useEffect(() => {fetchTransactions()});

// const sortedRecentTransactions = useMemo(() => {
// const txs = Object.values(allTransactions)
// return txs.filter(isTransactionRecent).sort(newTransactionsFirst)
// }, [allTransactions])

function renderTransactions(transactions: string[]) {
return (
<TransactionListWrapper>
{transactions.map((_token_address, i) => {
return (
<Stack direction="row">
<ChakraLink
display="flex"
mr="0.2em"
color="blue.400"
isExternal
href={`https://${
chainId > 0 ? getNetworkPrefix(chainId) : ""
}etherscan.io/address/${_token_address}`}
>
{_token_address}
<span style={{ margin: "auto", paddingLeft: "0.2em" }}>
<ExternalLinkIcon />
</span>
</ChakraLink>
</Stack>
)
})}
</TransactionListWrapper>
)
}

const pendingTransactions = [];
const confirmedTransactions = [];
// const pendingTransactions = sortedRecentTransactions.filter((tx) => !tx.receipt).map((tx) => tx.hash)
// const confirmedTransactions = sortedRecentTransactions.filter((tx) => tx.receipt).map((tx) => tx.hash)

return (
<ModalFooter
justifyContent="begin"
background="gray.700"
borderBottomLeftRadius="3xl"
borderBottomRightRadius="3xl"
p={6}
>
{!!pendingTransactions.length || !!confirmedTransactions.length ? (
<Text
color="white"
textAlign="left"
fontWeight="medium"
fontSize="md"
width="100%"
>
Recent Transactions
</Text>
// {renderTransactions(pendingTransactions)}
// {renderTransactions(confirmedTransactions)}
) : (
<Text
color="white"
textAlign="left"
fontWeight="medium"
fontSize="md"
width="100%"
>
Your transactions will appear here...
</Text>
)}
</ModalFooter>
);
};

export default TransactionsModalFooter;