Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

Commit

Permalink
Fix date
Browse files Browse the repository at this point in the history
  • Loading branch information
shelegdmitriy committed Jul 20, 2022
1 parent 061d0d0 commit e826be7
Show file tree
Hide file tree
Showing 13 changed files with 160 additions and 1,360 deletions.
21 changes: 3 additions & 18 deletions backend/src/database/databases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,9 @@ export const indexerDatabase = getKysely<Indexer.ModelTypeMap>(
config.db.readOnlyIndexer
);

export const indexerActivityDatabase = getKysely<{
balance_changes: {
block_timestamp: string;
receipt_id: string | null;
transaction_hash: string | null;
affected_account_id: string;
involved_account_id: string | null;
direction: "INBOUND" | "OUTBOUND";
cause: "VALIDATORS_REWARD" | "TRANSACTION" | "CONTRACT_REWARD" | "RECEIPT";
status: "FAILURE" | "SUCCESS";
delta_nonstaked_amount: string;
absolute_nonstaked_amount: string;
delta_staked_amount: string;
absolute_staked_amount: string;
shard_id: number;
index_in_chunk: number;
};
}>(config.db.readOnlyIndexerActivity);
export const indexerActivityDatabase = getKysely<any>(
config.db.readOnlyIndexerActivity
);

export const analyticsDatabase = getKysely<Analytics.ModelTypeMap>(
config.db.readOnlyAnalytics
Expand Down
2 changes: 1 addition & 1 deletion backend/src/router/transaction/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export const router = trpc
.selectFrom("transactions")
.select([
"signer_account_id as signerId",
(eb) => div(eb, "blocks.block_timestamp", 1000 * 1000, "timestamp"),
(eb) => div(eb, "block_timestamp", 1000 * 1000, "timestamp"),
])
.where("transaction_hash", "=", hash)
.executeTakeFirst();
Expand Down
31 changes: 22 additions & 9 deletions frontend/src/components/beta/transactions/InspectReceipt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { styled } from "../../../libraries/styles";
import * as BI from "../../../libraries/bigint";
import { trpc } from "../../../libraries/trpc";

import { Action, TransactionReceipt } from "../../../types/common";
import { Action, RPC, TransactionReceipt } from "../../../types/common";
import { NearAmount } from "../../utils/NearAmount";
import Gas from "../../utils/Gas";
import AccountLink from "../common/AccountLink";
Expand Down Expand Up @@ -41,6 +41,22 @@ const getDeposit = (actions: Action[]): JSBI => {
)
.reduce((accumulator, deposit) => JSBI.add(accumulator, deposit), BI.zero);
};
const getGasAttached = (actions: Action[]): JSBI => {
const gasAttached = actions
.map((action) => action.args)
.filter(
(args): args is RPC.FunctionCallActionView["FunctionCall"] =>
"gas" in args
);
if (gasAttached.length === 0) {
return BI.zero;
}
return gasAttached.reduce(
(accumulator, args) =>
JSBI.add(accumulator, JSBI.BigInt(args.gas.toString())),
BI.zero
);
};

