diff --git a/v2/features/stats/JarStats.tsx b/v2/features/stats/JarStats.tsx index 42a31110..6c2d3cc0 100644 --- a/v2/features/stats/JarStats.tsx +++ b/v2/features/stats/JarStats.tsx @@ -11,7 +11,6 @@ import FarmsTable from "v2/features/farms/FarmsTable"; import { JarSelectData } from "./JarSelect"; import { readyState } from "pages/stats"; import { useAccount } from "v2/hooks"; -import TxHistoryTable from "./jar/userHistory/TxHistoryContainer"; import { JarDefinition } from "picklefinance-core/lib/model/PickleModelJson"; import { useTranslation } from "next-i18next"; import TxHistoryContainer from "./jar/userHistory/TxHistoryContainer"; @@ -38,7 +37,7 @@ const JarStats: FC<{ const addrs = Object.fromEntries( Object.entries({ - User: "0xfeedc450742ac0d9bb38341d9939449e3270f76f", //account, + User: account, //"0xfeedc450742ac0d9bb38341d9939449e3270f76f", Jar: assetJar ? assetJar.contract.toLowerCase() : "jar not found", Farm: assetJar && assetJar.farm ? assetJar.farm.farmAddress.toLowerCase() : "farm not found", Null: "0x0000000000000000000000000000000000000000", @@ -57,7 +56,7 @@ const JarStats: FC<{ useEffect(() => { const getUserJarHistory = async (account: string | null | undefined): Promise => { - account = "0xfeedc450742ac0d9bb38341d9939449e3270f76f"; + // account = "0xfeedc450742ac0d9bb38341d9939449e3270f76f"; account && (await fetch(`https://api.pickle.finance/prod/protocol/userhistory/${account}`) .then((resp) => resp.json()) @@ -79,8 +78,8 @@ const JarStats: FC<{ {jarData && jarData.documentation && }
- {userJarHistory && userJarHistory.length > 0 && ( - + {userJarHistory && userJarHistory.length > 0 && core && ( + )}
{jarData && jarData.documentation && ( diff --git a/v2/features/stats/jar/userHistory/TxHistoryContainer.tsx b/v2/features/stats/jar/userHistory/TxHistoryContainer.tsx index c8baf5c5..65cbfc5f 100644 --- a/v2/features/stats/jar/userHistory/TxHistoryContainer.tsx +++ b/v2/features/stats/jar/userHistory/TxHistoryContainer.tsx @@ -1,4 +1,5 @@ import { TFunction } from "next-i18next"; +import { PickleModelJson } from "picklefinance-core"; import { FC } from "react"; import { UserTx } from "v2/types"; import { classNames } from "v2/utils"; @@ -6,15 +7,16 @@ import TxHistoryTable from "./TxHistoryTable"; const TxHistoryContainer: FC<{ txHistory: UserTx[]; + core: PickleModelJson.PickleModelJson; addrs: { [key: string]: string }; t: TFunction; className?: string; -}> = ({ txHistory, addrs, t, className }) => ( +}> = ({ txHistory, core, addrs, t, className }) => (

{"User History"}

- + {core && }
); diff --git a/v2/features/stats/jar/userHistory/TxHistoryTable.tsx b/v2/features/stats/jar/userHistory/TxHistoryTable.tsx index bf877e66..f217e3ce 100644 --- a/v2/features/stats/jar/userHistory/TxHistoryTable.tsx +++ b/v2/features/stats/jar/userHistory/TxHistoryTable.tsx @@ -1,3 +1,4 @@ +import { PickleModelJson } from "picklefinance-core"; import { FC } from "react"; import { UserTx } from "v2/types"; import { classNames } from "v2/utils"; @@ -5,9 +6,10 @@ import TxTableBody from "./TxTableBody"; const TxHistoryTable: FC<{ txHistory: UserTx[]; + core: PickleModelJson.PickleModelJson; addrs: { [key: string]: string }; className?: string; -}> = ({ txHistory, addrs, className }) => { +}> = ({ txHistory, core, addrs, className }) => { return (
@@ -23,7 +25,7 @@ const TxHistoryTable: FC<{ - + {/*
diff --git a/v2/features/stats/jar/userHistory/TxTableBody.tsx b/v2/features/stats/jar/userHistory/TxTableBody.tsx index ae72ce28..efefadac 100644 --- a/v2/features/stats/jar/userHistory/TxTableBody.tsx +++ b/v2/features/stats/jar/userHistory/TxTableBody.tsx @@ -1,4 +1,6 @@ import { Disclosure, Transition } from "@headlessui/react"; +import { PickleModelJson } from "picklefinance-core"; +import { RawChain } from "picklefinance-core/lib/chain/Chains"; import { FC, Fragment } from "react"; import { UserTx } from "v2/types"; import { classNames } from "v2/utils"; @@ -6,41 +8,59 @@ import TxTableRowBody from "./TxTableRowBody"; import TxTableRowHeader from "./TxTableRowHeader"; import TxTableSpacerRow from "./TxTableSpacerRow"; -const TxTableBody: FC<{ txs: UserTx[]; addrs: { [key: string]: string } }> = ({ txs, addrs }) => ( - <>{txs && txs.map((tx) => )} +const TxTableBody: FC<{ + txs: UserTx[]; + core: PickleModelJson.PickleModelJson; + addrs: { [key: string]: string }; +}> = ({ txs, core, addrs }) => ( + <>{txs && txs.map((tx) => )} ); -const TxTableRow: FC<{ tx: UserTx; addrs: { [key: string]: string } }> = ({ tx, addrs }) => ( - <> - - {({ open }) => ( - <> - - - +const TxTableRow: FC<{ + tx: UserTx; + core: PickleModelJson.PickleModelJson; + addrs: { [key: string]: string }; +}> = ({ tx, core, addrs }) => { + const chain: RawChain | undefined = core.chains.filter((c) => c.chainId === tx.chain_id)[0]; + return ( + <> + + {({ open }) => ( + <> + + {core && } + - - - - - - - )} - - - -); + + + {core && chain && ( + + )} + + + + )} + + + + ); +}; export default TxTableBody; diff --git a/v2/features/stats/jar/userHistory/TxTableRowBody.tsx b/v2/features/stats/jar/userHistory/TxTableRowBody.tsx index 006aee8e..9be0c552 100644 --- a/v2/features/stats/jar/userHistory/TxTableRowBody.tsx +++ b/v2/features/stats/jar/userHistory/TxTableRowBody.tsx @@ -1,35 +1,134 @@ +import { PickleModelJson } from "picklefinance-core"; +import { RawChain } from "picklefinance-core/lib/chain/Chains"; import { FC } from "react"; import { UserTransfer } from "v2/types"; -import { formatNumber } from "v2/utils"; +import { classNames, formatNumber } from "v2/utils"; +import Link from "v2/components/Link"; -const TxTableRowBody: FC<{ transfers: UserTransfer[]; addrs: { [key: string]: string } }> = ({ - transfers, - addrs, -}) => ( +const TxTableRowBody: FC<{ + transfers: UserTransfer[]; + core: PickleModelJson.PickleModelJson; + chain: RawChain; + addrs: { [key: string]: string }; +}> = ({ transfers, core, chain, addrs }) => (
{transfers.map((t) => ( -

- {transferToString(t, addrs)} -

+ ))}
); -const transferToString = (transfer: UserTransfer, addrs: { [key: string]: string }) => { +const TransferDescription: FC<{ + transfer: UserTransfer; + core: PickleModelJson.PickleModelJson; + chain: RawChain; + tmpAddrs: { [addr: string]: string }; +}> = ({ transfer, core, chain, tmpAddrs }) => { + const { fromAddr, toAddr, burned, minted, nTokens, value, tokenName } = transferData( + transfer, + core, + tmpAddrs, + ); + const useFromLink = fromAddr.includes("...") && chain !== undefined; + const useToLink = toAddr.includes("...") && chain !== undefined; + + return ( + <> + {burned && ( +

{`${nTokens}${ + " " + tokenName + } tokens ${value} were burned.`}

+ )} + {minted && ( + <> + {useToLink ? ( + +

+ {`${nTokens}${" " + tokenName} tokens ${value} were minted and sent to`} +

+ +
+ ) : ( +

+ {`${nTokens}${" " + tokenName} tokens ${value} were minted and sent to ${toAddr}`} +

+ )} + + )} + {!minted && !burned && ( + <> + {useFromLink && useToLink && ( +
+ +

+ {`sent ${nTokens}${" " + tokenName} tokens ${value} to `} +

+ +
+ )} + {useFromLink && !useToLink && ( +
+ +

+ {`sent ${nTokens}${" " + tokenName} tokens ${value} to ${toAddr}`} +

+
+ )} + {!useFromLink && useToLink && ( +
+

+ {`${fromAddr} sent ${nTokens}${" " + tokenName} tokens ${value} to`} +

+ +
+ )} + {!useFromLink && !useToLink && ( +

+ {`${fromAddr} sent ${nTokens}${" " + tokenName} tokens ${value} to ${toAddr}`} +

+ )} + + )} + + ); +}; + +const AddrLink: FC<{ chain: RawChain; addr: string; className?: string }> = ({ + chain, + addr, + className, +}) => ( + + {addr} + +); + +const transferData = ( + transfer: UserTransfer, + core: PickleModelJson.PickleModelJson, + addrs: { [addr: string]: string }, +) => { + const tmp = core && coreToAddrMap(core); + addrs = tmp && { ...tmp, ...addrs }; const fromAddr = - addrs[transfer.fromAddress] || + addrs[transfer.fromAddress.toLowerCase()] || transfer.fromAddress.slice(0, 5) + "..." + transfer.fromAddress.slice(-3); const toAddr = - addrs[transfer.toAddress] || + addrs[transfer.toAddress.toLowerCase()] || transfer.toAddress.slice(0, 5) + "..." + transfer.toAddress.slice(-3); - const burned = toAddr === "Null"; const minted = fromAddr === "Null"; const nTokens = @@ -37,11 +136,35 @@ const transferToString = (transfer: UserTransfer, addrs: { [key: string]: string ? formatNumber(+transfer.price / transfer.value, 8) : "an unknown number of"; const value = transfer.value ? "(" + formatNumber(transfer.value, 2) + " USD)" : ""; - return burned - ? `${fromAddr} burned ${nTokens} tokens ${value}` - : minted - ? `${nTokens} ${value} were minted and sent to ${toAddr}` - : `${fromAddr} sent ${nTokens} tokens ${value} to ${toAddr}`; + const tokenName = addrs[transfer.tokenAddress.toLowerCase()] || ""; + return { + addrs: addrs, + fromAddr: fromAddr, + toAddr: toAddr, + burned: burned, + minted: minted, + nTokens: nTokens, + value: value, + tokenName: tokenName, + }; +}; + +const coreToAddrMap = (core: PickleModelJson.PickleModelJson) => { + let addrs: { [addr: string]: string } = {}; + core.assets.jars.forEach((a) => { + const depositTokenAddr = a.depositToken.addr.toLowerCase(); + const depositTokenName = a.depositToken.name; + const pTokenAddr = a.contract.toLowerCase(); + const pTokenName = "p" + depositTokenName; + addrs[depositTokenAddr] = depositTokenName; + addrs[pTokenAddr] = pTokenName; + }); + core.tokens.forEach((t) => { + const tokenAddr = t.contractAddr.toLowerCase(); + const tokenName = t.name ? t.name : t.id; + addrs[tokenAddr] = tokenName; + }); + return addrs; }; export default TxTableRowBody; diff --git a/v2/features/stats/jar/userHistory/TxTableRowHeader.tsx b/v2/features/stats/jar/userHistory/TxTableRowHeader.tsx index 7dd8949f..55f2b3c0 100644 --- a/v2/features/stats/jar/userHistory/TxTableRowHeader.tsx +++ b/v2/features/stats/jar/userHistory/TxTableRowHeader.tsx @@ -1,9 +1,18 @@ import { ChevronDownIcon } from "@heroicons/react/solid"; +import { PickleModelJson } from "picklefinance-core"; import { FC, HTMLAttributes } from "react"; import { UserTx } from "v2/types"; import { classNames, formatDate } from "v2/utils"; +import Link from "v2/components/Link"; -const TxTableRowHeader: FC<{ tx: UserTx; open: boolean }> = ({ tx, open }) => { +const TxTableRowHeader: FC<{ + tx: UserTx; + core: PickleModelJson.PickleModelJson; + open: boolean; +}> = ({ tx, core, open }) => { + const chain = core.chains.find((c) => c.chainId == tx.chain_id); + const txLink = `${chain?.explorer}/tx/${tx.hash}`; + console.log(txLink); return ( <> @@ -26,13 +35,9 @@ const TxTableRowHeader: FC<{ tx: UserTx; open: boolean }> = ({ tx, open }) => {
-

+ {tx.hash.slice(0, 5) + "..." + tx.hash.slice(-3)} -

+