Skip to content

Commit

Permalink
Merge pull request #295 from TrueBlocks/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
tjayrush authored Dec 22, 2022
2 parents a43240c + 49f39d4 commit 2021e18
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 43 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"react-syntax-highlighter": "^15.4.3",
"react-test-renderer": "^17.0.2",
"recharts": "^2.0.9",
"trueblocks-sdk": "../trueblocks-sdk",
"trueblocks-sdk": "^0.50.0",
"ts-morph": "^13.0.2"
}
}
8 changes: 4 additions & 4 deletions src/ui/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
import {
Chain,
getConfig, getVersion, Status, SuccessResponse,
Config, getConfig, getVersion, SuccessResponse,
} from 'trueblocks-sdk';

import { ChainSelect } from '@components/ChainSelect';
Expand All @@ -32,8 +32,8 @@ import { useDatastore } from '@hooks/useDatastore';
import {
isFailedCall, isSuccessfulCall, wrapResponse,
} from '@modules/api/call_status';
import { createEmptyStatus } from '@modules/types/Config';
import { createEmptyMeta } from '@modules/types/Meta';
import { createEmptyStatus } from '@modules/types/Status';

import {
ExplorerLocation, NamesLocation, RootLocation, Routes, SettingsLocation, SupportLocation,
Expand All @@ -60,7 +60,7 @@ export const App = () => {
dayjs.extend(relativeTime);

const { location, action } = useHistory();
const [status, setStatus] = useState<Pick<SuccessResponse<Status>, 'data' | 'meta'>>({
const [status, setStatus] = useState<Pick<SuccessResponse<Config>, 'data' | 'meta'>>({
data: createEmptyStatus(),
meta: createEmptyMeta(),
});
Expand Down Expand Up @@ -103,7 +103,7 @@ export const App = () => {

if (isSuccessfulCall(statusResponse)) {
setStatus({
data: statusResponse.data[0] as Status,
data: statusResponse.data[0] as Config,
meta: statusResponse.meta,
});

Expand Down
4 changes: 2 additions & 2 deletions src/ui/components/ChainSelect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { useHistory } from 'react-router-dom';

import { useGlobalState } from '@state';
import { Select } from 'antd';
import { Status } from 'trueblocks-sdk';
import { Config } from 'trueblocks-sdk';

export function ChainSelect({ status }: { status: Status }) {
export function ChainSelect({ status }: { status: Config }) {
const history = useHistory();
const { chain, setChain } = useGlobalState();

Expand Down
4 changes: 2 additions & 2 deletions src/ui/components/SidePanels/StatusPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '@ant-design/icons';
import { Badge } from 'antd';
import filesize from 'filesize';
import { Chain, Status, SuccessResponse } from 'trueblocks-sdk';
import { Chain, Config, SuccessResponse } from 'trueblocks-sdk';

import { Loading } from '@components/Loading';
import { createEmptyMeta } from '@modules/types/Meta';
Expand All @@ -16,7 +16,7 @@ import { useGlobalState2 } from '../../State';
interface StatusPanelProps {
// status is always a { data: ..., meta: ... } because of the way we fetch it in App.ts
chain: string;
status: Pick<SuccessResponse<Status>, 'data' | 'meta'>;
status: Pick<SuccessResponse<Config>, 'data' | 'meta'>;
error: boolean;
loading: boolean;
}
Expand Down
4 changes: 2 additions & 2 deletions src/ui/datastore/messages.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
address, getNames, ListStats, Name,
address, AppearanceCount, getNames, Name,
} from 'trueblocks-sdk';

import { TransactionFilters } from '@modules/filters/transaction';
Expand Down Expand Up @@ -41,7 +41,7 @@ export type GetTransactionsTotal = {
addresses: address[],
}

export type GetTransactionsTotalResult = ListStats[];
export type GetTransactionsTotalResult = AppearanceCount[];

export type GetPage = {
chain: string,
Expand Down
7 changes: 3 additions & 4 deletions src/ui/datastore/worker/transactions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
address as Address, AnyResponse, getExport, getList, ListStats, Name, Transaction,
address as Address, AnyResponse, AppearanceCount, getExport, getList, Name, Transaction,
} from 'trueblocks-sdk';

import { isFailedCall, wrapResponse } from '@modules/api/call_status';
Expand Down Expand Up @@ -37,14 +37,13 @@ async function fetchTransactions(chain: string, addresses: Address[], loaded: nu
return transactions;
}

type GetTransactionsTotal = (chain: string, addresses: Address[]) => Promise<ListStats[]>;
type GetTransactionsTotal = (chain: string, addresses: Address[]) => Promise<AppearanceCount[]>;
export const getTransactionsTotal: GetTransactionsTotal = async (chain, addresses) => {
const listCall = wrapResponse((await getList({
chain,
count: true,
appearances: true,
addrs: addresses,
}) as AnyResponse<ListStats[]>));
}) as AnyResponse<AppearanceCount[]>));

if (isFailedCall(listCall)) {
throw new Error(listCall.errors.join());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Status } from 'trueblocks-sdk';
import { Config } from 'trueblocks-sdk';

export function createEmptyStatus(): Status {
export function createEmptyStatus(): Config {
return {
clientVersion: '',
clientIds: '',
Expand All @@ -26,6 +26,7 @@ export function createEmptyStatus(): Status {
nFiles: 0,
nFolders: 0,
sizeInBytes: 0,
isValid: false,
},
{
items: [],
Expand All @@ -34,6 +35,7 @@ export function createEmptyStatus(): Status {
nFiles: 0,
nFolders: 0,
sizeInBytes: 0,
isValid: false,
},
{
items: [],
Expand All @@ -42,6 +44,7 @@ export function createEmptyStatus(): Status {
nFiles: 0,
nFolders: 0,
sizeInBytes: 0,
isValid: false,
},
{
items: [],
Expand All @@ -50,6 +53,7 @@ export function createEmptyStatus(): Status {
nFiles: 0,
nFolders: 0,
sizeInBytes: 0,
isValid: false,
},
],
chains: [],
Expand Down
43 changes: 26 additions & 17 deletions src/ui/views/Dashboard/Tabs/Details/SubTabs/HistoryRecons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,14 @@ const statementHeader = (statement: Reconciliation, details: boolean, setShowDet

//-----------------------------------------------------------------
const statementBody = (statement: Reconciliation, details: boolean, styles: any) => {
const preAppBlkStr = statement.prevAppBlk === undefined ? '0' : statement.prevAppBlk.toString();
const rowStyle = styles.tableRow;
const detailView = !details ? <></> : (
<>
{DividerRow(rowStyle)}
{DetailRow(rowStyle, 'assetSymbol', statement.assetSymbol)}
{DetailRow(rowStyle, 'decimals', statement.decimals)}
{DetailRow(rowStyle, 'prevAppBlk', statement.prevAppBlk.toString())}
{DetailRow(rowStyle, 'prevAppBlk', preAppBlkStr)}
{DetailRow(rowStyle, 'blockNumber', statement.blockNumber.toString())}
{DetailRow(rowStyle, 'transactionIndex', statement.transactionIndex.toString())}
{DetailRow(rowStyle, 'timestamp', statement.timestamp.toString())}
Expand All @@ -125,30 +126,38 @@ const statementBody = (statement: Reconciliation, details: boolean, styles: any)
</>
);

const toNumberArguments = (...strings: string[]): number[] => strings.map((someString) => (
someString === '' ? 0.0 : parseFloat(someString)));
const toNumberArguments2 = (v1: string|undefined, v2: string|undefined): number[] => {
const s1 = v1 === undefined ? '0.0' : v1;
const s2 = v2 === undefined ? '0.0' : v2;
return [parseFloat(s1), parseFloat(s2)];
};

const toNumberArguments1 = (v1: string|undefined): number[] => {
const s1 = v1 === undefined ? '0.0' : v1;
return [parseFloat(s1)];
};

return (
<table style={{ width: '100%', tableLayout: 'fixed' }}>
<tbody>
<HeaderRow />
{BodyRow(rowStyle, 'begBal', details, 0, 0, ...toNumberArguments(statement.begBal, statement.begBalDiff))}
{BodyRow(rowStyle, 'amount', details, ...toNumberArguments(statement.amountIn, statement.amountOut))}
{BodyRow(rowStyle, 'internal', details, ...toNumberArguments(statement.internalIn, statement.internalOut))}
{BodyRow(rowStyle, 'begBal', details, 0, 0, ...toNumberArguments2(statement.begBal, statement.begBalDiff))}
{BodyRow(rowStyle, 'amount', details, ...toNumberArguments2(statement.amountIn, statement.amountOut))}
{BodyRow(rowStyle, 'internal', details, ...toNumberArguments2(statement.internalIn, statement.internalOut))}
{BodyRow(
rowStyle,
'selfDestruct',
details,
...toNumberArguments(statement.selfDestructIn, statement.selfDestructOut),
...toNumberArguments2(statement.selfDestructIn, statement.selfDestructOut),
)}
{BodyRow(rowStyle, 'baseReward', details, ...toNumberArguments(statement.minerBaseRewardIn), 0)}
{BodyRow(rowStyle, 'txFee', details, ...toNumberArguments(statement.minerTxFeeIn), 0)}
{BodyRow(rowStyle, 'nephewReward', details, ...toNumberArguments(statement.minerNephewRewardIn), 0)}
{BodyRow(rowStyle, 'uncleReward', details, ...toNumberArguments(statement.minerUncleRewardIn), 0)}
{BodyRow(rowStyle, 'prefund', details, ...toNumberArguments(statement.prefundIn), 0)}
{BodyRow(rowStyle, 'gasCost', details, 0, ...toNumberArguments(statement.gasOut))}
{BodyRow(rowStyle, 'totalNet', details, 0, 0, ...toNumberArguments(statement.amountNet))}
{BodyRow(rowStyle, 'endBal', details, 0, 0, ...toNumberArguments(statement.endBal, statement.endBalDiff))}
{BodyRow(rowStyle, 'baseReward', details, ...toNumberArguments1(statement.minerBaseRewardIn), 0)}
{BodyRow(rowStyle, 'txFee', details, ...toNumberArguments1(statement.minerTxFeeIn), 0)}
{BodyRow(rowStyle, 'nephewReward', details, ...toNumberArguments1(statement.minerNephewRewardIn), 0)}
{BodyRow(rowStyle, 'uncleReward', details, ...toNumberArguments1(statement.minerUncleRewardIn), 0)}
{BodyRow(rowStyle, 'prefund', details, ...toNumberArguments1(statement.prefundIn), 0)}
{BodyRow(rowStyle, 'gasCost', details, 0, ...toNumberArguments1(statement.gasOut))}
{BodyRow(rowStyle, 'totalNet', details, 0, 0, ...toNumberArguments1(statement.amountNet))}
{BodyRow(rowStyle, 'endBal', details, 0, 0, ...toNumberArguments2(statement.endBal, statement.endBalDiff))}
{detailView}
</tbody>
</table>
Expand Down Expand Up @@ -211,12 +220,12 @@ const BodyRow = (
};

//-----------------------------------------------------------------
const DetailRow = (style: string, name: string, value: double | string) => {
const DetailRow = (style: string, name: string, value: double | string | undefined) => {
const isErr: boolean = name?.includes('Diff') && value !== 0;
const valueToDisplay = (() => {
if (typeof value === 'number') return clip2(value);

const parsed = parseFloat(value);
const parsed = value ? parseFloat(value) : 0;

if (Number.isNaN(parsed)) return value;

Expand Down
3 changes: 2 additions & 1 deletion src/ui/views/Dashboard/Tabs/Details/components/Statement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const Statement = ({ statement }: { statement: Reconciliation }) => {
}, [denom, statement.assetSymbol, statement.priceSource]);

const pricedRecon = priceReconciliation(statement, denom);
const gasOutStr = pricedRecon.gasOut ? pricedRecon.gasOut.toString() : '0.00';
return (
<tr className={style.row} key={`${k}-row`}>
<td key={`${k}-1`} className={style.col} style={{ width: '12%' }}>
Expand All @@ -39,7 +40,7 @@ export const Statement = ({ statement }: { statement: Reconciliation }) => {
{showValue(pricedRecon.totalOutLessGas.toString())}
</td>
<td key={`${k}-5`} className={style.col} style={{ width: '17%' }}>
{showValue(pricedRecon.gasOut.toString(), false, true)}
{showValue(gasOutStr, false, true)}
</td>
<td key={`${k}-6`} className={style.col} style={{ width: '17%' }}>
{showValue(pricedRecon.endBal.toString(), true)}
Expand Down
5 changes: 3 additions & 2 deletions src/ui/views/Dashboard/Tabs/Monitors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
} from 'antd';
import { ColumnsType } from 'antd/lib/table';
import {
Chain, getConfig, Monitor, Status,
Chain, Config,
getConfig, Monitor,
} from 'trueblocks-sdk';

import { ClickableAddress } from '@components/ClickableAddress';
Expand Down Expand Up @@ -44,7 +45,7 @@ export const Monitors = () => {
modes: ['show'],
module: ['monitors'],
details: true,
}), undefined, []) as CallStatus<Status[]>;
}), undefined, []) as CallStatus<Config[]>;
if (isFailedCall(monitorsCall)) {
createErrorNotification({
description: 'Could not fetch monitors',
Expand Down
2 changes: 1 addition & 1 deletion src/ui/views/Settings/Tabs/Indexes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { addColumn, addNumColumn } from '@components/Table';
import { useSdk } from '@hooks/useSdk';
import { isFailedCall, isSuccessfulCall } from '@modules/api/call_status';
import { createErrorNotification } from '@modules/error_notification';
import { createEmptyStatus } from '@modules/types/Status';
import { createEmptyStatus } from '@modules/types/Config';

import {
SettingsIndexesChartsLocation,
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13005,7 +13005,7 @@ resolve@^2.0.0-next.3:
react-test-renderer: ^17.0.2
recharts: ^2.0.9
style-loader: ^2.0.0
trueblocks-sdk: ../trueblocks-sdk
trueblocks-sdk: ^0.50.0
ts-jest: ^26.5.3
ts-loader: ^8.0.18
ts-morph: ^13.0.2
Expand All @@ -13016,12 +13016,12 @@ resolve@^2.0.0-next.3:
languageName: unknown
linkType: soft

"trueblocks-sdk@file:../trueblocks-sdk::locator=trueblocks-explorer%40workspace%3A.":
version: 0.45.0
resolution: "trueblocks-sdk@file:../trueblocks-sdk#../trueblocks-sdk::hash=5a1126&locator=trueblocks-explorer%40workspace%3A."
"trueblocks-sdk@npm:^0.50.0":
version: 0.50.0
resolution: "trueblocks-sdk@npm:0.50.0"
dependencies:
typescript: ^4.9.4
checksum: 1633f02b5eb858ccc685add8675c39f50f9e735b1c831151e432c7e224727a0dad0f1348cf6d11648c3ab72e618a768aeaf2eba4257de8319c270ac6c8b21618
checksum: e8adf0c915eb65e76567dc9cd13b45dc4cd810b90f0cc954d20e52af7ac03d408e995834b1df12e1df4e2a343675ac8f03960c9560ab454c13238250578d98db
languageName: node
linkType: hard

Expand Down

0 comments on commit 2021e18

Please sign in to comment.