Skip to content

Commit d8d30e4

Browse files
authored
Polls pending transactions at 5 second intervals with custom refetchInterval (#281)
1 parent b240dfa commit d8d30e4

File tree

4 files changed

+69
-7
lines changed

4 files changed

+69
-7
lines changed

renderer/components/NoteRow/NoteRow.tsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@ import type {
55
TransactionStatus,
66
TransactionType,
77
} from "@ironfish/sdk";
8-
import { ReactNode, useMemo } from "react";
8+
import { ReactNode, useMemo, useState } from "react";
99
import { MessageDescriptor, useIntl } from "react-intl";
1010

11-
import { TRPCRouterOutputs } from "@/providers/TRPCProvider";
11+
import { trpcReact, TRPCRouterOutputs } from "@/providers/TRPCProvider";
1212
import { MaybeLink } from "@/ui/ChakraLink/ChakraLink";
1313
import { COLORS } from "@/ui/colors";
1414
import { ShadowCard } from "@/ui/ShadowCard/ShadowCard";
1515
import { CurrencyUtils } from "@/utils/currency";
1616
import { formatDate } from "@/utils/formatDate";
17+
import {
18+
refetchTransactionUntilTerminal,
19+
isTransactionStatusTerminal,
20+
} from "@/utils/transactionUtils";
1721

1822
import { BridgeIcon } from "./icons/BridgeIcon";
1923
import { ChangeIcon } from "./icons/ChangeIcon";
@@ -110,7 +114,7 @@ export function NoteRow({
110114
from,
111115
to,
112116
type,
113-
status,
117+
status: initialStatus,
114118
memo,
115119
transactionHash,
116120
asTransaction = false,
@@ -137,6 +141,21 @@ export function NoteRow({
137141
isBridge?: boolean;
138142
}) {
139143
const { formatMessage } = useIntl();
144+
const [status, setStatus] = useState(initialStatus);
145+
146+
// Poll Transaction if it is a non-terminal status
147+
trpcReact.getTransaction.useQuery(
148+
{ accountName, transactionHash },
149+
{
150+
enabled: asTransaction && !isTransactionStatusTerminal(status),
151+
refetchInterval: refetchTransactionUntilTerminal,
152+
onSuccess: (data) => {
153+
if (data.transaction.status !== status) {
154+
setStatus(data.transaction.status);
155+
}
156+
},
157+
},
158+
);
140159

141160
const statusDisplay = getNoteStatusDisplay(
142161
type,

renderer/intl/locales/en-US.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,9 @@
544544
"TzwzhT": {
545545
"message": "You can remove and reimport your accounts whenever you like, provided that you possess the account keys. It is highly recommended to maintain a backup of your account keys in a secure location."
546546
},
547+
"U78NhE": {
548+
"message": "Complete"
549+
},
547550
"ULXFfP": {
548551
"message": "Receive"
549552
},
@@ -730,6 +733,9 @@
730733
"hR0flV": {
731734
"message": "All your transactions, whether in $IRON or other custom assets, will be displayed in this section. To start a transaction, simply click on the 'Send' or 'Receive' tabs."
732735
},
736+
"iFsDVR": {
737+
"message": "Loading"
738+
},
733739
"iWiHY7": {
734740
"message": "The blockchain is syncing. Your balance may be inaccurate and sending transactions will be disabled until the sync is complete."
735741
},
@@ -769,6 +775,9 @@
769775
"kTt/ND": {
770776
"message": "Russian"
771777
},
778+
"kbpDqo": {
779+
"message": "Preparing destination txn"
780+
},
772781
"krty63": {
773782
"message": "Need help?"
774783
},
@@ -856,6 +865,9 @@
856865
"rGIQdX": {
857866
"message": "Back to Account Overview"
858867
},
868+
"raexxM": {
869+
"message": "Submitted"
870+
},
859871
"rbrahO": {
860872
"message": "Close"
861873
},
@@ -865,6 +877,9 @@
865877
"rqrhXg": {
866878
"message": "Confirm Your Recovery Phrase"
867879
},
880+
"rrBTkh": {
881+
"message": "Submitted destination txn"
882+
},
868883
"sXlL42": {
869884
"message": "Encrypted Wallets Unsupported"
870885
},
@@ -907,6 +922,9 @@
907922
"vV69eP": {
908923
"message": "Downloading a snapshot is the fastest way to sync with the network."
909924
},
925+
"vXCeIi": {
926+
"message": "Failed"
927+
},
910928
"vaP4MI": {
911929
"message": "It currently holds:"
912930
},

renderer/pages/accounts/[account-name]/transaction/[transaction-hash].tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { TransactionInformation } from "@/components/TransactionInformation/Tran
1010
import MainLayout from "@/layouts/MainLayout";
1111
import { trpcReact } from "@/providers/TRPCProvider";
1212
import { asQueryString } from "@/utils/parseRouteQuery";
13+
import { refetchTransactionUntilTerminal } from "@/utils/transactionUtils";
1314

1415
const messages = defineMessages({
1516
backToAccountOverview: {
@@ -38,10 +39,15 @@ function SingleTransactionContent({
3839
name: accountName,
3940
});
4041

41-
const { data: transactionData } = trpcReact.getTransaction.useQuery({
42-
accountName,
43-
transactionHash,
44-
});
42+
const { data: transactionData } = trpcReact.getTransaction.useQuery(
43+
{
44+
accountName,
45+
transactionHash,
46+
},
47+
{
48+
refetchInterval: refetchTransactionUntilTerminal,
49+
},
50+
);
4551

4652
if (!accountData) {
4753
return null;

renderer/utils/transactionUtils.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { TransactionStatus } from "@ironfish/sdk";
2+
3+
import { TRPCRouterOutputs } from "@/providers/TRPCProvider";
4+
5+
export const isTransactionStatusTerminal = (status: TransactionStatus) => {
6+
return status === "confirmed" || status === "expired";
7+
};
8+
9+
export const refetchTransactionUntilTerminal = (
10+
query: TRPCRouterOutputs["getTransaction"] | undefined,
11+
) => {
12+
if (!query) {
13+
return 5000;
14+
}
15+
const txStatus = query.transaction.status;
16+
const isTerminalStatus = isTransactionStatusTerminal(txStatus);
17+
18+
return !isTerminalStatus ? 5000 : false;
19+
};

0 commit comments

Comments
 (0)