Skip to content

Commit

Permalink
feat: Prepare for the second testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
OwshenNetwork committed Jun 8, 2024
1 parent c901e1b commit d725441
Show file tree
Hide file tree
Showing 24 changed files with 193 additions and 180 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Test

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Where am i?
run: |
pwd
ls -la
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ assets:
cp -r rapidsnark/package/bin/prover assets/bin
cp -r contracts/circuits/coin_withdraw_cpp/coin_withdraw assets/bin
cp -r contracts/circuits/coin_withdraw_cpp/coin_withdraw.dat assets/bin
cp -r owshen-genesis.dat assets/bin
cp -r client/build/static assets
cp -r client/build/static assets
cp -r client/build/static assets
Expand Down
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^1.5.1",
"ethers": "^6.8.0",
"ethers": "^6.12.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-loading": "^2.0.3",
Expand Down
1 change: 0 additions & 1 deletion client/src/api/hooks/useSelectNetworkApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const useSelectNetworkApi = () => {
const response = await axios.post(`${coreEndpoint}/set-network`, null, {
params: { chain_id },
});
console.log("Response:", response.data);
setChainId(chain_id);
return response.data;
} catch (error) {
Expand Down
39 changes: 31 additions & 8 deletions client/src/api/hooks/useTransactionModalApi.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { useSelector } from "react-redux";
import { toast } from "react-toastify";
import axios from "axios";
import { coreEndpoint, validateTransaction } from "../../utils/helper";
import {
coreEndpoint,
trueAmount,
validateTransaction,
} from "../../utils/helper";
import {
selectUserAddress,
selectOwshen,
selectNetwork,
selectIsTest,
setReceivedCoins,
selectReceivedCoins,
} from "../../store/containerSlice";
import { ethers, toBigInt } from "ethers";
import { utils } from "web3";
Expand All @@ -17,6 +22,7 @@ import { groth16 } from "snarkjs";

export const useTransactionModalApi = (tokenContract) => {
const address = useSelector(selectUserAddress);
const receivedCoins = useSelector(selectReceivedCoins);
const OwshenWallet = useSelector(selectOwshen);
const network = useSelector(selectNetwork);
const isTest = useSelector(selectIsTest);
Expand Down Expand Up @@ -81,8 +87,9 @@ export const useTransactionModalApi = (tokenContract) => {
const ephemeral = [ex, ey];
const to_wei_token_amount = utils.toWei(Number(tokenAmount), "ether");
try {
if (Number(allowance) < Number(tokenAmount))
if (Number(allowance) < to_wei_token_amount)
await approve(to_wei_token_amount);

const tx = await contract.deposit(
pubKey,
ephemeral,
Expand All @@ -93,8 +100,8 @@ export const useTransactionModalApi = (tokenContract) => {
await tx.wait();
axios.get(`${coreEndpoint}/coins`).then((result) => {
setReceivedCoins(result.data.coins);
setIsOpen(false);
});
setIsOpen(false);
} catch (error) {
toast.error("Error while transferring tokens!");

Expand Down Expand Up @@ -122,7 +129,6 @@ export const useTransactionModalApi = (tokenContract) => {
tokenContract,
tokenAmount,
chainId,
findMatchingCoin,
setIsOpen
) => {
const errorMessage = validateTransaction(
Expand All @@ -136,7 +142,17 @@ export const useTransactionModalApi = (tokenContract) => {
return toast.error(errorMessage);
}

const selectedCoint = findMatchingCoin();
let selectedCoint;
for (let coin of receivedCoins) {
if (
trueAmount(coin.amount, coin.uint_token) > Number(tokenAmount) &&
String(coin.uint_token) === String(tokenContract)
) {
return coin;
} else {
return toast.error("No matching coin is found");
}
}

const options = {
gasLimit: 5000000,
Expand All @@ -154,7 +170,7 @@ export const useTransactionModalApi = (tokenContract) => {
})
.then(async (result) => {
let abi = OwshenWallet.contract_abi;
let reciver_commitment = result.data.receiver_commitment;
let receiver_commitment = result.data.receiver_commitment;
let sender_commitment = result.data.sender_commitment;

let proof =
Expand Down Expand Up @@ -206,7 +222,7 @@ export const useTransactionModalApi = (tokenContract) => {
receiver_ephemeral,
sender_ephemeral,
[result.data.nullifier, utils.toBigInt(0)],
[sender_commitment, reciver_commitment],
[sender_commitment, receiver_commitment],
result.data.obfuscated_receiver_token_address,
result.data.obfuscated_sender_token_address,
result.data.obfuscated_receiver_amount,
Expand All @@ -225,6 +241,7 @@ export const useTransactionModalApi = (tokenContract) => {
}
})
.catch((error) => {
console.log("error ", error);
setIsOpen(false);
return toast.error(`Internal server error: ${error}`);
});
Expand All @@ -245,8 +262,14 @@ export const useTransactionModalApi = (tokenContract) => {
"Your wallet is not connected. Please connect your wallet to proceed."
);
}
if (!tokenAmount || tokenAmount === 0) {
setIsLoading(false);
return toast.error(
"Token amount is not specified. Please enter the amount of tokens you want to withdraw."
);
}

const desireAmount = utils.toWei(Number(tokenAmount), "ether");
console.log("request withdrawal", index, owshen.wallet, desireAmount);
axios
.get(`${coreEndpoint}/withdraw`, {
params: {
Expand Down
28 changes: 6 additions & 22 deletions client/src/components/Main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
selectIsWalletConnected,
selectIsOwshenWalletExist,
} from "../../store/containerSlice";
import SetParamsModal from "../Modal/SetParamsModal";
import { useDispatch, useSelector } from "react-redux";
import { toast } from "react-toastify";
import { Tooltip } from "react-tooltip";
Expand Down Expand Up @@ -42,7 +41,6 @@ const Main = ({ children }) => {
const [isOpen, setIsOpen] = useState(false);
const [isInprogress, setIsInprogress] = useState(false);
const [isOpenWithdraw, setIsOpenWithdraw] = useState(false);
const [isOpenSetParams, setIsOpenSetParams] = useState(false);

const isConnected = useSelector(selectIsWalletConnected);
const defaultChainId = isTest ? 11155111 : null;
Expand Down Expand Up @@ -70,34 +68,21 @@ const Main = ({ children }) => {
if (networkChainId && isChainIdExist(networkChainId)) {
setChainId(networkChainId);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
networkChainId,
OwshenWallet.wallet,
OwshenWallet.contract_address,
isConnected
isConnected,
]);
useEffect(() => {
if (!isOwshenWalletExist) {
navigate("/walletSelection");
}
});
// const setParamsToastContent = (
// <div className="text-center">
// pleas set your params to do transaction
// <button
// className="!bg-white p-2 w-full text-black rounded my-2"
// onClick={() => setIsOpenSetParams(true)}
// >
// open set params
// </button>
// </div>
// );


const canOpenModal = () => {
// return toast.error(setParamsToastContent, {
// closeOnClick: false,
// className: "custom-toast-container",
// });
if (isTest) {
return setIsInprogress(true);
}
Expand Down Expand Up @@ -137,11 +122,10 @@ const Main = ({ children }) => {
isOpen={isOpen}
setIsOpen={setIsOpen}
/>
<SetParamsModal isOpen={isOpenSetParams} setIsOpen={setIsOpenSetParams} />
<InProgress isOpen={isInprogress} setIsOpen={setIsInprogress} />

<div className="mt-10 text-center">
<Tooltip id="copy" place="top" content="Copy wallet address" />
<Tooltip id="copy" place="top" content="Copy to clipboard" />
{OwshenWallet.wallet && (
<button
data-tooltip-id="copy"
Expand All @@ -160,11 +144,11 @@ const Main = ({ children }) => {
<div className="my-8 flex justify-around w-32 mx-auto">
<button onClick={canOpenModal}>
<img src={SendIcon} alt="sendIcon" />
<p>send</p>
<p>Send</p>
</button>
<button onClick={() => setIsInprogress(true)}>
<img src={SwapIcon} alt="swapIcon" />
<p>swap</p>
<p>Swap</p>
</button>
</div>
</div>
Expand Down
10 changes: 1 addition & 9 deletions client/src/components/Modal/InProgress.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import Modal from ".";
import ReactLoading from "react-loading";

const InProgress = ({ isOpen, setIsOpen }) => {
return (
<Modal title="" isOpen={isOpen} setIsOpen={setIsOpen}>
<div className="h-[300px] bg-[url('../pics/inProgress.png')] bg-contain bg-center">
<ReactLoading
className="mx-auto pt-24"
type="spin"
color="#2c21ff99"
height={100}
width={100}
/></div>
<div className="h-[300px] bg-[url('../pics/inProgress.png')] bg-contain bg-center"></div>
</Modal>
);
};
Expand Down
46 changes: 0 additions & 46 deletions client/src/components/Modal/SetParamsModal.js

This file was deleted.

Loading

0 comments on commit d725441

Please sign in to comment.