const InspectReceipt: React.FC<Props> = React.memo(
({ receipt: { id, ...receipt } }) => {
Expand All @@ -53,10 +69,11 @@ const InspectReceipt: React.FC<Props> = React.memo(
{ accountId: receipt.receiverId, receiptId: id },
]);

const gasAttached = getGasAttached(receipt.actions);
const refund =
receipt.outcome.nestedReceipts
.filter((receipt) => receipt.predecessorId === "system")
?.reduce(
.reduce(
(acc, receipt) => JSBI.add(acc, getDeposit(receipt.actions)),
BI.zero
)
Expand Down Expand Up @@ -92,17 +109,13 @@ const InspectReceipt: React.FC<Props> = React.memo(
<tr>
<TableElement>Attached Gas</TableElement>
<TableElement>
{receipt.actions[0].kind === "functionCall" ? (
<Gas gas={JSBI.BigInt(receipt.actions[0].args.gas)} />
) : (
"-"
)}
<Gas gas={gasAttached} />
</TableElement>
</tr>
<tr>
<TableElement>Gas Burned</TableElement>
<TableElement>
<Gas gas={JSBI.BigInt(receipt.outcome.gasBurnt || 0)} />
<Gas gas={JSBI.BigInt(receipt.outcome.gasBurnt)} />
</TableElement>
</tr>
<tr>
Expand All @@ -117,7 +130,7 @@ const InspectReceipt: React.FC<Props> = React.memo(
<tr>
<TableElement>Refunded</TableElement>
<TableElement>
{refund ? <NearAmount amount={refund} decimalPlaces={2} /> : "0"}
<NearAmount amount={refund} decimalPlaces={2} />
</TableElement>
</tr>
<tr>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from "react";
import { useTranslation } from "react-i18next";
import { styled } from "../../../libraries/styles";
import Moment from "../../../libraries/moment";
import { useFormatDistance } from "../../../hooks/use-format-distance";

import { Transaction } from "../../../types/common";

Expand Down Expand Up @@ -72,13 +72,13 @@ const TransactionActionsList: React.FC<Props> = React.memo(
[setExpandAll]
);
const { t } = useTranslation();
const formatDistance = useFormatDistance();

const start = Moment(timestamp);
const end = Moment(
const pending = formatDistance(
timestamp,
receipt.outcome.nestedReceipts[receipt.outcome.nestedReceipts.length - 1]
?.outcome.block.timestamp
);
const pending = end.from(start, true);

return (
<Container>
Expand All @@ -93,13 +93,14 @@ const TransactionActionsList: React.FC<Props> = React.memo(
</span>
</div>
<Expand onClick={expandAllReceipts}>
Expand All
{t("pages.transaction.expand_all")}
<span>+</span>
</Expand>
</TitleWrapper>
<TransactionReceipt
receipt={receipt}
fellowOutgoingReceipts={[]}
className=""
convertionReceipt={true}
expandAll={expandAll}
/>
Expand Down
67 changes: 43 additions & 24 deletions frontend/src/components/beta/transactions/TransactionReceipt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type Props = {
receipt: TransactionReceipt;
convertionReceipt: boolean;
fellowOutgoingReceipts: TransactionReceipt[];
className: string;
customCss?: React.CSSProperties;
expandAll: boolean;
};
Expand All @@ -23,6 +24,14 @@ const Author = styled("div", {
position: "relative",
});

const Predecessor = styled(Author, {
marginBottom: 10,
});

const Receiver = styled(Author, {
marginTop: 10,
});

const ActionItems = styled("div", {
display: "flex",
flexDirection: "column",
Expand Down Expand Up @@ -53,6 +62,26 @@ const ReceiptWrapper = styled("div", {
},
},
},

"&.lastFellowReceipt": {
paddingBottom: 20,
marginTop: 0,
},

"&.lastNonRefundReceipt": {
borderLeftColor: "transparent",
paddingLeft: 0,
},

variants: {
convertionReceipt: {
true: {
paddingLeft: 0,
borderLeftColor: "transparent",
marginTop: 0,
},
},
},
});

const Avatar = styled("div", {
Expand All @@ -73,7 +102,7 @@ const TransactionReceiptView: React.FC<Props> = React.memo(
receipt,
convertionReceipt,
fellowOutgoingReceipts,
customCss,
className,
expandAll,
}) => {
const [isTxTypeActive, setTxTypeActive] = React.useState(false);
Expand All @@ -84,40 +113,33 @@ const TransactionReceiptView: React.FC<Props> = React.memo(

React.useEffect(() => switchActiveTxType, [expandAll]);

const remainingFellowOutgoingReceipts = [...fellowOutgoingReceipts];
const lastFellowOutgoingReceipt = remainingFellowOutgoingReceipts.pop();
const nonRefundNestedReceipts = receipt.outcome.nestedReceipts.filter(
const remainingFellowOutgoingReceipts = fellowOutgoingReceipts.slice(0, -1);
const lastFellowOutgoingReceipt = fellowOutgoingReceipts.at(-1);
const filterRefundNestedReceipts = receipt.outcome.nestedReceipts.filter(
(receipt) => receipt.predecessorId !== "system"
);
const lastNonRefundNestedReceipt = nonRefundNestedReceipts.pop();
const nonRefundNestedReceipts = filterRefundNestedReceipts.slice(0, -1);
const lastNonRefundNestedReceipt = filterRefundNestedReceipts.at(-1);

return (
<>
<ReceiptWrapper
style={
convertionReceipt
? {
paddingLeft: 0,
borderLeftColor: "transparent",
marginTop: 0,
}
: {}
}
css={{ ...customCss }}
convertionReceipt={convertionReceipt}
className={className}
>
{convertionReceipt ? (
<Author css={{ marginBottom: 10 }}>
<Predecessor>
<Avatar />
<span>{receipt.predecessorId}</span>
</Author>
</Predecessor>
) : null}

{lastFellowOutgoingReceipt ? (
<TransactionReceiptView
receipt={lastFellowOutgoingReceipt}
convertionReceipt={false}
fellowOutgoingReceipts={remainingFellowOutgoingReceipts}
customCss={{ paddingBottom: 20, marginTop: 0 }}
className="lastFellowReceipt"
expandAll={expandAll}
/>
) : null}
Expand All @@ -137,20 +159,17 @@ const TransactionReceiptView: React.FC<Props> = React.memo(
</ReceiptInfoWrapper>
) : null}

<Author css={{ marginTop: 10 }}>
<Receiver>
<Avatar />
<span>{receipt.receiverId}</span>
</Author>
</Receiver>
</ReceiptWrapper>
{lastNonRefundNestedReceipt ? (
<TransactionReceiptView
receipt={lastNonRefundNestedReceipt}
convertionReceipt={false}
fellowOutgoingReceipts={nonRefundNestedReceipts}
customCss={{
borderLeftColor: "transparent",
paddingLeft: 0,
}}
className="lastNonRefundReceipt"
expandAll={expandAll}
/>
) : null}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/beta/transactions/[hash].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { NextPage } from "next";
import { Transaction } from "../../../types/common";
import { useAnalyticsTrackOnMount } from "../../../hooks/analytics/use-analytics-track-on-mount";

import { trpc } from "../../../libraries/trpc";
import { styled } from "../../../libraries/styles";
import TransactionHeader from "../../../components/beta/transactions/TransactionHeader";
import TransactionActionsList from "../../../components/beta/transactions/TransactionActionsList";
import { trpc } from "../../../libraries/trpc";
import { styled } from "../../../libraries/styles";

type Props = {
hash: string;
Expand Down
1 change: 1 addition & 0 deletions frontend/src/translations/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
},
"processed": "Processed in ${time}",
"execution_plan": "Execution Plan",
"expand_all": "Expand All",
"tabs": {
"output": "Output",
"inspect": "Inspect"
Expand Down
1 change: 1 addition & 0 deletions frontend/src/translations/ru/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
},
"processed": "Выполнено за ${time}",
"execution_plan": "План выполнения",
"expand_all": "Раскрыть все",
"tabs": {
"output": "Итог",
"inspect": "Обзор"
Expand Down
1 change: 1 addition & 0 deletions frontend/src/translations/ua/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
},
"processed": "Виконано за ${time}",
"execution_plan": "План виконання",
"expand_all": "Розкрити всі",
"tabs": {
"output": "Підсумок",
"inspect": "Огляд"
Expand Down
1 change: 1 addition & 0 deletions frontend/src/translations/vi/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
},
"processed": "Processed in ${time}",
"execution_plan": "Execution Plan",
"expand_all": "Expand All",
"tabs": {
"output": "Output",
"inspect": "Inspect"
Expand Down
1 change: 1 addition & 0 deletions frontend/src/translations/zh-hans/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
},
"processed": "Processed in ${time}",
"execution_plan": "Execution Plan",
"expand_all": "Expand All",
"tabs": {
"output": "Output",
"inspect": "Inspect"
Expand Down
18 changes: 18 additions & 0 deletions frontend/src/translations/zh-hant/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,24 @@
"fetching": "獲取狀態...",
"fail": "失敗",
"success": "成功"
},
"processed": "Processed in ${time}",
"execution_plan": "Execution Plan",
"expand_all": "Expand All",
"tabs": {
"output": "Output",
"inspect": "Inspect"
},
"type": {
"transfer": "Transfer",
"stake": "Restake",
"deployContract": "Contract Deployed",
"addKey": "Access Key Created",
"deleteKey": "Access Key Deleted",
"functionCall": "",
"createAccount": "Account created",
"deleteAccount": "Account removed",
"refund": "Refund"
}
}
},
Expand Down
Loading

0 comments on commit e826be7

Please sign in to comment.