From 56655ba86c7c85245fc5148b24be8500c2848c3a Mon Sep 17 00:00:00 2001 From: Poafs1 Date: Tue, 18 Jun 2024 11:23:43 +0700 Subject: [PATCH 1/6] fix(utils): update get txs by account addr lcd to support new cosmos sdk --- src/lib/services/tx/lcd.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/lib/services/tx/lcd.ts b/src/lib/services/tx/lcd.ts index 67632fbb8..19ef065af 100644 --- a/src/lib/services/tx/lcd.ts +++ b/src/lib/services/tx/lcd.ts @@ -44,14 +44,22 @@ export const getTxsByAccountAddressLcd = async ( offset: number ) => axios - .get( - `${endpoint}/cosmos/tx/v1beta1/txs?events=message.sender=%27${encodeURI(address)}%27`, - { + .get(`${endpoint}/cosmos/tx/v1beta1/txs`, { + params: { + order_by: 2, + limit, + page: offset / limit + 1, + query: `message.sender='${encodeURI(address)}'`, + }, + }) + .catch(() => + axios.get(`${endpoint}/cosmos/tx/v1beta1/txs`, { params: { order_by: 2, limit, page: offset / limit + 1, + events: `message.sender='${encodeURI(address)}'`, }, - } + }) ) .then(({ data }) => parseWithError(zTxsByAddressResponseLcd, data)); From 3aee15b92d07119475b4e4311a60c1d036899fb2 Mon Sep 17 00:00:00 2001 From: Poafs1 Date: Tue, 18 Jun 2024 11:42:06 +0700 Subject: [PATCH 2/6] refactor(components): add error state to txs table --- CHANGELOG.md | 1 + .../components/tables/txs/Lite.tsx | 16 +++++-- src/lib/pages/past-txs/lite.tsx | 47 +++++++++++-------- 3 files changed, 41 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da10c5840..cbf3f23d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -97,6 +97,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Bug fixes +- [#974](https://github.com/alleslabs/celatone-frontend/pull/974) Fix tx by account addr lcd to support new cosmos sdk - [#962](https://github.com/alleslabs/celatone-frontend/pull/962) Fix tx msg expand - [#965](https://github.com/alleslabs/celatone-frontend/pull/965) Add search not found state in module detail - [#946](https://github.com/alleslabs/celatone-frontend/pull/946) Fix token card diff --git a/src/lib/pages/account-details/components/tables/txs/Lite.tsx b/src/lib/pages/account-details/components/tables/txs/Lite.tsx index dc32b2500..a619a6299 100644 --- a/src/lib/pages/account-details/components/tables/txs/Lite.tsx +++ b/src/lib/pages/account-details/components/tables/txs/Lite.tsx @@ -3,7 +3,7 @@ import { Box } from "@chakra-ui/react"; import { useMobile } from "lib/app-provider"; import { Pagination } from "lib/components/pagination"; import { usePaginator } from "lib/components/pagination/usePaginator"; -import { ErrorFetching } from "lib/components/state"; +import { EmptyState, ErrorFetching } from "lib/components/state"; import { MobileTitle, TableTitle, @@ -38,7 +38,7 @@ export const TxsTableLite = ({ }, }); - const { data, isLoading } = useTxsByAddressLcd( + const { data, isLoading, error } = useTxsByAddressLcd( address as BechAddr20, undefined, onViewMore ? 5 : pageSize, @@ -65,7 +65,17 @@ export const TxsTableLite = ({ } + emptyState={ + error ? ( + + ) : ( + + ) + } showRelations={false} /> )} diff --git a/src/lib/pages/past-txs/lite.tsx b/src/lib/pages/past-txs/lite.tsx index af235862b..6f2ed74bd 100644 --- a/src/lib/pages/past-txs/lite.tsx +++ b/src/lib/pages/past-txs/lite.tsx @@ -1,13 +1,13 @@ import { Flex, Heading } from "@chakra-ui/react"; import type { ChangeEvent } from "react"; -import { useEffect, useState } from "react"; +import { useCallback, useEffect, useState } from "react"; import { useCurrentChain, useWasmConfig } from "lib/app-provider"; import InputWithIcon from "lib/components/InputWithIcon"; import PageContainer from "lib/components/PageContainer"; import { Pagination } from "lib/components/pagination"; import { usePaginator } from "lib/components/pagination/usePaginator"; -import { EmptyState } from "lib/components/state"; +import { EmptyState, ErrorFetching } from "lib/components/state"; import { TransactionsTableWithWallet } from "lib/components/table"; import { UserDocsLink } from "lib/components/UserDocsLink"; import { useDebounce } from "lib/hooks"; @@ -39,7 +39,7 @@ export const PastTxsLite = () => { }, }); - const { data, isLoading } = useTxsByAddressLcd( + const { data, isLoading, error } = useTxsByAddressLcd( address, debouncedSearch, pageSize, @@ -62,6 +62,29 @@ export const PastTxsLite = () => { setCurrentPage(1); }, [debouncedSearch, setCurrentPage]); + const handleTransactionTableWithWalletEmptyState = useCallback(() => { + if (search.trim().length > 0) + return ( + + ); + + if (error) return ; + + return ( + + ); + }, [search, error, wasm]); + return ( @@ -90,23 +113,7 @@ export const PastTxsLite = () => { 0 ? ( - - ) : ( - - ) - } + emptyState={handleTransactionTableWithWalletEmptyState()} showActions={false} showRelations={false} /> From 23df54e9ca368fa2d0f967db3141a93fcb0aa732 Mon Sep 17 00:00:00 2001 From: Poafs1 Date: Tue, 18 Jun 2024 13:39:39 +0700 Subject: [PATCH 3/6] feat(utils): add timeout to txs addr lcd api call --- src/lib/pages/account-details/components/tables/txs/Lite.tsx | 2 +- src/lib/services/tx/index.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lib/pages/account-details/components/tables/txs/Lite.tsx b/src/lib/pages/account-details/components/tables/txs/Lite.tsx index a619a6299..89b6637ff 100644 --- a/src/lib/pages/account-details/components/tables/txs/Lite.tsx +++ b/src/lib/pages/account-details/components/tables/txs/Lite.tsx @@ -72,7 +72,7 @@ export const TxsTableLite = ({ ) } diff --git a/src/lib/services/tx/index.ts b/src/lib/services/tx/index.ts index 06dd6bef4..16652e8d2 100644 --- a/src/lib/services/tx/index.ts +++ b/src/lib/services/tx/index.ts @@ -20,6 +20,7 @@ import { useValidateAddress, useWasmConfig, } from "lib/app-provider"; +import { createQueryFnWithTimeout } from "lib/query-utils"; import type { BechAddr, BechAddr20, @@ -361,7 +362,7 @@ export const useTxsByAddressLcd = ( limit, offset, ], - queryfn, + createQueryFnWithTimeout(queryfn, 20000), { ...options, retry: 1, refetchOnWindowFocus: false } ); }; From 9de9b026ab90f6ea9e96c456d10f7a3a15e13405 Mon Sep 17 00:00:00 2001 From: Poafs1 Date: Tue, 18 Jun 2024 14:39:33 +0700 Subject: [PATCH 4/6] feat(components): add alert to txs table --- .../components/tables/txs/Lite.tsx | 28 +++++++++++++++---- src/lib/pages/account-details/index.tsx | 2 +- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/lib/pages/account-details/components/tables/txs/Lite.tsx b/src/lib/pages/account-details/components/tables/txs/Lite.tsx index 89b6637ff..a0c309b11 100644 --- a/src/lib/pages/account-details/components/tables/txs/Lite.tsx +++ b/src/lib/pages/account-details/components/tables/txs/Lite.tsx @@ -1,6 +1,7 @@ -import { Box } from "@chakra-ui/react"; +import { Alert, AlertDescription, Box, Flex } from "@chakra-ui/react"; -import { useMobile } from "lib/app-provider"; +import { useMobile, useTierConfig } from "lib/app-provider"; +import { CustomIcon } from "lib/components/icon"; import { Pagination } from "lib/components/pagination"; import { usePaginator } from "lib/components/pagination/usePaginator"; import { EmptyState, ErrorFetching } from "lib/components/state"; @@ -21,6 +22,7 @@ export const TxsTableLite = ({ onViewMore, }: TxsTableProps) => { const isMobile = useMobile(); + const isFullTier = useTierConfig() === "full"; const { pagesQuantity, @@ -59,8 +61,24 @@ export const TxsTableLite = ({ onViewMore={onViewMore} /> ) : ( - <> - + + + + + + Please note that account transactions are queried from the LCD and + may have pruned transactions that will not be displayed. + + {!isMobileOverview && ( ))} - + )} ); diff --git a/src/lib/pages/account-details/index.tsx b/src/lib/pages/account-details/index.tsx index 812569aa4..1e1aecf6e 100644 --- a/src/lib/pages/account-details/index.tsx +++ b/src/lib/pages/account-details/index.tsx @@ -179,7 +179,7 @@ const AccountDetailsBody = ({ NFTs Date: Wed, 19 Jun 2024 16:05:39 +0700 Subject: [PATCH 5/6] fix: pr comments --- src/lib/pages/past-txs/lite.tsx | 66 ++++++++++++++++++++------------- src/lib/services/tx/index.ts | 24 ------------ src/lib/services/tx/lcd.ts | 34 ++++++++++------- 3 files changed, 61 insertions(+), 63 deletions(-) diff --git a/src/lib/pages/past-txs/lite.tsx b/src/lib/pages/past-txs/lite.tsx index 6f2ed74bd..333f97c02 100644 --- a/src/lib/pages/past-txs/lite.tsx +++ b/src/lib/pages/past-txs/lite.tsx @@ -1,6 +1,6 @@ import { Flex, Heading } from "@chakra-ui/react"; import type { ChangeEvent } from "react"; -import { useCallback, useEffect, useState } from "react"; +import { useEffect, useState } from "react"; import { useCurrentChain, useWasmConfig } from "lib/app-provider"; import InputWithIcon from "lib/components/InputWithIcon"; @@ -13,6 +13,39 @@ import { UserDocsLink } from "lib/components/UserDocsLink"; import { useDebounce } from "lib/hooks"; import { useTxsByAddressLcd } from "lib/services/tx"; +interface PastTxsLiteTransactionsTableWithWalletEmptyStateProps { + search: string; + wasm: ReturnType; + error: unknown; +} + +const PastTxsLiteTransactionsTableWithWalletEmptyState = ({ + search, + wasm, + error, +}: PastTxsLiteTransactionsTableWithWalletEmptyStateProps) => { + if (search.trim().length > 0) + return ( + + ); + + if (error) return ; + + return ( + + ); +}; + export const PastTxsLite = () => { const wasm = useWasmConfig({ shouldRedirect: false }); const { @@ -62,29 +95,6 @@ export const PastTxsLite = () => { setCurrentPage(1); }, [debouncedSearch, setCurrentPage]); - const handleTransactionTableWithWalletEmptyState = useCallback(() => { - if (search.trim().length > 0) - return ( - - ); - - if (error) return ; - - return ( - - ); - }, [search, error, wasm]); - return ( @@ -113,7 +123,13 @@ export const PastTxsLite = () => { + } showActions={false} showRelations={false} /> diff --git a/src/lib/services/tx/index.ts b/src/lib/services/tx/index.ts index 16652e8d2..678b68802 100644 --- a/src/lib/services/tx/index.ts +++ b/src/lib/services/tx/index.ts @@ -282,30 +282,6 @@ export const useTxsByContractAddressLcd = ( ); }; -export const useTxsByAccountAddressLcd = ( - address: Option, - limit: number, - offset: number -) => { - const endpoint = useLcdEndpoint(); - - return useQuery( - [ - CELATONE_QUERY_KEYS.TXS_BY_ACCOUNT_ADDRESS_LCD, - endpoint, - address, - limit, - offset, - ], - async () => { - if (!address) - throw new Error("address is undefined (useTxsByAccountAddressLcd)"); - return getTxsByAccountAddressLcd(endpoint, address, limit, offset); - }, - { retry: 1, refetchOnWindowFocus: false } - ); -}; - export const useTxsByAddressLcd = ( address: Option, search: Option, diff --git a/src/lib/services/tx/lcd.ts b/src/lib/services/tx/lcd.ts index 19ef065af..ca5b19a47 100644 --- a/src/lib/services/tx/lcd.ts +++ b/src/lib/services/tx/lcd.ts @@ -43,23 +43,29 @@ export const getTxsByAccountAddressLcd = async ( limit: number, offset: number ) => - axios - .get(`${endpoint}/cosmos/tx/v1beta1/txs`, { + Promise.allSettled([ + axios.get(`${endpoint}/cosmos/tx/v1beta1/txs`, { params: { order_by: 2, limit, page: offset / limit + 1, query: `message.sender='${encodeURI(address)}'`, }, - }) - .catch(() => - axios.get(`${endpoint}/cosmos/tx/v1beta1/txs`, { - params: { - order_by: 2, - limit, - page: offset / limit + 1, - events: `message.sender='${encodeURI(address)}'`, - }, - }) - ) - .then(({ data }) => parseWithError(zTxsByAddressResponseLcd, data)); + }), + axios.get(`${endpoint}/cosmos/tx/v1beta1/txs`, { + params: { + order_by: 2, + limit, + page: offset / limit + 1, + events: `message.sender='${encodeURI(address)}'`, + }, + }), + ]).then(([queryParam, eventsParam]) => { + if (queryParam.status === "fulfilled") + return parseWithError(zTxsByAddressResponseLcd, queryParam.value.data); + + if (eventsParam.status === "fulfilled") + return parseWithError(zTxsByAddressResponseLcd, eventsParam.value.data); + + throw new Error("No data found (getTxsByAccountAddressLcd)"); + }); From f67e5a5ff28cf02984e6f0b4544d00db28d77f5a Mon Sep 17 00:00:00 2001 From: evilpeach Date: Wed, 19 Jun 2024 17:20:18 +0700 Subject: [PATCH 6/6] fix: isWasmEnabled --- src/lib/pages/past-txs/lite.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib/pages/past-txs/lite.tsx b/src/lib/pages/past-txs/lite.tsx index 333f97c02..2e08b69b3 100644 --- a/src/lib/pages/past-txs/lite.tsx +++ b/src/lib/pages/past-txs/lite.tsx @@ -15,13 +15,13 @@ import { useTxsByAddressLcd } from "lib/services/tx"; interface PastTxsLiteTransactionsTableWithWalletEmptyStateProps { search: string; - wasm: ReturnType; + isWasmEnabled: boolean; error: unknown; } const PastTxsLiteTransactionsTableWithWalletEmptyState = ({ search, - wasm, + isWasmEnabled, error, }: PastTxsLiteTransactionsTableWithWalletEmptyStateProps) => { if (search.trim().length > 0) @@ -29,7 +29,7 @@ const PastTxsLiteTransactionsTableWithWalletEmptyState = ({ @@ -47,7 +47,7 @@ const PastTxsLiteTransactionsTableWithWalletEmptyState = ({ }; export const PastTxsLite = () => { - const wasm = useWasmConfig({ shouldRedirect: false }); + const isWasmEnabled = useWasmConfig({ shouldRedirect: false }).enabled; const { address, chain: { chain_id: chainId }, @@ -112,7 +112,7 @@ export const PastTxsLite = () => { { emptyState={ }