From cc16106d92659d01b932642ad6bd734eec55e65d Mon Sep 17 00:00:00 2001 From: Carlos Fontes Date: Mon, 2 Dec 2024 11:50:41 +0000 Subject: [PATCH] chore: fixed issues --- packages/shared/package.json | 2 +- packages/shared/src/utils/payouts.utils.ts | 5 ++--- packages/web/src/contracts/write/ExecutePayout.ts | 8 ++++++-- .../PayoutStatusPage/useCreatePayoutProposal.ts | 8 ++++++-- .../PayoutsTool/PayoutStatusPage/useSignPayout.ts | 8 ++++++-- 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/packages/shared/package.json b/packages/shared/package.json index 6229e2b50..be7ceba1b 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -1,6 +1,6 @@ { "name": "@hats.finance/shared", - "version": "1.1.122", + "version": "1.1.124", "description": "", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/packages/shared/src/utils/payouts.utils.ts b/packages/shared/src/utils/payouts.utils.ts index 9657961c9..8920fb204 100644 --- a/packages/shared/src/utils/payouts.utils.ts +++ b/packages/shared/src/utils/payouts.utils.ts @@ -55,16 +55,15 @@ export const createNewSplitPayoutBeneficiary = (): ISplitPayoutBeneficiary => { }; export const getExecutePayoutSafeTransaction = async ( - signer: Signer, + providerUrl: string, committee: string, payout: IPayoutResponse ): Promise<{ tx: SafeTransaction; txHash: string }> => { const vaultInfo = payout.vaultInfo; const protocolKit = await Safe.init({ - provider: (signer.provider as any)?.provider as never, + provider: providerUrl, safeAddress: committee, - signer: (await signer.getAddress()) as never, }); const percentageToPay = Math.round(Number(payout.payoutData.percentageToPay) * 100); diff --git a/packages/web/src/contracts/write/ExecutePayout.ts b/packages/web/src/contracts/write/ExecutePayout.ts index 3a93fa627..79179e85d 100644 --- a/packages/web/src/contracts/write/ExecutePayout.ts +++ b/packages/web/src/contracts/write/ExecutePayout.ts @@ -5,7 +5,7 @@ import { useState } from "react"; import { useTranslation } from "react-i18next"; import { IVault } from "types"; import { switchNetworkAndValidate } from "utils/switchNetwork.utils"; -import { useNetwork, useSigner } from "wagmi"; +import { useNetwork, useProvider, useSigner } from "wagmi"; export class ExecutePayoutContract { /** @@ -20,6 +20,7 @@ export class ExecutePayoutContract { const { t } = useTranslation(); const { chain } = useNetwork(); const { data: signer } = useSigner(); + const provider = useProvider(); const [data, setData] = useState(); const [isLoading, setIsLoading] = useState(false); @@ -49,8 +50,11 @@ export class ExecutePayoutContract { console.log("Safe SDK done"); console.log("Getting safe TX"); + const providerUrl = provider.chains?.find((c) => c.id === chain?.id)?.rpcUrls.default.http[0]; + if (!providerUrl) return; + const { tx: safeTransaction, txHash: safeTransactionHash } = await getExecutePayoutSafeTransaction( - signer, + providerUrl, vault.committee, payout ); diff --git a/packages/web/src/pages/CommitteeTools/PayoutsTool/PayoutStatusPage/useCreatePayoutProposal.ts b/packages/web/src/pages/CommitteeTools/PayoutsTool/PayoutStatusPage/useCreatePayoutProposal.ts index 818385f22..3449bf9d7 100644 --- a/packages/web/src/pages/CommitteeTools/PayoutsTool/PayoutStatusPage/useCreatePayoutProposal.ts +++ b/packages/web/src/pages/CommitteeTools/PayoutsTool/PayoutStatusPage/useCreatePayoutProposal.ts @@ -3,11 +3,12 @@ import SafeApiKit from "@safe-global/api-kit"; import Safe from "@safe-global/protocol-kit"; import { utils } from "ethers"; import { useState } from "react"; -import { useAccount, useSigner } from "wagmi"; +import { useAccount, useProvider, useSigner } from "wagmi"; export const useCreatePayoutProposal = (vault?: IVault, payout?: IPayoutResponse) => { const { address: account } = useAccount(); const { data: signer } = useSigner(); + const provider = useProvider(); const [isLoading, setIsLoading] = useState(false); @@ -38,7 +39,10 @@ export const useCreatePayoutProposal = (vault?: IVault, payout?: IPayoutResponse const txServiceUrl = getGnosisSafeTxServiceBaseUrl(vault.chainId); const safeService = new SafeApiKit({ txServiceUrl: `${txServiceUrl}/api`, chainId: BigInt(vault.chainId) }); - const { tx: safeTransaction } = await getExecutePayoutSafeTransaction(signer, multisigAddress, payout); + const providerUrl = provider.chains?.find((c) => c.id === vault.chainId)?.rpcUrls.default.http[0]; + if (!providerUrl) return; + + const { tx: safeTransaction } = await getExecutePayoutSafeTransaction(providerUrl, multisigAddress, payout); const safeTxHash = await protocolKit.getTransactionHash(safeTransaction); const senderSignature = await protocolKit.signTypedData(safeTransaction); diff --git a/packages/web/src/pages/CommitteeTools/PayoutsTool/PayoutStatusPage/useSignPayout.ts b/packages/web/src/pages/CommitteeTools/PayoutsTool/PayoutStatusPage/useSignPayout.ts index 9539e5e74..94cbf494c 100644 --- a/packages/web/src/pages/CommitteeTools/PayoutsTool/PayoutStatusPage/useSignPayout.ts +++ b/packages/web/src/pages/CommitteeTools/PayoutsTool/PayoutStatusPage/useSignPayout.ts @@ -2,12 +2,13 @@ import { IPayoutResponse, IVault, getExecutePayoutSafeTransaction } from "@hats. import Safe from "@safe-global/protocol-kit"; import { useState } from "react"; import { switchNetworkAndValidate } from "utils/switchNetwork.utils"; -import { useNetwork, useSignTypedData, useSigner } from "wagmi"; +import { useNetwork, useProvider, useSignTypedData, useSigner } from "wagmi"; export const useSignPayout = (vault?: IVault, payout?: IPayoutResponse) => { const { chain } = useNetwork(); const { data: signer } = useSigner(); const signPayout = useSignTypedData(); + const provider = useProvider(); const [isLoading, setIsLoading] = useState(false); @@ -24,7 +25,10 @@ export const useSignPayout = (vault?: IVault, payout?: IPayoutResponse) => { signer: (await signer.getAddress()) as never, }); - const { tx: safeTransaction } = await getExecutePayoutSafeTransaction(signer, vault.committee, payout); + const providerUrl = provider.chains?.find((c) => c.id === vault.chainId)?.rpcUrls.default.http[0]; + if (!providerUrl) return; + + const { tx: safeTransaction } = await getExecutePayoutSafeTransaction(providerUrl, vault.committee, payout); const signature = await protocolKit.signTypedData(safeTransaction);