Fix listing transaction by getting alchemy provider
Co-authored-by: brunoedcf <brest.dallacosta@outlook.com>
This commit is contained in:
		
							parent
							
								
									59538d23d0
								
							
						
					
					
						commit
						242d28f0e3
					
				@ -1,6 +1,6 @@
 | 
			
		||||
import { useEtherStore } from "@/store/ether";
 | 
			
		||||
 | 
			
		||||
import { getProvider } from "./provider";
 | 
			
		||||
import { getContract, getProvider } from "./provider";
 | 
			
		||||
import { getP2PixAddress } from "./addresses";
 | 
			
		||||
 | 
			
		||||
import p2pix from "../utils/smart_contract_files/P2PIX.json";
 | 
			
		||||
@ -14,9 +14,7 @@ const addLock = async (
 | 
			
		||||
): Promise<string> => {
 | 
			
		||||
  const etherStore = useEtherStore();
 | 
			
		||||
 | 
			
		||||
  const provider = getProvider();
 | 
			
		||||
  const signer = provider.getSigner();
 | 
			
		||||
  const p2pContract = new ethers.Contract(getP2PixAddress(), p2pix.abi, signer);
 | 
			
		||||
  const p2pContract = getContract();
 | 
			
		||||
 | 
			
		||||
  const lock = await p2pContract.lock(
 | 
			
		||||
    depositId, // BigNumber
 | 
			
		||||
@ -75,26 +73,22 @@ const releaseLock = async (
 | 
			
		||||
  return release;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const cancelDeposit = async (depositId: BigNumber): Promise<boolean> => {
 | 
			
		||||
  const provider = getProvider();
 | 
			
		||||
const cancelDeposit = async (depositId: BigNumber): Promise<any> => {
 | 
			
		||||
  const contract = getContract();
 | 
			
		||||
 | 
			
		||||
  const signer = provider.getSigner();
 | 
			
		||||
  const contract = new ethers.Contract(getP2PixAddress(), p2pix.abi, signer);
 | 
			
		||||
  await contract.cancelDeposit(depositId);
 | 
			
		||||
  const cancel = await contract.cancelDeposit(depositId);
 | 
			
		||||
  await cancel.wait();
 | 
			
		||||
 | 
			
		||||
  return true;
 | 
			
		||||
  return cancel;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const withdrawDeposit = async (depositId: BigNumber): Promise<boolean> => {
 | 
			
		||||
  const provider = getProvider();
 | 
			
		||||
const withdrawDeposit = async (depositId: BigNumber): Promise<any> => {
 | 
			
		||||
  const contract = getContract();
 | 
			
		||||
 | 
			
		||||
  if (!provider) return false;
 | 
			
		||||
  const withdraw = await contract.withdraw(depositId, []);
 | 
			
		||||
  await withdraw.wait();
 | 
			
		||||
 | 
			
		||||
  const signer = provider.getSigner();
 | 
			
		||||
  const contract = new ethers.Contract(getP2PixAddress(), p2pix.abi, signer);
 | 
			
		||||
  await contract.withdraw(depositId, []);
 | 
			
		||||
 | 
			
		||||
  return true;
 | 
			
		||||
  return withdraw;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export { cancelDeposit, withdrawDeposit, addLock, releaseLock };
 | 
			
		||||
 | 
			
		||||
@ -3,8 +3,7 @@ import { Contract, ethers } from "ethers";
 | 
			
		||||
 | 
			
		||||
import p2pix from "../utils/smart_contract_files/P2PIX.json";
 | 
			
		||||
import { formatEther } from "ethers/lib/utils";
 | 
			
		||||
import { getProvider } from "./provider";
 | 
			
		||||
import { getP2PixAddress } from "./addresses";
 | 
			
		||||
import { getContract } from "./provider";
 | 
			
		||||
import type { ValidDeposit } from "@/model/ValidDeposit";
 | 
			
		||||
 | 
			
		||||
const getNetworksLiquidity = async (): Promise<void> => {
 | 
			
		||||
@ -50,15 +49,14 @@ const getValidDeposits = async (
 | 
			
		||||
  if (contract) {
 | 
			
		||||
    p2pContract = contract;
 | 
			
		||||
  } else {
 | 
			
		||||
    const provider = getProvider();
 | 
			
		||||
    const signer = provider.getSigner();
 | 
			
		||||
 | 
			
		||||
    p2pContract = new ethers.Contract(getP2PixAddress(), p2pix.abi, signer);
 | 
			
		||||
    p2pContract = getContract(true);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  const filterDeposits = p2pContract.filters.DepositAdded(null);
 | 
			
		||||
  const eventsDeposits = await p2pContract.queryFilter(filterDeposits);
 | 
			
		||||
 | 
			
		||||
  p2pContract = getContract(); // get metamask provider contract
 | 
			
		||||
 | 
			
		||||
  const depositList = await Promise.all(
 | 
			
		||||
    eventsDeposits.map(async (deposit) => {
 | 
			
		||||
      const mappedDeposit = await p2pContract.mapDeposits(
 | 
			
		||||
 | 
			
		||||
@ -1,27 +1,36 @@
 | 
			
		||||
import { useEtherStore } from "@/store/ether";
 | 
			
		||||
 | 
			
		||||
import p2pix from "../utils/smart_contract_files/P2PIX.json";
 | 
			
		||||
 | 
			
		||||
import { updateWalletStatus } from "./wallet";
 | 
			
		||||
import {
 | 
			
		||||
  getProviderUrl,
 | 
			
		||||
  isPossibleNetwork,
 | 
			
		||||
  possibleChains,
 | 
			
		||||
  network2Chain,
 | 
			
		||||
  getP2PixAddress,
 | 
			
		||||
} from "./addresses";
 | 
			
		||||
 | 
			
		||||
import { ethers } from "ethers";
 | 
			
		||||
 | 
			
		||||
const getProvider = ():
 | 
			
		||||
  | ethers.providers.Web3Provider
 | 
			
		||||
  | ethers.providers.JsonRpcProvider => {
 | 
			
		||||
const getProvider = (
 | 
			
		||||
  onlyAlchemyProvider: boolean = false
 | 
			
		||||
): ethers.providers.Web3Provider | ethers.providers.JsonRpcProvider => {
 | 
			
		||||
  const window_ = window as any;
 | 
			
		||||
  const connection = window_.ethereum;
 | 
			
		||||
 | 
			
		||||
  if (!connection)
 | 
			
		||||
  if (!connection || onlyAlchemyProvider)
 | 
			
		||||
    return new ethers.providers.JsonRpcProvider(getProviderUrl()); // alchemy provider
 | 
			
		||||
 | 
			
		||||
  return new ethers.providers.Web3Provider(connection); // metamask provider
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const getContract = (onlyAlchemyProvider: boolean = false) => {
 | 
			
		||||
  const provider = getProvider(onlyAlchemyProvider);
 | 
			
		||||
  const signer = provider.getSigner();
 | 
			
		||||
  return new ethers.Contract(getP2PixAddress(), p2pix.abi, signer);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const connectProvider = async (): Promise<void> => {
 | 
			
		||||
  const window_ = window as any;
 | 
			
		||||
  const connection = window_.ethereum;
 | 
			
		||||
@ -79,6 +88,7 @@ const requestNetworkChange = async (network: string): Promise<boolean> => {
 | 
			
		||||
 | 
			
		||||
export {
 | 
			
		||||
  getProvider,
 | 
			
		||||
  getContract,
 | 
			
		||||
  connectProvider,
 | 
			
		||||
  listenToNetworkChange,
 | 
			
		||||
  requestNetworkChange,
 | 
			
		||||
 | 
			
		||||
@ -1,10 +1,9 @@
 | 
			
		||||
import { getProvider } from "./provider";
 | 
			
		||||
import { getContract, getProvider } from "./provider";
 | 
			
		||||
import { getTokenAddress, getP2PixAddress } from "./addresses";
 | 
			
		||||
import { parseEther } from "ethers/lib/utils";
 | 
			
		||||
 | 
			
		||||
import { ethers } from "ethers";
 | 
			
		||||
 | 
			
		||||
import p2pix from "../utils/smart_contract_files/P2PIX.json";
 | 
			
		||||
import mockToken from "../utils/smart_contract_files/MockToken.json";
 | 
			
		||||
 | 
			
		||||
const approveTokens = async (tokenQty: string): Promise<any> => {
 | 
			
		||||
@ -28,10 +27,7 @@ const approveTokens = async (tokenQty: string): Promise<any> => {
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const addDeposit = async (tokenQty: string, pixKey: string): Promise<any> => {
 | 
			
		||||
  const provider = getProvider();
 | 
			
		||||
 | 
			
		||||
  const signer = provider.getSigner();
 | 
			
		||||
  const p2pContract = new ethers.Contract(getP2PixAddress(), p2pix.abi, signer);
 | 
			
		||||
  const p2pContract = getContract();
 | 
			
		||||
 | 
			
		||||
  const deposit = await p2pContract.deposit(
 | 
			
		||||
    getTokenAddress(),
 | 
			
		||||
 | 
			
		||||
@ -1,9 +1,8 @@
 | 
			
		||||
import { useEtherStore } from "@/store/ether";
 | 
			
		||||
 | 
			
		||||
import { getProvider } from "./provider";
 | 
			
		||||
import { getP2PixAddress, getTokenAddress, possibleChains } from "./addresses";
 | 
			
		||||
import { getContract, getProvider } from "./provider";
 | 
			
		||||
import { getTokenAddress, possibleChains } from "./addresses";
 | 
			
		||||
 | 
			
		||||
import p2pix from "../utils/smart_contract_files/P2PIX.json";
 | 
			
		||||
import mockToken from "../utils/smart_contract_files/MockToken.json";
 | 
			
		||||
 | 
			
		||||
import { ethers, type Event } from "ethers";
 | 
			
		||||
@ -52,10 +51,7 @@ const listValidDepositTransactionsByWalletAddress = async (
 | 
			
		||||
const listAllTransactionByWalletAddress = async (
 | 
			
		||||
  walletAddress: string
 | 
			
		||||
): Promise<Event[]> => {
 | 
			
		||||
  const provider = getProvider();
 | 
			
		||||
 | 
			
		||||
  const signer = provider.getSigner();
 | 
			
		||||
  const p2pContract = new ethers.Contract(getP2PixAddress(), p2pix.abi, signer);
 | 
			
		||||
  const p2pContract = getContract();
 | 
			
		||||
 | 
			
		||||
  const filterDeposits = p2pContract.filters.DepositAdded([walletAddress]);
 | 
			
		||||
  const eventsDeposits = await p2pContract.queryFilter(filterDeposits);
 | 
			
		||||
@ -79,10 +75,7 @@ const listAllTransactionByWalletAddress = async (
 | 
			
		||||
const listReleaseTransactionByWalletAddress = async (
 | 
			
		||||
  walletAddress: string
 | 
			
		||||
): Promise<Event[]> => {
 | 
			
		||||
  const provider = getProvider();
 | 
			
		||||
 | 
			
		||||
  const signer = provider.getSigner();
 | 
			
		||||
  const p2pContract = new ethers.Contract(getP2PixAddress(), p2pix.abi, signer);
 | 
			
		||||
  const p2pContract = getContract();
 | 
			
		||||
 | 
			
		||||
  const filterReleasedLocks = p2pContract.filters.LockReleased([walletAddress]);
 | 
			
		||||
  const eventsReleasedLocks = await p2pContract.queryFilter(
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user