Skip to content

Commit 760a698

Browse files
authored
Merge pull request #396 from compolabs/feat/blockchain-refactor
feat: blockchain refactor
2 parents 6a3ebcc + 20db950 commit 760a698

File tree

65 files changed

+276
-254
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+276
-254
lines changed

.eslintrc.cjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,13 @@ module.exports = {
6060
// Packages. `react` related packages come first.
6161
["^react", "^@?\\w"],
6262
["^@compolabs"],
63+
["^(@blockchain)(/.*|$)"],
6364
["^(@themes|@components)(/.*|$)"],
6465
["^(@assets)(/.*|$)"],
6566
["^(@stores|@hooks)(/.*|$)"],
6667
["^(@screens)(/.*|$)"],
6768
["^(@utils|@constants)(/.*|$)"],
68-
["^(@blockchain|@entity)(/.*|$)"],
69+
["^(@entity)(/.*|$)"],
6970
["^(@src)(/.*|$)"],
7071
["^\\u0000"],
7172
// Parent imports. Put `..` last.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
"last 1 safari version"
108108
]
109109
},
110-
"packageManager": "pnpm@10.6.3+sha512.bb45e34d50a9a76e858a95837301bfb6bd6d35aea2c5d52094fa497a467c43f5c440103ce2511e9e0a2f89c3d6071baac3358fc68ac6fb75e2ceb3d2736065e6",
110+
"packageManager": "pnpm@10.7.0+sha512.6b865ad4b62a1d9842b61d674a393903b871d9244954f652b8842c2b553c72176b278f64c463e52d40fff8aba385c235c8c9ecf5cc7de4fd78b8bb6d49633ab6",
111111
"pnpm": {
112112
"overrides": {}
113113
}

src/blockchain/Blockchain.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Nullable } from "tsdef";
2+
3+
import { FuelNetwork } from "./fuel/FuelNetwork";
4+
5+
export class Blockchain {
6+
private static instance: Nullable<Blockchain> = null;
7+
8+
sdk: FuelNetwork;
9+
10+
private constructor() {
11+
this.sdk = FuelNetwork.getInstance();
12+
}
13+
14+
public static getInstance(): Blockchain {
15+
if (!Blockchain.instance) {
16+
Blockchain.instance = new Blockchain();
17+
}
18+
return Blockchain.instance;
19+
}
20+
}

src/blockchain/FuelNetwork.ts renamed to src/blockchain/fuel/FuelNetwork.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { Account, B256Address } from "fuels";
21
import { makeObservable } from "mobx";
32
import { Nullable } from "tsdef";
43

54
import SparkOrderBookSdk, { BN, OrderType, WriteTransactionResponse } from "@compolabs/spark-orderbook-ts-sdk";
65

6+
import { Account, B256Address } from "@blockchain/fuel/types/fuels";
7+
78
import { CONFIG } from "@utils/getConfig";
89

910
import { Token } from "@entity";

src/blockchain/WalletManager.ts renamed to src/blockchain/fuel/WalletManager.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1-
import { Account, B256Address, Fuel, Provider, Wallet, WalletLocked, WalletUnlocked } from "fuels";
21
import { makeAutoObservable } from "mobx";
32
import { Nullable } from "tsdef";
43

4+
import {
5+
Account,
6+
B256Address,
7+
Fuel,
8+
Provider,
9+
Wallet,
10+
WalletLocked,
11+
WalletUnlocked,
12+
} from "@blockchain/fuel/types/fuels";
13+
514
import { FUEL_CONFIG } from "@constants";
615
import { CONFIG } from "@utils/getConfig";
716

8-
import { NETWORK_ERROR, NetworkError } from "./NetworkError";
17+
import { NETWORK_ERROR, NetworkError } from "../NetworkError";
18+
919
import { Balances } from "./types";
1020

1121
export class WalletManager {

src/blockchain/fuel/types/fuels.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "fuels";

src/blockchain/types/index.ts renamed to src/blockchain/fuel/types/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { BN } from "@compolabs/spark-orderbook-ts-sdk";
22

3+
export * from "@compolabs/spark-orderbook-ts-sdk";
4+
35
export type FetchTradesParams = {
46
limit: number;
57
asset?: string;

src/blockchain/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from "./FuelNetwork";
1+
export * from "./Blockchain";

src/components/CompressedNumber.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useMemo } from "react";
22

3-
import { BN } from "@compolabs/spark-orderbook-ts-sdk";
3+
import { BN } from "@blockchain/fuel/types";
44

55
import { SmartFlex } from "./SmartFlex";
66
import Text from "./Text";

src/components/Modal/AccountInfoSheet.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import React from "react";
22
import styled from "@emotion/styled";
33
import copy from "copy-to-clipboard";
44

5-
import { BN } from "@compolabs/spark-orderbook-ts-sdk";
5+
import { Blockchain } from "@blockchain";
6+
import { BN } from "@blockchain/fuel/types";
67

78
import copyIcon from "@assets/icons/copy.svg";
89
import linkIcon from "@assets/icons/link.svg";
@@ -13,8 +14,6 @@ import { useStores } from "@stores";
1314

1415
import { getExplorerLinkByAddress } from "@utils/getExplorerLink";
1516

16-
import { FuelNetwork } from "@blockchain";
17-
1817
import Divider from "../Divider";
1918
import Sheet from "../Sheet";
2019
import { SmartFlex } from "../SmartFlex";
@@ -29,11 +28,11 @@ const AccountInfoSheet: React.FC<Props> = ({ isOpen, onClose }) => {
2928
const { disconnect } = useWallet();
3029
const { accountStore, notificationStore, balanceStore } = useStores();
3130

32-
const bcNetwork = FuelNetwork.getInstance();
31+
const bcNetwork = Blockchain.getInstance();
3332

3433
const ethBalance = BN.formatUnits(
35-
balanceStore.getWalletBalance(bcNetwork!.getTokenBySymbol("ETH").assetId) ?? BN.ZERO,
36-
bcNetwork?.getTokenBySymbol("ETH").decimals,
34+
balanceStore.getWalletBalance(bcNetwork.sdk.getTokenBySymbol("ETH").assetId) ?? BN.ZERO,
35+
bcNetwork.sdk.getTokenBySymbol("ETH").decimals,
3736
)?.toFormat(4);
3837

3938
const handleAddressCopy = () => {
@@ -80,7 +79,7 @@ const AccountInfoSheet: React.FC<Props> = ({ isOpen, onClose }) => {
8079
<Sheet isOpen={isOpen} header onClose={onClose}>
8180
<SmartFlex column>
8281
<TokenContainer center="y" gap="8px">
83-
<Icon alt="ETH" src={bcNetwork?.getTokenBySymbol("ETH").logo} />
82+
<Icon alt="ETH" src={bcNetwork.sdk.getTokenBySymbol("ETH").logo} />
8483
<Text type="H" primary>{`${ethBalance} ETH`}</Text>
8584
</TokenContainer>
8685
<Divider />

0 commit comments

Comments
 (0)