diff --git a/public/locales/en.json b/public/locales/en.json index c89e29a..50a7708 100644 --- a/public/locales/en.json +++ b/public/locales/en.json @@ -325,6 +325,7 @@ "autoRefreshTables": "Auto-refresh tables", "autoRefreshTablesDescription": "Whether or not large table listings (e.g. transactions, names) should automatically refresh when a change is detected on the network.", "autoRefreshAddressPage": "Auto-refresh address page", + "autoRefreshNamePage": "Auto-refresh name page", "subMenuAdvanced": "Advanced settings", "alwaysIncludeMined": "Always include mined transactions in transaction listings (may require refresh)", diff --git a/src/pages/names/NamePage.tsx b/src/pages/names/NamePage.tsx index 9647bfa..025fefe 100644 --- a/src/pages/names/NamePage.tsx +++ b/src/pages/names/NamePage.tsx @@ -22,6 +22,7 @@ import { useWallets } from "@wallets"; import { useNameSuffix } from "@utils/currency"; +import { useSubscription } from "@global/ws/WebsocketSubscription"; import { useBooleanSetting } from "@utils/settings"; import { NameButtonRow } from "./NameButtonRow"; @@ -35,7 +36,17 @@ name: string; } -function PageContents({ name, nameWithSuffix }: { name: KristName; nameWithSuffix: string }): JSX.Element { +interface PageContentsProps { + name: KristName; + nameWithSuffix: string; + lastTransactionID: number; +} + +function PageContents({ + name, + nameWithSuffix, + lastTransactionID +}: PageContentsProps): JSX.Element { const { t } = useTranslation(); const { wallets } = useWallets(); const copyNameSuffixes = useBooleanSetting("copyNameSuffixes"); @@ -134,12 +145,20 @@ {/* Recent transactions */} - + {/* Name history */} - + ; @@ -154,14 +173,21 @@ const [kristName, setKristName] = useState(); const [error, setError] = useState(); + // Used to refresh the cards when a transaction is made to the name + const lastTransactionID = useSubscription({ name }); + const shouldAutoRefresh = useBooleanSetting("autoRefreshNamePage"); + const usedRefreshID = shouldAutoRefresh ? lastTransactionID : 0; + // Load the name on page load useEffect(() => { api.get<{ name: KristName }>("names/" + encodeURIComponent(name)) .then(res => setKristName(res.name)) .catch(err => { console.error(err); setError(err); }); - }, [syncNode, name]); + }, [syncNode, name, usedRefreshID]); - const nameWithSuffix = kristName ? `${kristName.name}.${nameSuffix}` : undefined; + const nameWithSuffix = kristName + ? `${kristName.name}.${nameSuffix}` + : undefined; // Change the page title depending on whether or not the name has loaded const title = kristName @@ -187,7 +213,13 @@ /> ) : (kristName - ? + ? ( + + ) : )} ; } diff --git a/src/pages/names/NameTransactionsCard.tsx b/src/pages/names/NameTransactionsCard.tsx index 6841931..ec54316 100644 --- a/src/pages/names/NameTransactionsCard.tsx +++ b/src/pages/names/NameTransactionsCard.tsx @@ -28,9 +28,14 @@ interface Props { name: string; type: LookupTXType; + lastTransactionID: number; } -export function NameTransactionsCard({ name, type }: Props): JSX.Element { +export function NameTransactionsCard({ + name, + type, + lastTransactionID +}: Props): JSX.Element { const { t } = useTranslation(); const syncNode = useSyncNode(); @@ -39,8 +44,6 @@ const [loading, setLoading] = useState(true); // Fetch transactions on page load or sync node reload - // TODO: set up something to temporarily subscribe to an address via the - // websocket service, so this can be updated in realtime useEffect(() => { if (!syncNode) return; @@ -52,7 +55,7 @@ .then(setRes) .catch(setError) .finally(() => setLoading(false)); - }, [syncNode, name, type]); + }, [syncNode, name, type, lastTransactionID]); const isEmpty = !loading && (error || !res || res.count === 0); const classes = classNames("kw-card", "name-card-transactions", { diff --git a/src/pages/settings/SettingsPage.tsx b/src/pages/settings/SettingsPage.tsx index 2eca35d..80b8ad6 100644 --- a/src/pages/settings/SettingsPage.tsx +++ b/src/pages/settings/SettingsPage.tsx @@ -51,10 +51,15 @@ /> - {/* Auto-refresh tables */} + {/* Auto-refresh address page */} + + {/* Auto-refresh name page */} + + + {/* Advanced settings */} diff --git a/src/utils/settings.ts b/src/utils/settings.ts index f54abb7..f38e89a 100644 --- a/src/utils/settings.ts +++ b/src/utils/settings.ts @@ -25,6 +25,9 @@ /** Whether or not the address page should auto-refresh when a change is * detected on the network. */ readonly autoRefreshAddressPage: boolean; + /** Whether or not the name page should auto-refresh when a change is detected + * on the network. */ + readonly autoRefreshNamePage: boolean; // =========================================================================== // ADVANCED SETTINGS @@ -56,6 +59,7 @@ export const DEFAULT_SETTINGS: SettingsState = { autoRefreshTables: true, autoRefreshAddressPage: true, + autoRefreshNamePage: true, alwaysIncludeMined: false, copyNameSuffixes: true,