Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
fix: avoid using raw transaction data (#2684)
Browse files Browse the repository at this point in the history
  • Loading branch information
faustbrian committed Aug 18, 2020
1 parent 18aa8eb commit eada866
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 44 deletions.
1 change: 1 addition & 0 deletions src/app/components/Notifications/Notifications.stories.tsx
Expand Up @@ -24,6 +24,7 @@ export const Default = () => {
const transactions = [
{
id: () => "ee4175091d9f4dacf5fed213711c3e0e4cc371e37afa7bce0429d09bcf3ecefe",
blockId: () => "71fd1a494ded5430586f4dd1c79c3ac77bf38120e868c8f8980972b8075d67e9",
type: () => "transfer",
timestamp: () => DateTime.fromUnix(1596213281),
confirmations: () => BigNumber.make(10),
Expand Down
1 change: 1 addition & 0 deletions src/app/components/Notifications/Notifications.test.tsx
Expand Up @@ -22,6 +22,7 @@ const plugins = [
const transactions = [
{
id: () => "ee4175091d9f4dacf5fed213711c3e0e4cc371e37afa7bce0429d09bcf3ecefe",
blockId: () => "71fd1a494ded5430586f4dd1c79c3ac77bf38120e868c8f8980972b8075d67e9",
type: () => "transfer",
timestamp: () => DateTime.fromUnix(1596213281),
confirmations: () => BigNumber.make(10),
Expand Down
4 changes: 4 additions & 0 deletions src/domains/dashboard/data.ts
Expand Up @@ -20,6 +20,7 @@ export const networks = [
export const transactions = [
{
id: () => "ee4175091d9f4dacf5fed213711c3e0e4cc371e37afa7bce0429d09bcf3ecefe",
blockId: () => "71fd1a494ded5430586f4dd1c79c3ac77bf38120e868c8f8980972b8075d67e9",
type: () => "transfer",
timestamp: () => DateTime.fromUnix(1596213281),
confirmations: () => BigNumber.make(10),
Expand Down Expand Up @@ -64,6 +65,7 @@ export const transactions = [
},
{
id: () => "ee4175091d9f4dacf5fed213711c3e0e4cc371e37afa7bce0429d09bcf3ecefe",
blockId: () => "71fd1a494ded5430586f4dd1c79c3ac77bf38120e868c8f8980972b8075d67e9",
type: () => "transfer",
timestamp: () => DateTime.fromUnix(1596213281),
confirmations: () => BigNumber.make(5),
Expand Down Expand Up @@ -108,6 +110,7 @@ export const transactions = [
},
{
id: () => "ee4175091d9f4dacf5fed213711c3e0e4cc371e37afa7bce0429d09bcf3ecefe",
blockId: () => "71fd1a494ded5430586f4dd1c79c3ac77bf38120e868c8f8980972b8075d67e9",
type: () => "vote",
timestamp: () => DateTime.fromUnix(1596213281),
confirmations: () => BigNumber.make(5),
Expand Down Expand Up @@ -152,6 +155,7 @@ export const transactions = [
},
{
id: () => "ee4175091d9f4dacf5fed213711c3e0e4cc371e37afa7bce0429d09bcf3ecefe",
blockId: () => "71fd1a494ded5430586f4dd1c79c3ac77bf38120e868c8f8980972b8075d67e9",
type: () => "delegateRegistration",
timestamp: () => DateTime.fromUnix(1596213281),
confirmations: () => BigNumber.make(5),
Expand Down
34 changes: 2 additions & 32 deletions src/domains/transaction/components/IpfsDetail/IpfsDetail.test.tsx
Expand Up @@ -15,19 +15,7 @@ describe("IpfsDetail", () => {

it("should not render if not open", () => {
const { asFragment, getByTestId } = render(
<IpfsDetail
isOpen={false}
transaction={{
...TransactionFixture,
data: {
asset: {
ipfs: "QmPRqPTEEwx95WNcSsk6YQk7aGW9hoZbTF9zE92dBj9H68",
},
blockId: "as32d1as65d1as3d1as32d1asd51as3d21as3d2as165das",
},
}}
{...extraProps}
/>,
<IpfsDetail isOpen={false} transaction={TransactionFixture} {...extraProps} />,
);

expect(() => getByTestId("modal__inner")).toThrow(/Unable to find an element by/);
Expand All @@ -36,19 +24,7 @@ describe("IpfsDetail", () => {

it("should render a modal", () => {
const { asFragment, getByTestId } = render(
<IpfsDetail
isOpen={true}
transaction={{
...TransactionFixture,
data: {
asset: {
ipfs: "QmPRqPTEEwx95WNcSsk6YQk7aGW9hoZbTF9zE92dBj9H68",
},
blockId: "as32d1as65d1as3d1as32d1asd51as3d21as3d2as165das",
},
}}
{...extraProps}
/>,
<IpfsDetail isOpen={true} transaction={TransactionFixture} {...extraProps} />,
);

expect(getByTestId("modal__inner")).toHaveTextContent(translations.MODAL_IPFS_DETAIL.TITLE);
Expand All @@ -62,12 +38,6 @@ describe("IpfsDetail", () => {
transaction={{
...TransactionFixture,
confirmations: () => BigNumber.make(52),
data: {
asset: {
ipfs: "QmPRqPTEEwx95WNcSsk6YQk7aGW9hoZbTF9zE92dBj9H68",
},
blockId: "as32d1as65d1as3d1as32d1asd51as3d21as3d2as165das",
},
}}
{...extraProps}
/>,
Expand Down
4 changes: 2 additions & 2 deletions src/domains/transaction/components/IpfsDetail/IpfsDetail.tsx
Expand Up @@ -100,7 +100,7 @@ export const IpfsDetail = (props: IpfsDetailProps) => {
</Circle>
}
>
<div className="flex justify-between">{props.transaction.data.asset.ipfs}</div>
<div className="flex justify-between">{props.transaction.hash()}</div>
</TransactionDetail>

<TransactionDetail label={t("TRANSACTION.TIMESTAMP")}>
Expand All @@ -120,7 +120,7 @@ export const IpfsDetail = (props: IpfsDetailProps) => {
</TransactionDetail>

<TransactionDetail label={t("TRANSACTION.BLOCK_ID")}>
<TruncateMiddle text={props.transaction.data.blockId} className="text-theme-primary-dark" />
<TruncateMiddle text={props.transaction.blockId()} className="text-theme-primary-dark" />

<span className="inline-block ml-4 text-theme-primary-300">
<Icon name="Copy" />
Expand Down
Expand Up @@ -272,7 +272,7 @@ exports[`IpfsDetail should render a modal 1`] = `
class="sc-AxhUy kMyssT text-theme-primary-dark"
data-testid="TruncateMiddle"
>
as32d1…165das
71fd1a…5d67e9
</span>
<span
class="inline-block ml-4 text-theme-primary-300"
Expand Down Expand Up @@ -568,7 +568,7 @@ exports[`IpfsDetail should render as confirmed 1`] = `
class="sc-AxhUy kMyssT text-theme-primary-dark"
data-testid="TruncateMiddle"
>
as32d1…165das
71fd1a…5d67e9
</span>
<span
class="inline-block ml-4 text-theme-primary-300"
Expand Down
Expand Up @@ -142,7 +142,7 @@ exports[`TransactionDetailModal should render a ipfs modal 1`] = `
<div
class="flex justify-between"
>
as32d1as65d1as3d1as32d1asd51as3d21as3d2as165das
QmPRqPTEEwx95WNcSsk6YQk7aGW9hoZbTF9zE92dBj9H68
</div>
</div>
</div>
Expand Down Expand Up @@ -271,7 +271,7 @@ exports[`TransactionDetailModal should render a ipfs modal 1`] = `
class="sc-AxhUy kMyssT text-theme-primary-dark"
data-testid="TruncateMiddle"
>
as32d1…165das
71fd1a…5d67e9
</span>
<span
class="inline-block ml-4 text-theme-primary-300"
Expand Down Expand Up @@ -1624,7 +1624,7 @@ exports[`TransactionDetailModal should render a transfer modal 1`] = `
class="sc-AxhUy kMyssT text-theme-primary-dark"
data-testid="TruncateMiddle"
>
as32d1…165das
71fd1a…5d67e9
</span>
<span
class="inline-block ml-4 text-theme-primary-300"
Expand Down
Expand Up @@ -10,6 +10,7 @@ export default { title: "Domains / Transaction / Components / TransactionTable"
const transactions: Contracts.TransactionDataType[] = [
{
id: () => "ee4175091d9f4dacf5fed213711c3e0e4cc371e37afa7bce0429d09bcf3ecefe",
blockId: () => "71fd1a494ded5430586f4dd1c79c3ac77bf38120e868c8f8980972b8075d67e9",
type: () => "transfer",
timestamp: () => DateTime.fromUnix(1596213281),
confirmations: () => BigNumber.make(10),
Expand Down Expand Up @@ -54,6 +55,7 @@ const transactions: Contracts.TransactionDataType[] = [
},
{
id: () => "ee4175091d9f4dacf5fed213711c3e0e4cc371e37afa7bce0429d09bcf3ecefe",
blockId: () => "71fd1a494ded5430586f4dd1c79c3ac77bf38120e868c8f8980972b8075d67e9",
type: () => "transfer",
timestamp: () => DateTime.fromUnix(1596213281),
confirmations: () => BigNumber.make(5),
Expand Down Expand Up @@ -98,6 +100,7 @@ const transactions: Contracts.TransactionDataType[] = [
},
{
id: () => "ee4175091d9f4dacf5fed213711c3e0e4cc371e37afa7bce0429d09bcf3ecefe",
blockId: () => "71fd1a494ded5430586f4dd1c79c3ac77bf38120e868c8f8980972b8075d67e9",
type: () => "vote",
timestamp: () => DateTime.fromUnix(1596213281),
confirmations: () => BigNumber.make(5),
Expand Down Expand Up @@ -142,6 +145,7 @@ const transactions: Contracts.TransactionDataType[] = [
},
{
id: () => "ee4175091d9f4dacf5fed213711c3e0e4cc371e37afa7bce0429d09bcf3ecefe",
blockId: () => "71fd1a494ded5430586f4dd1c79c3ac77bf38120e868c8f8980972b8075d67e9",
type: () => "delegateRegistration",
timestamp: () => DateTime.fromUnix(1596213281),
confirmations: () => BigNumber.make(5),
Expand Down
Expand Up @@ -9,6 +9,7 @@ import { TransactionTable } from "./TransactionTable";
const transactions: Contracts.TransactionDataType[] = [
{
id: () => "ee4175091d9f4dacf5fed213711c3e0e4cc371e37afa7bce0429d09bcf3ecefe",
blockId: () => "71fd1a494ded5430586f4dd1c79c3ac77bf38120e868c8f8980972b8075d67e9",
type: () => "transfer",
timestamp: () => DateTime.fromUnix(1596213281),
confirmations: () => BigNumber.make(10),
Expand Down Expand Up @@ -53,6 +54,7 @@ const transactions: Contracts.TransactionDataType[] = [
},
{
id: () => "ee4175091d9f4dacf5fed213711c3e0e4cc371e37afa7bce0429d09bcf3ecefe",
blockId: () => "71fd1a494ded5430586f4dd1c79c3ac77bf38120e868c8f8980972b8075d67e9",
type: () => "transfer",
timestamp: () => DateTime.fromUnix(1596213281),
confirmations: () => BigNumber.make(5),
Expand Down
Expand Up @@ -160,7 +160,7 @@ export const TransferDetail = (props: TransferDetailProps) => {
</TransactionDetail>

<TransactionDetail label={t("TRANSACTION.BLOCK_ID")}>
<TruncateMiddle text={props.transaction.data.blockId} className="text-theme-primary-dark" />
<TruncateMiddle text={props.transaction.blockId()} className="text-theme-primary-dark" />

<span className="inline-block ml-4 text-theme-primary-300">
<Icon name="Copy" />
Expand Down
Expand Up @@ -339,7 +339,7 @@ exports[`TransferDetail should render a modal 1`] = `
class="sc-AxgMl fFPQpl text-theme-primary-dark"
data-testid="TruncateMiddle"
>
adsad1…203e12
71fd1a…5d67e9
</span>
<span
class="inline-block ml-4 text-theme-primary-300"
Expand Down Expand Up @@ -702,7 +702,7 @@ exports[`TransferDetail should render as confirmed 1`] = `
class="sc-AxgMl fFPQpl text-theme-primary-dark"
data-testid="TruncateMiddle"
>
adsad1…203e12
71fd1a…5d67e9
</span>
<span
class="inline-block ml-4 text-theme-primary-300"
Expand Down Expand Up @@ -1065,7 +1065,7 @@ exports[`TransferDetail should render as not is sent 1`] = `
class="sc-AxgMl fFPQpl text-theme-primary-dark"
data-testid="TruncateMiddle"
>
adsad1…203e12
71fd1a…5d67e9
</span>
<span
class="inline-block ml-4 text-theme-primary-300"
Expand Down Expand Up @@ -1429,7 +1429,7 @@ exports[`TransferDetail should render with wallet alias 1`] = `
class="sc-AxgMl fFPQpl text-theme-primary-dark"
data-testid="TruncateMiddle"
>
adsad1…203e12
71fd1a…5d67e9
</span>
<span
class="inline-block ml-4 text-theme-primary-300"
Expand Down
4 changes: 4 additions & 0 deletions src/domains/wallet/data.ts
Expand Up @@ -39,6 +39,7 @@ const baseWallet = {
pendingTransactions: [
{
id: () => "ee4175091d9f4dacf5fed213711c3e0e4cc371e37afa7bce0429d09bcf3ecefe",
blockId: () => "71fd1a494ded5430586f4dd1c79c3ac77bf38120e868c8f8980972b8075d67e9",
type: () => "transfer",
timestamp: () => DateTime.fromUnix(1596213281),
confirmations: () => BigNumber.make(10),
Expand Down Expand Up @@ -85,6 +86,7 @@ const baseWallet = {
transactions: [
{
id: () => "ee4175091d9f4dacf5fed213711c3e0e4cc371e37afa7bce0429d09bcf3ecefe",
blockId: () => "71fd1a494ded5430586f4dd1c79c3ac77bf38120e868c8f8980972b8075d67e9",
type: () => "transfer",
timestamp: () => DateTime.fromUnix(1596213281),
confirmations: () => BigNumber.make(10),
Expand Down Expand Up @@ -129,6 +131,7 @@ const baseWallet = {
},
{
id: () => "ee4175091d9f4dacf5fed213711c3e0e4cc371e37afa7bce0429d09bcf3ecefe",
blockId: () => "71fd1a494ded5430586f4dd1c79c3ac77bf38120e868c8f8980972b8075d67e9",
type: () => "transfer",
timestamp: () => DateTime.fromUnix(1596213281),
confirmations: () => BigNumber.make(5),
Expand Down Expand Up @@ -173,6 +176,7 @@ const baseWallet = {
},
{
id: () => "ee4175091d9f4dacf5fed213711c3e0e4cc371e37afa7bce0429d09bcf3ecefe",
blockId: () => "71fd1a494ded5430586f4dd1c79c3ac77bf38120e868c8f8980972b8075d67e9",
type: () => "vote",
timestamp: () => DateTime.fromUnix(1596213281),
confirmations: () => BigNumber.make(5),
Expand Down
3 changes: 3 additions & 0 deletions src/tests/fixtures/transactions/index.ts
Expand Up @@ -4,6 +4,7 @@ import { BigNumber } from "@arkecosystem/platform-sdk-support";

export const TransactionFixture: Contracts.TransactionDataType = {
id: () => "ee4175091d9f4dacf5fed213711c3e0e4cc371e37afa7bce0429d09bcf3ecefe",
blockId: () => "71fd1a494ded5430586f4dd1c79c3ac77bf38120e868c8f8980972b8075d67e9",
type: () => "transfer",
timestamp: () => DateTime.fromUnix(1596213281),
confirmations: () => BigNumber.make(10),
Expand Down Expand Up @@ -45,4 +46,6 @@ export const TransactionFixture: Contracts.TransactionDataType = {
hasFailed: () => false,
getMeta: () => "",
setMeta: () => "",
// IPFS Type
hash: () => "QmPRqPTEEwx95WNcSsk6YQk7aGW9hoZbTF9zE92dBj9H68",
};

0 comments on commit eada866

Please sign in to comment.