Added different types of tokens.
This commit is contained in:
@@ -9,7 +9,7 @@ import {
|
||||
} from "../addresses";
|
||||
|
||||
import { setActivePinia, createPinia } from "pinia";
|
||||
import { NetworkEnum } from "@/model/NetworkEnum";
|
||||
import { NetworkEnum, TokenEnum } from "@/model/NetworkEnum";
|
||||
import { useEtherStore } from "@/store/ether";
|
||||
|
||||
describe("addresses.ts types", () => {
|
||||
@@ -32,7 +32,7 @@ describe("addresses.ts functions", () => {
|
||||
it("getTokenAddress Ethereum", () => {
|
||||
const etherStore = useEtherStore();
|
||||
etherStore.setNetworkName(NetworkEnum.ethereum);
|
||||
expect(getTokenAddress()).toBe(
|
||||
expect(getTokenAddress(TokenEnum.BRZ)).toBe(
|
||||
"0x4A2886EAEc931e04297ed336Cc55c4eb7C75BA00"
|
||||
);
|
||||
});
|
||||
@@ -40,13 +40,13 @@ describe("addresses.ts functions", () => {
|
||||
it("getTokenAddress Polygon", () => {
|
||||
const etherStore = useEtherStore();
|
||||
etherStore.setNetworkName(NetworkEnum.polygon);
|
||||
expect(getTokenAddress()).toBe(
|
||||
expect(getTokenAddress(TokenEnum.BRZ)).toBe(
|
||||
"0xC86042E9F2977C62Da8c9dDF7F9c40fde4796A29"
|
||||
);
|
||||
});
|
||||
|
||||
it("getTokenAddress Default", () => {
|
||||
expect(getTokenAddress()).toBe(
|
||||
expect(getTokenAddress(TokenEnum.BRZ)).toBe(
|
||||
"0x4A2886EAEc931e04297ed336Cc55c4eb7C75BA00"
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1,16 +1,53 @@
|
||||
import { useEtherStore } from "@/store/ether";
|
||||
import { NetworkEnum } from "@/model/NetworkEnum";
|
||||
import { NetworkEnum, TokenEnum } from "@/model/NetworkEnum";
|
||||
|
||||
const getTokenAddress = (network?: NetworkEnum): string => {
|
||||
const ethereumTokens: { [key in TokenEnum]: string } = {
|
||||
BRZ: "0x3eBE67A2C7bdB2081CBd34ba3281E90377462289",
|
||||
BRX: "0x3eBE67A2C7bdB2081CBd34ba3281E90377462289",
|
||||
}
|
||||
|
||||
const polygonTokens: { [key in TokenEnum]: string } = {
|
||||
BRZ: "0xC86042E9F2977C62Da8c9dDF7F9c40fde4796A29",
|
||||
BRX: "0xC86042E9F2977C62Da8c9dDF7F9c40fde4796A29",
|
||||
}
|
||||
|
||||
const rootstockTokens: { [key in TokenEnum]: string } = {
|
||||
BRZ: "0xfE841c74250e57640390f46d914C88d22C51e82e",
|
||||
BRX: "0xfE841c74250e57640390f46d914C88d22C51e82e",
|
||||
}
|
||||
|
||||
export const getTokenByAddress = (address: string) => {
|
||||
for (const token of Object.keys(ethereumTokens)) {
|
||||
if (address === ethereumTokens[token as TokenEnum]) {
|
||||
return token as TokenEnum;
|
||||
}
|
||||
}
|
||||
|
||||
for (const token of Object.keys(polygonTokens)) {
|
||||
if (address === ethereumTokens[token as TokenEnum]) {
|
||||
return token as TokenEnum;
|
||||
}
|
||||
}
|
||||
|
||||
for (const token of Object.keys(rootstockTokens)) {
|
||||
if (address === ethereumTokens[token as TokenEnum]) {
|
||||
return token as TokenEnum;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
const getTokenAddress = (token: TokenEnum, network?: NetworkEnum): string => {
|
||||
const etherStore = useEtherStore();
|
||||
|
||||
const possibleTokenAddresses: { [key: string]: string } = {
|
||||
Ethereum: "0x3eBE67A2C7bdB2081CBd34ba3281E90377462289",
|
||||
Polygon: "0xC86042E9F2977C62Da8c9dDF7F9c40fde4796A29",
|
||||
Rootstock: "0xfE841c74250e57640390f46d914C88d22C51e82e",
|
||||
const possibleTokenAddresses: { [key: string]: { [key in TokenEnum]: string } } = {
|
||||
Ethereum: ethereumTokens,
|
||||
Polygon: polygonTokens,
|
||||
Rootstock: rootstockTokens,
|
||||
};
|
||||
|
||||
return possibleTokenAddresses[network ? network : etherStore.networkName];
|
||||
return possibleTokenAddresses[network ? network : etherStore.networkName][token];
|
||||
};
|
||||
|
||||
const getP2PixAddress = (network?: NetworkEnum): string => {
|
||||
@@ -27,7 +64,6 @@ const getP2PixAddress = (network?: NetworkEnum): string => {
|
||||
|
||||
const getProviderUrl = (): string => {
|
||||
const etherStore = useEtherStore();
|
||||
|
||||
const possibleProvidersUrls: { [key: string]: string } = {
|
||||
Ethereum: import.meta.env.VITE_SEPOLIA_API_URL,
|
||||
Polygon: import.meta.env.VITE_MUMBAI_API_URL,
|
||||
|
||||
@@ -7,6 +7,7 @@ import p2pix from "@/utils/smart_contract_files/P2PIX.json";
|
||||
|
||||
import { BigNumber, ethers } from "ethers";
|
||||
import { parseEther } from "ethers/lib/utils";
|
||||
import type { TokenEnum } from "@/model/NetworkEnum";
|
||||
|
||||
const addLock = async (
|
||||
seller: string,
|
||||
@@ -84,11 +85,11 @@ const cancelDeposit = async (depositId: BigNumber): Promise<any> => {
|
||||
return cancel;
|
||||
};
|
||||
|
||||
const withdrawDeposit = async (amount: string): Promise<any> => {
|
||||
const withdrawDeposit = async (amount: string, token: TokenEnum): Promise<any> => {
|
||||
const contract = getContract();
|
||||
|
||||
const withdraw = await contract.withdraw(
|
||||
getTokenAddress(),
|
||||
getTokenAddress(token),
|
||||
parseEther(String(amount)),
|
||||
[]
|
||||
);
|
||||
|
||||
@@ -12,7 +12,6 @@ import type { Pix } from "@/model/Pix";
|
||||
|
||||
const getNetworksLiquidity = async (): Promise<void> => {
|
||||
const etherStore = useEtherStore();
|
||||
|
||||
const sepoliaProvider = new ethers.providers.JsonRpcProvider(
|
||||
import.meta.env.VITE_SEPOLIA_API_URL,
|
||||
11155111
|
||||
@@ -36,7 +35,6 @@ const getNetworksLiquidity = async (): Promise<void> => {
|
||||
p2pix.abi,
|
||||
mumbaiProvider
|
||||
);
|
||||
|
||||
const p2pContractRootstock = new ethers.Contract(
|
||||
getP2PixAddress(NetworkEnum.rootstock),
|
||||
p2pix.abi,
|
||||
@@ -46,22 +44,20 @@ const getNetworksLiquidity = async (): Promise<void> => {
|
||||
etherStore.setLoadingNetworkLiquidity(true);
|
||||
|
||||
const depositListSepolia = await getValidDeposits(
|
||||
getTokenAddress(NetworkEnum.ethereum),
|
||||
getTokenAddress(etherStore.selectedToken, NetworkEnum.ethereum),
|
||||
p2pContractSepolia
|
||||
);
|
||||
|
||||
const depositListMumbai = await getValidDeposits(
|
||||
getTokenAddress(NetworkEnum.polygon),
|
||||
p2pContractMumbai
|
||||
);
|
||||
|
||||
// const depositListMumbai = await getValidDeposits(
|
||||
// getTokenAddress(etherStore.selectedToken, NetworkEnum.polygon),
|
||||
// p2pContractMumbai
|
||||
// );
|
||||
const depositListRootstock = await getValidDeposits(
|
||||
getTokenAddress(NetworkEnum.rootstock),
|
||||
getTokenAddress(etherStore.selectedToken, NetworkEnum.rootstock),
|
||||
p2pContractRootstock
|
||||
);
|
||||
|
||||
etherStore.setDepositsValidListSepolia(depositListSepolia);
|
||||
etherStore.setDepositsValidListMumbai(depositListMumbai);
|
||||
// etherStore.setDepositsValidListMumbai(depositListMumbai);
|
||||
etherStore.setDepositsValidListRootstock(depositListRootstock);
|
||||
etherStore.setLoadingNetworkLiquidity(false);
|
||||
};
|
||||
|
||||
@@ -5,13 +5,15 @@ import { parseEther } from "ethers/lib/utils";
|
||||
import { ethers } from "ethers";
|
||||
|
||||
import mockToken from "../utils/smart_contract_files/MockToken.json";
|
||||
import { useEtherStore } from "@/store/ether";
|
||||
|
||||
const approveTokens = async (tokenQty: string): Promise<any> => {
|
||||
const provider = getProvider();
|
||||
const signer = provider.getSigner();
|
||||
const etherStore = useEtherStore();
|
||||
|
||||
const tokenContract = new ethers.Contract(
|
||||
getTokenAddress(),
|
||||
getTokenAddress(etherStore.selectedToken),
|
||||
mockToken.abi,
|
||||
signer
|
||||
);
|
||||
@@ -27,9 +29,10 @@ const approveTokens = async (tokenQty: string): Promise<any> => {
|
||||
|
||||
const addDeposit = async (tokenQty: string, pixKey: string): Promise<any> => {
|
||||
const p2pContract = getContract();
|
||||
const etherStore = useEtherStore();
|
||||
|
||||
const deposit = await p2pContract.deposit(
|
||||
getTokenAddress(),
|
||||
getTokenAddress(etherStore.selectedToken),
|
||||
parseEther(tokenQty),
|
||||
pixKey,
|
||||
true,
|
||||
|
||||
@@ -21,14 +21,14 @@ const updateWalletStatus = async (): Promise<void> => {
|
||||
const signer = provider.getSigner();
|
||||
|
||||
const { chainId } = await provider.getNetwork();
|
||||
if(!isPossibleNetwork(chainId.toString())){
|
||||
window.alert("Invalid chain!:"+chainId);
|
||||
if (!isPossibleNetwork(chainId.toString())) {
|
||||
window.alert("Invalid chain!:" + chainId);
|
||||
return;
|
||||
}
|
||||
etherStore.setNetworkName(possibleChains[chainId]);
|
||||
|
||||
const mockTokenContract = new ethers.Contract(
|
||||
getTokenAddress(),
|
||||
getTokenAddress(etherStore.selectedToken),
|
||||
mockToken.abi,
|
||||
signer
|
||||
);
|
||||
@@ -43,7 +43,8 @@ const updateWalletStatus = async (): Promise<void> => {
|
||||
const listValidDepositTransactionsByWalletAddress = async (
|
||||
walletAddress: string
|
||||
): Promise<ValidDeposit[]> => {
|
||||
const walletDeposits = await getValidDeposits(getTokenAddress());
|
||||
const etherStore = useEtherStore();
|
||||
const walletDeposits = await getValidDeposits(getTokenAddress(etherStore.selectedToken));
|
||||
|
||||
if (walletDeposits) {
|
||||
return walletDeposits
|
||||
|
||||
Reference in New Issue
Block a user