Skip to content

Commit

Permalink
Fix AccountListView table sort order and flickering issue
Browse files Browse the repository at this point in the history
Fix #259
Fix #225
Fix #239
  • Loading branch information
SvenDowideit authored Jul 19, 2022
1 parent 6104ac7 commit 13111e4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
12 changes: 10 additions & 2 deletions src/renderer/components/ProgramChange.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,22 @@ export function ProgramChange(props: {
return;
}
if (!pubKey) {
setChangeInfo(undefined);
// setChangeInfo(undefined);
return;
}
setChangeInfo(getAccount(net, pubKey));
const update = getAccount(net, pubKey);
if (!update) {
return;
}
setChangeInfo(update);
}, [net, status, pubKey]);
useEffect(updateAccount, [updateAccount]);
useInterval(updateAccount, 666);

if (!change) {
return null;
}

const showCount = change?.count || 0;
const showSOL = change
? truncateLamportAmount(change)
Expand Down
32 changes: 26 additions & 6 deletions src/renderer/components/ProgramChangeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,32 @@ function ProgramChangeView() {
const WalletAdapterState = useWallet();

function sortFunction(a: AccountInfo, b: AccountInfo) {
let order = 0;
switch (sortColumn) {
case SortColumn.Count:
return b.count - a.count;
order = b.count - a.count;
break;
case SortColumn.Sol:
if (!b.accountInfo || !a.accountInfo) {
return 0;
order = 0;
} else {
order = b.accountInfo.lamports - a.accountInfo.lamports;
}
return b.accountInfo.lamports - a.accountInfo.lamports;
break;
case SortColumn.MaxDelta:
default:
return Math.abs(b.maxDelta) - Math.abs(a.maxDelta);
order = Math.abs(b.maxDelta) - Math.abs(a.maxDelta);
}

if (order === 0) {
// tie breaker based on public key
if (a.pubKey > b.pubKey) {
return 1;
}

return -1;
}
return order;
}

useInterval(() => {
Expand Down Expand Up @@ -145,8 +159,14 @@ function ProgramChangeView() {
});
setPinnedAccount(pinMap);
setDisplayList(showKeys);
refreshAccountInfos(net, showKeys);
}, 666);
}, 333);

useInterval(() => {
if (status !== NetStatus.Running) {
return;
}
refreshAccountInfos(net, displayList);
}, 2222);

const uniqueAccounts = displayList.length;

Expand Down
3 changes: 1 addition & 2 deletions src/renderer/data/accounts/getAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const HEXDUMP_BYTES = 512;
// Also use that to decide if we need to do a validator is available check or not - if we're watching changes, then we already know...

const cache = new LRUCache<string, AccountInfo>({
maxSize: 500,
maxSize: 2000,
entryExpirationTimeInMS: 60000,
});

Expand Down Expand Up @@ -109,7 +109,6 @@ export function getAccount(net: Net, pubKey: string): AccountInfo | undefined {
if (cachedResponse) {
return cachedResponse;
}

// logger.silly('getAccountInfo cache miss', pubKey, pubKey.toString());

const response: AccountInfo = {
Expand Down
1 change: 0 additions & 1 deletion src/renderer/nav/ValidatorNetworkInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as sol from '@solana/web3.js';
import { useEffect, useState } from 'react';
import { Col, Row } from 'react-bootstrap';
import Container from 'react-bootstrap/Container';
import { isWhiteSpaceLike } from 'typescript';
import { VictoryPie } from 'victory';
import { logger } from '../common/globals';
import {
Expand Down

0 comments on commit 13111e4

Please sign in to comment.