Skip to content

Commit eee5144

Browse files
committed
chore(txn-table): run biome
1 parent 621888c commit eee5144

File tree

4 files changed

+686
-686
lines changed

4 files changed

+686
-686
lines changed

Diff for: apps/storybook/src/lib/blockscout/api.ts

+60-60
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,85 @@
11
import { Address, Transaction, parseGwei, parseUnits } from "viem";
22
import {
3-
TokenTransfer,
4-
TransactionMeta,
3+
TokenTransfer,
4+
TransactionMeta,
55
} from "../domain/transaction/transaction";
66

77
const ROOT = "https://eth.blockscout.com/api/";
88
export const invokeApi = async (endpoint: string, body?: any) => {
9-
return fetch(endpoint, {
10-
method: "GET",
11-
headers: {
12-
"Content-Type": "application/json",
13-
},
14-
}).then((res) => {
15-
return res.json();
16-
});
9+
return fetch(endpoint, {
10+
method: "GET",
11+
headers: {
12+
"Content-Type": "application/json",
13+
},
14+
}).then((res) => {
15+
return res.json();
16+
});
1717
};
1818

1919
// TODO better pairing types
2020
export enum BlockscoutEndpoint {
21-
Transaction = "transaction",
22-
Address = "address",
21+
Transaction = "transaction",
22+
Address = "address",
2323
}
2424
export interface BlockscoutEndpointParams {
25-
address?: Address;
26-
txnHash?: string;
25+
address?: Address;
26+
txnHash?: string;
2727
}
2828

2929
export const ENDPOINT_STRATEGIES = {
30-
[BlockscoutEndpoint.Address]: (params: BlockscoutEndpointParams) => {
31-
const { address } = params;
32-
return ROOT + "v1/address/" + address;
33-
},
34-
[BlockscoutEndpoint.Transaction]: (params: BlockscoutEndpointParams) => {
35-
const { txnHash } = params;
36-
return ROOT + "v2/transactions/" + txnHash;
37-
},
30+
[BlockscoutEndpoint.Address]: (params: BlockscoutEndpointParams) => {
31+
const { address } = params;
32+
return ROOT + "v1/address/" + address;
33+
},
34+
[BlockscoutEndpoint.Transaction]: (params: BlockscoutEndpointParams) => {
35+
const { txnHash } = params;
36+
return ROOT + "v2/transactions/" + txnHash;
37+
},
3838
};
3939

4040
// TODO enum type
4141
export const getEndpoint = (
42-
endpoint: BlockscoutEndpoint,
43-
params: BlockscoutEndpointParams,
42+
endpoint: BlockscoutEndpoint,
43+
params: BlockscoutEndpointParams,
4444
) => {
45-
const strategy = ENDPOINT_STRATEGIES[endpoint];
46-
if (!strategy) {
47-
throw new Error("");
48-
}
45+
const strategy = ENDPOINT_STRATEGIES[endpoint];
46+
if (!strategy) {
47+
throw new Error("");
48+
}
4949

50-
return strategy(params);
50+
return strategy(params);
5151
};
5252

5353
export const getAddressInfo = async (address: Address) => {
54-
const endpoint = getEndpoint(BlockscoutEndpoint.Address, { address });
55-
return invokeApi(endpoint);
54+
const endpoint = getEndpoint(BlockscoutEndpoint.Address, { address });
55+
return invokeApi(endpoint);
5656
};
5757

5858
export const getTransaction = async (txnHash: string) => {
59-
const endpoint = getEndpoint(BlockscoutEndpoint.Transaction, {
60-
txnHash,
61-
});
62-
return invokeApi(endpoint);
59+
const endpoint = getEndpoint(BlockscoutEndpoint.Transaction, {
60+
txnHash,
61+
});
62+
return invokeApi(endpoint);
6363
};
6464

6565
export const findDisplayedTxType = (transaction_types: any[]): string => {
66-
if (transaction_types.includes("contract_call")) {
67-
return "contract_call";
68-
}
69-
if (transaction_types.includes("coin_transfer")) {
70-
return "coin_transfer";
71-
}
72-
return "native_transfer";
66+
if (transaction_types.includes("contract_call")) {
67+
return "contract_call";
68+
}
69+
if (transaction_types.includes("coin_transfer")) {
70+
return "coin_transfer";
71+
}
72+
return "native_transfer";
7373
};
7474

7575
export const asTokenTransfer = (transfer: any): TokenTransfer => {
76-
const { token } = transfer;
77-
return {
78-
...token,
79-
// imageUrl: '',
80-
name: transfer.token.name,
81-
amount: parseUnits(transfer.total.value, transfer.total.decimals),
82-
};
76+
const { token } = transfer;
77+
return {
78+
...token,
79+
// imageUrl: '',
80+
name: transfer.token.name,
81+
amount: parseUnits(transfer.total.value, transfer.total.decimals),
82+
};
8383
};
8484

8585
/**
@@ -88,15 +88,15 @@ export const asTokenTransfer = (transfer: any): TokenTransfer => {
8888
*
8989
*/
9090
export const asTransactionMeta = (res: any): TransactionMeta => {
91-
return {
92-
hash: res.hash,
93-
blockHash: res.blockHash,
94-
from: res.from.hash as Address,
95-
to: res.to.hash as Address,
96-
isSuccess: res.success,
97-
displayedTxType: findDisplayedTxType(res.tx_types),
98-
value: parseUnits(res.value, res.decimals),
99-
tokenTransfers: res.token_transfers.map(asTokenTransfer),
100-
gas: res.gas_used,
101-
};
91+
return {
92+
hash: res.hash,
93+
blockHash: res.blockHash,
94+
from: res.from.hash as Address,
95+
to: res.to.hash as Address,
96+
isSuccess: res.success,
97+
displayedTxType: findDisplayedTxType(res.tx_types),
98+
value: parseUnits(res.value, res.decimals),
99+
tokenTransfers: res.token_transfers.map(asTokenTransfer),
100+
gas: res.gas_used,
101+
};
102102
};

0 commit comments

Comments
 (0)