Skip to content

Commit 07d5679

Browse files
authored
Feat: fix market orders (#140)
1 parent 5e89629 commit 07d5679

File tree

7 files changed

+47
-36
lines changed

7 files changed

+47
-36
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"pnpm": ">=9.7.0"
1616
},
1717
"dependencies": {
18-
"@compolabs/spark-orderbook-ts-sdk": "^1.8.4",
18+
"@compolabs/spark-orderbook-ts-sdk": "^1.8.6",
1919
"@emotion/react": "^11.11.3",
2020
"@emotion/styled": "^11.11.0",
2121
"@fuels/connectors": "^0.9.1",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/blockchain/FuelNetwork.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,14 @@ export class FuelNetwork {
130130
};
131131

132132
withdrawSpotBalance = async (
133-
...params: Parameters<typeof this.orderbookSdk.withdraw>
133+
...params: Parameters<typeof this.orderbookSdk.withdrawAssets>
134134
): Promise<WriteTransactionResponse> => {
135-
return this.orderbookSdk.withdraw(...params);
135+
return this.orderbookSdk.withdrawAssets(...params);
136136
};
137137

138-
withdrawSpotBalanceAll = async (...params: Parameters<typeof this.orderbookSdk.withdrawAll>): Promise<void> => {
139-
await this.orderbookSdk.withdrawAll(...params);
138+
withdrawSpotBalanceAll = async (...params: Parameters<typeof this.orderbookSdk.withdrawAllAssets>): Promise<void> => {
139+
console.log("params", params);
140+
await this.orderbookSdk.withdrawAllAssets(...params);
140141
};
141142

142143
depositSpotBalance = async (

src/screens/Assets/MainAssets/MainAssets.tsx

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,15 @@ const MainAssets = observer(({ setStep }: MainAssets) => {
3636
const bcNetwork = FuelNetwork.getInstance();
3737
const isShowDepositInfo = !settingsStore?.isShowDepositInfo.includes(accountStore.address ?? "");
3838
const balanceList = swapStore.getFormatedContractBalance();
39-
const hasPositiveBalance = balanceList.some((item) => !new BN(item.contractBalance).isZero());
39+
const hasPositiveBalance = balanceList.some((item) => !new BN(item.balance).isZero());
4040
const accumulateBalanceContract = balanceList.reduce((acc, account) => {
4141
const price = BN.formatUnits(oracleStore.getTokenIndexPrice(account.asset.priceFeed), DEFAULT_DECIMALS);
42-
return acc.plus(new BN(account.contractBalance).multipliedBy(price));
42+
return acc.plus(new BN(account.balance).multipliedBy(price));
4343
}, BN.ZERO);
4444

4545
const handleWithdraw = async () => {
46-
const assets = balanceList.map((el) => ({
47-
assetId: el.assetId,
48-
balance: BN.parseUnits(el.contractBalance, el.asset.decimals).toString(),
49-
}));
5046
setIsLoading(true);
51-
await balanceStore.withdrawBalanceAll(assets);
47+
await balanceStore.withdrawBalanceAll();
5248
setIsLoading(false);
5349
};
5450
const closeAssets = () => {
@@ -70,7 +66,7 @@ const MainAssets = observer(({ setStep }: MainAssets) => {
7066
<SmartFlex alignItems="center" justifyContent="space-between" column>
7167
<HeaderBlock alignItems="center" gap="10px" justifyContent="space-between">
7268
<TextTitle type={TEXT_TYPES.TITLE_MODAL} primary>
73-
Deposited Assets
69+
Assets
7470
</TextTitle>
7571
<CloseButton alt="icon close" src={closeThin} onClick={closeAssets} />
7672
</HeaderBlock>
@@ -81,7 +77,7 @@ const MainAssets = observer(({ setStep }: MainAssets) => {
8177
<>
8278
{balanceList.map((el) => (
8379
<AssetItem key={el.assetId}>
84-
<AssetBlock options={{ showBalance: "contractBalance" }} token={el} />
80+
<AssetBlock options={{ showBalance: "balance" }} token={el} />
8581
</AssetItem>
8682
))}
8783
<OverallBlock justifyContent="space-between">
@@ -120,11 +116,21 @@ const MainAssets = observer(({ setStep }: MainAssets) => {
120116
{!hasPositiveBalance && isConnected && (
121117
<DepositedAssets alignItems="center" gap="20px" justifyContent="center" column>
122118
<DepositAssets />
123-
<TextTitleDeposit>Trade fast to trade fast and cheap.</TextTitleDeposit>
119+
<TextTitleDeposit>
120+
It looks like your wallet is empty. Tap the{" "}
121+
<LinkStyled
122+
href="/#/faucet"
123+
onClick={() => {
124+
quickAssetsStore.setQuickAssets(false);
125+
}}
126+
>
127+
faucet
128+
</LinkStyled>{" "}
129+
to grab some tokens.
130+
</TextTitleDeposit>
124131
</DepositedAssets>
125132
)}
126133
<BottomColumn justifyContent="space-between">
127-
{isShowDepositInfo && isConnected && <InfoBlockAssets />}
128134
{!isConnected && (
129135
<SizedBoxStyled width={150}>
130136
<Text type={TEXT_TYPES.BUTTON}>Connect wallet to see your assets and trade</Text>
@@ -137,7 +143,7 @@ const MainAssets = observer(({ setStep }: MainAssets) => {
137143
)}
138144
{accumulateBalanceContract.gt(0) && (
139145
<SmartFlexBlock>
140-
<ButtonConfirm fitContent onClick={() => setStep(2)}>
146+
<ButtonConfirm fitContent onClick={() => setStep(1)}>
141147
Withdraw
142148
</ButtonConfirm>
143149
<ButtonConfirm disabled={isLoading} fitContent onClick={handleWithdraw}>
@@ -223,3 +229,11 @@ const CloseButton = styled.img`
223229
cursor: pointer;
224230
}
225231
`;
232+
233+
const LinkStyled = styled.a`
234+
color: ${({ theme }) => theme.colors.greenLight};
235+
text-decoration: underline;
236+
&:hover {
237+
cursor: pointer;
238+
}
239+
`;

src/screens/Assets/SideManageAssets/SideManageAssets.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const SideManageAssets = observer(() => {
3838
const [isFirstOpen, setIsFirstOpen] = useState(true);
3939
const [isBack, setIsBack] = useState(true);
4040
const setStep = (step: number) => {
41+
console.log("step", step);
4142
setIsBack(step > quickAssetsStore.currentStep);
4243
setIsFirstOpen(false);
4344
setTimeout(() => {

src/screens/Assets/WithdrawAssets/WithdrawAssets.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ import closeThin from "@src/assets/icons/closeThin.svg";
1414
import DataBase from "@src/assets/icons/dataBase.svg?react";
1515
import Spinner from "@src/assets/icons/spinner.svg?react";
1616
import WalletIcon from "@src/assets/icons/wallet.svg?react";
17-
import { FuelNetwork } from "@src/blockchain";
1817
import { DEFAULT_DECIMALS } from "@src/constants";
1918
import BN from "@src/utils/BN";
20-
import { CONFIG } from "@src/utils/getConfig";
2119
import { useStores } from "@stores";
2220

2321
interface WithdrawAssets {
@@ -38,7 +36,6 @@ const WithdrawAssets = observer(({ setStep }: WithdrawAssets) => {
3836
const [amount, setAmount] = useState(BN.ZERO);
3937
const [isLoading, setIsLoading] = useState(false);
4038
const { quickAssetsStore, balanceStore, swapStore } = useStores();
41-
const bcNetwork = FuelNetwork.getInstance();
4239
const closeAssets = () => {
4340
quickAssetsStore.setCurrentStep(0);
4441
quickAssetsStore.setQuickAssets(false);

src/stores/BalanceStore.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ export class BalanceStore {
182182

183183
withdrawBalance = async (assetId: string, amount: string) => {
184184
const { notificationStore } = this.rootStore;
185+
const markets = CONFIG.APP.markets
186+
.filter((el) => el.baseAssetId === assetId || el.quoteAssetId === assetId)
187+
.map((el) => el.contractId);
188+
185189
const bcNetwork = FuelNetwork.getInstance();
186190

187191
const token = bcNetwork.getTokenByAssetId(assetId);
@@ -192,10 +196,10 @@ export class BalanceStore {
192196
});
193197
}
194198
const { type } = this.getContractBalanceInfo(assetId);
195-
const amountFormatted = BN.formatUnits(amount, token.decimals).toSignificant(2);
199+
const amountFormatted = amount;
196200

197201
try {
198-
const tx = await bcNetwork?.withdrawSpotBalance(amount, type);
202+
const tx = await bcNetwork?.withdrawSpotBalance(type, markets, amountFormatted);
199203
notificationStore.success({
200204
text: getActionMessage(ACTION_MESSAGE_TYPE.WITHDRAWING_TOKENS)(amountFormatted, token.symbol),
201205
hash: tx.transactionId,
@@ -211,21 +215,15 @@ export class BalanceStore {
211215
}
212216
};
213217

214-
withdrawBalanceAll = async (withdrawAssets: any) => {
218+
withdrawBalanceAll = async () => {
215219
const { notificationStore } = this.rootStore;
216220
const bcNetwork = FuelNetwork.getInstance();
217221
if (bcNetwork?.getIsExternalWallet()) {
218222
notificationStore.info({ text: "Please, confirm operation in your wallet" });
219223
}
220-
const amountFormatted = withdrawAssets.map((el: { assetId: string; balance: number }) => {
221-
const { type } = this.getContractBalanceInfo(el.assetId);
222-
return {
223-
amount: el.balance,
224-
assetType: type,
225-
};
226-
});
224+
const markets = CONFIG.APP.markets.map((el) => el.contractId);
227225
try {
228-
await bcNetwork?.withdrawSpotBalanceAll(amountFormatted);
226+
await bcNetwork?.withdrawSpotBalanceAll(markets);
229227
notificationStore.success({
230228
text: getActionMessage(ACTION_MESSAGE_TYPE.WITHDRAWING_ALL_TOKENS)(),
231229
hash: "",

0 commit comments

Comments
 (0)