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

Commit

Permalink
fix: pool contract calls (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlicanC authored Apr 21, 2022
1 parent 11f3037 commit 695679a
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions client/src/pages/Pool.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import classNames from "classnames";
import { parseUnits } from "ethers/lib/utils";
import { Wallet } from "fuels";
import { inputify, Wallet } from "fuels";
import { useState } from "react";
import { RiCheckFill } from "react-icons/ri";
import { useWallet } from "src/context/WalletContext";
import { SwayswapContractAbi__factory } from "src/types/contracts";
import assets from "src/lib/CoinsMetadata";
import { Coin, CoinInput } from "src/components/CoinInput";
import { Spinner } from "src/components/Spinner";
import { CoinETH } from "src/lib/constants";

const { REACT_APP_CONTRACT_ID } = process.env;

Expand Down Expand Up @@ -77,20 +78,41 @@ export const Pool = () => {
// https://github.com/FuelLabs/swayswap-demo/issues/42
setIsLoading(true);
// Deposit coins from
setStage(1);
await contract.functions.deposit({
assetId: coinFrom.assetId,
amount: parseUnits(fromAmount, 9)
});
{
setStage(1);
const amount = parseUnits(fromAmount, 9);
const coins = await wallet.getCoinsToSpend([[amount, coinFrom.assetId]]);
await contract.functions.deposit({
assetId: coinFrom.assetId,
amount,
transformRequest: async (request) => {
request.addCoins(coins);
return request;
},
});
}
// Deposit coins to
setStage(2);
await contract.functions.deposit({
assetId: coinTo.assetId,
amount: parseUnits(toAmount, 9),
});
{
setStage(2);
const amount = parseUnits(toAmount, 9);
const coins = await wallet.getCoinsToSpend([[amount, coinTo.assetId]]);
await contract.functions.deposit({
assetId: coinTo.assetId,
amount,
transformRequest: async (request) => {
request.addCoins(coins);
return request;
},
});
}
// Create liquidity pool
setStage(3);
await contract.functions.add_liquidity(1, parseUnits(toAmount, 9), 1000);
await contract.functions.add_liquidity(1, parseUnits(toAmount, 9), 1000, {
variableOutputs: 1,
});
// We are done, reset
setStage(0);
setIsLoading(false);
};

return (
Expand Down

0 comments on commit 695679a

Please sign in to comment.