Skip to content

Commit 026dcba

Browse files
authored
feat: add TxInput component (#55)
1 parent 86765fa commit 026dcba

36 files changed

+1738
-3083
lines changed

.eslintignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ storybook
1818
**/storybook/**
1919
.turbo
2020
pnpm-lock.yaml
21-
21+
**/**/.*
22+
.*/
23+
packages/app/public/**

.eslintrc.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ const { resolve } = require('path');
22
const { dependencies } = require('./packages/app/package.json');
33

44
const project = [
5-
resolve(__dirname, 'tsconfig.json'),
6-
resolve(__dirname, 'packages/**/tsconfig.json'),
5+
resolve(__dirname, './tsconfig.json'),
6+
resolve(__dirname, './packages/**/tsconfig.json'),
77
];
88

99
module.exports = {
@@ -14,6 +14,7 @@ module.exports = {
1414
'plugin:@fuels/react',
1515
],
1616
parserOptions: {
17+
tsconfigRootDir: __dirname,
1718
project,
1819
},
1920
settings: {

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ public-hoist-pattern[]=*framer-motion*
2929
public-hoist-pattern[]=*@react-aria/interactions*
3030
public-hoist-pattern[]=*eslint*
3131
public-hoist-pattern[]=*prettier*
32+
public-hoist-pattern[]=*ts-node*
3233
public-hoist-pattern[]=@types*

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"@swc/core": "1.3.89",
6464
"@swc/jest": "0.2.29",
6565
"@types/jest": "29.5.5",
66-
"@types/node": "20.6.5",
66+
"@types/node": "20.7.0",
6767
"deepmerge-json": "1.5.0",
6868
"@next/eslint-plugin-next": "^13.5.3",
6969
"@typescript-eslint/eslint-plugin": "^6.7.3",

packages/app/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"ts:check": "tsc --noEmit"
1414
},
1515
"dependencies": {
16+
"@faker-js/faker": "8.1.0",
1617
"@fontsource-variable/inter": "5.0.8",
1718
"@fuel-explorer/graphql": "workspace:*",
1819
"@fuel-ts/math": "0.59.0",
@@ -51,8 +52,8 @@
5152
"@storybook/types": "^7.4.5",
5253
"@testing-library/dom": "9.3.3",
5354
"@testing-library/jest-dom": "6.1.3",
54-
"@types/node": "20.6.5",
55-
"@types/react": "^18.2.22",
55+
"@types/node": "20.7.0",
56+
"@types/react": "^18.2.23",
5657
"@types/react-dom": "^18.2.7",
5758
"@xstate/cli": "^0.5.2",
5859
"autoprefixer": "10.4.16",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { getSdk } from '@fuel-explorer/graphql';
2+
import { GraphQLClient } from 'graphql-request';
3+
4+
const graphql = new GraphQLClient(process.env.GRAPHQL_API!);
5+
export const sdk = getSdk(graphql);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
import { faker } from '@faker-js/faker';
3+
import { GroupInputType, mocks } from '@fuel-explorer/graphql';
4+
import { bn } from '@fuel-ts/math';
5+
import { assets } from '@fuels/assets';
6+
import { dayjs } from '~/systems/Core/utils/dayjs';
7+
8+
const date = dayjs().subtract(1, 'day');
9+
const status = mocks.aSuccessStatus({
10+
__typename: 'SuccessStatus',
11+
block: mocks.aBlock({
12+
transactions: [],
13+
}),
14+
});
15+
16+
const genInput = (typename: any) =>
17+
mocks.anInputCoin({
18+
__typename: typename,
19+
amount: bn(1),
20+
utxoId: faker.string.uuid(),
21+
});
22+
23+
export const GROUPED_INPUT_ASSET = mocks.aGroupedInput({
24+
__typename: 'GroupedInput',
25+
type: GroupInputType.InputCoin,
26+
inputs: [genInput('InputCoin'), genInput('InputCoin'), genInput('InputCoin')],
27+
assetId: assets[0].assetId,
28+
totalAmount: bn(3),
29+
owner: `0x${faker.string.alpha(32)}`,
30+
});
31+
32+
export const GROUPED_INPUT_ASSET_UNKNOWN = mocks.aGroupedInput({
33+
__typename: 'GroupedInput',
34+
type: GroupInputType.InputCoin,
35+
inputs: [genInput('InputCoin'), genInput('InputCoin'), genInput('InputCoin')],
36+
owner: `0x${faker.string.alpha(32)}`,
37+
assetId: `0x${faker.string.alpha(32)}`,
38+
totalAmount: bn(3),
39+
});
40+
41+
export const GROUPED_INPUT_CONTRACT = mocks.aGroupedInput({
42+
__typename: 'GroupedInput',
43+
type: GroupInputType.InputContract,
44+
inputs: [
45+
genInput('InputContract'),
46+
genInput('InputContract'),
47+
genInput('InputContract'),
48+
],
49+
contractId: assets[0].assetId,
50+
totalAmount: bn(3),
51+
});
52+
53+
export const GROUPED_INPUT_MESSAGE = mocks.aGroupedInput({
54+
__typename: 'GroupedInput',
55+
type: GroupInputType.InputMessage,
56+
sender: `0x${faker.string.alpha(40)}`,
57+
recipient: `0x${faker.string.alpha(40)}`,
58+
data: `0x${faker.string.alpha(160)}`,
59+
});
60+
61+
export const TX_MOCK = mocks.aTransaction({
62+
id: '0x78d13f111bf301324f34f2a7eaffc546d39598d156af38e7c4ef9fe61ea2c46a',
63+
time: {
64+
__typename: 'ParsedTime',
65+
fromNow: date.fromNow(),
66+
full: dayjs().format('DD MMM YYYY - HH:mm:ss A'),
67+
},
68+
totalAccounts: 2,
69+
totalAssets: 3,
70+
totalOperations: 4,
71+
gasUsed: bn(1),
72+
status,
73+
groupedInputs: [
74+
GROUPED_INPUT_ASSET,
75+
GROUPED_INPUT_ASSET_UNKNOWN,
76+
GROUPED_INPUT_ASSET,
77+
GROUPED_INPUT_MESSAGE,
78+
],
79+
});

packages/app/src/systems/Transaction/actions/get-last-txs.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
import { z } from 'zod';
44
import { act } from '~/systems/Core/utils/act-server';
5-
import { explorer } from '~/systems/explerer';
5+
import { sdk } from '~/systems/Core/utils/sdk';
66

77
const schema = z.object({
88
last: z.number().default(12).optional(),
99
});
1010

1111
export const getLastTxs = act(schema, async ({ last = 12 }) => {
12-
const { data } = await explorer.getLastTransactions({ last }).catch(() => ({
12+
const { data } = await sdk.getLastTransactions({ last }).catch(() => ({
1313
data: { transactions: { nodes: [] } },
1414
}));
1515
return data.transactions.nodes;

packages/app/src/systems/Transaction/component/TxAccountItem/TxAccountItem.stories.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { bn } from '@fuel-ts/math';
22
import { VStack } from '@fuels/ui';
33
import type { Meta, StoryObj } from '@storybook/react';
44

5+
import { TX_MOCK } from '../../__mocks__/tx';
56
import { TxAccountTypeEnum } from '../../types';
6-
import { TX_MOCK } from '../__mocks__/tx';
77

88
import { TxAccountItem } from './TxAccountItem';
99

packages/app/src/systems/Transaction/component/TxCard/TxCard.stories.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Meta, StoryObj } from '@storybook/react';
22

3-
import { TX_MOCK } from '../__mocks__/tx';
3+
import { TX_MOCK } from '../../__mocks__/tx';
44

55
import { TxCard } from './TxCard';
66

packages/app/src/systems/Transaction/component/TxIcon/TxIcon.stories.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { HStack, VStack } from '@fuels/ui';
22
import type { Meta, StoryObj } from '@storybook/react';
33

44
import type { TxStatus, TxType } from '../../types';
5-
import { TX_STATUS, TX_TYPES } from '../../types';
5+
import { TX_STATUS, TX_ICON_TYPES } from '../../types';
66

77
import { TxIcon } from './TxIcon';
88

@@ -17,7 +17,7 @@ type Story = StoryObj<typeof TxIcon>;
1717
export const Usage: Story = {
1818
render: () => (
1919
<VStack>
20-
{TX_TYPES.map((type) => (
20+
{TX_ICON_TYPES.map((type) => (
2121
<HStack key={type}>
2222
{TX_STATUS.map((status) => (
2323
<TxIcon

packages/app/src/systems/Transaction/component/TxIcon/TxIcon.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
IconCode,
55
IconCoins,
66
IconFlame,
7+
IconMessageCode,
78
IconScript,
89
IconSwitch3,
910
IconTransfer,
@@ -12,16 +13,17 @@ import {
1213
import type { VariantProps } from 'tailwind-variants';
1314
import { tv } from 'tailwind-variants';
1415

15-
import type { TxAccountType, TxStatus, TxType } from '../../types';
16+
import type { TxIconType, TxStatus } from '../../types';
1617

17-
const TX_ICON_MAP: Record<TxType | TxAccountType, IconComponent> = {
18+
const TX_ICON_MAP: Record<TxIconType, IconComponent> = {
1819
ContractCall: IconCode,
1920
Mint: IconCoins,
2021
Transfer: IconTransfer,
2122
Burn: IconFlame,
2223
Contract: IconScript,
2324
Wallet: IconWallet,
2425
Predicate: IconSwitch3,
26+
Message: IconMessageCode,
2527
} as const;
2628

2729
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import type { Meta, StoryObj } from '@storybook/react';
2+
3+
import {
4+
GROUPED_INPUT_ASSET,
5+
GROUPED_INPUT_ASSET_UNKNOWN,
6+
GROUPED_INPUT_CONTRACT,
7+
GROUPED_INPUT_MESSAGE,
8+
} from '../../__mocks__/tx';
9+
10+
import { TxInput } from './TxInput';
11+
12+
const meta: Meta<typeof TxInput> = {
13+
title: 'Transaction/TxInput',
14+
component: TxInput,
15+
};
16+
17+
export default meta;
18+
type Story = StoryObj<typeof TxInput>;
19+
20+
export const Asset: Story = {
21+
render: () => <TxInput className="w-[500px]" input={GROUPED_INPUT_ASSET} />,
22+
};
23+
24+
export const AssetUnknown: Story = {
25+
render: () => (
26+
<TxInput className="w-[500px]" input={GROUPED_INPUT_ASSET_UNKNOWN} />
27+
),
28+
};
29+
30+
export const Contract: Story = {
31+
render: () => (
32+
<TxInput className="w-[500px]" input={GROUPED_INPUT_CONTRACT} />
33+
),
34+
};
35+
36+
export const Message: Story = {
37+
render: () => <TxInput className="w-[500px]" input={GROUPED_INPUT_MESSAGE} />,
38+
};

0 commit comments

Comments
 (0)