fix type errors
This commit is contained in:
@@ -8,7 +8,7 @@ export const addLock = async (
|
||||
tokenAddress: string,
|
||||
amount: number
|
||||
): Promise<string> => {
|
||||
const { address, abi, wallet, client } = await getContract();
|
||||
const { address, abi, wallet, client, account } = await getContract();
|
||||
const parsedAmount = parseEther(amount.toString());
|
||||
|
||||
const { request } = await client.simulateContract({
|
||||
@@ -16,19 +16,31 @@ export const addLock = async (
|
||||
abi,
|
||||
functionName: "lock",
|
||||
args: [sellerAddress, tokenAddress, parsedAmount, [], []],
|
||||
account,
|
||||
});
|
||||
console.log(wallet);
|
||||
if (!wallet) {
|
||||
throw new Error("Wallet is undefined");
|
||||
}
|
||||
const hash = await wallet.writeContract(request);
|
||||
const receipt = await client.waitForTransactionReceipt({ hash });
|
||||
|
||||
return receipt.status ? receipt.logs[0].topics[2] : "";
|
||||
if (!receipt.status)
|
||||
throw new Error("Transaction failed: " + receipt.transactionHash);
|
||||
|
||||
const topic = receipt.logs[0]?.topics[2];
|
||||
if (!topic) {
|
||||
throw new Error("Topic is undefined");
|
||||
}
|
||||
|
||||
return topic;
|
||||
};
|
||||
|
||||
export const withdrawDeposit = async (
|
||||
amount: string,
|
||||
token: TokenEnum
|
||||
): Promise<boolean> => {
|
||||
const { address, abi, wallet, client } = await getContract();
|
||||
const { address, abi, wallet, client, account } = await getContract();
|
||||
|
||||
const tokenAddress = getTokenAddress(token);
|
||||
|
||||
@@ -37,24 +49,38 @@ export const withdrawDeposit = async (
|
||||
abi,
|
||||
functionName: "withdraw",
|
||||
args: [tokenAddress, parseEther(amount), []],
|
||||
account
|
||||
});
|
||||
|
||||
if (!wallet) {
|
||||
throw new Error("Wallet is undefined");
|
||||
}
|
||||
|
||||
const hash = await wallet.writeContract(request);
|
||||
const receipt = await client.waitForTransactionReceipt({ hash });
|
||||
|
||||
return receipt.status;
|
||||
if ( receipt.status == "success"){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
export const releaseLock = async (solicitation: any): Promise<any> => {
|
||||
const { address, abi, wallet, client } = await getContract();
|
||||
const { address, abi, wallet, client, account } = await getContract();
|
||||
|
||||
const { request } = await client.simulateContract({
|
||||
address,
|
||||
abi,
|
||||
functionName: "release",
|
||||
args: [solicitation.lockId, solicitation.e2eId],
|
||||
account
|
||||
});
|
||||
|
||||
if (!wallet) {
|
||||
throw new Error("Wallet is undefined");
|
||||
}
|
||||
|
||||
const hash = await wallet.writeContract(request);
|
||||
return client.waitForTransactionReceipt({ hash });
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user