1 Commits

Author SHA1 Message Date
Filipe Soccol
c1542707c2 Merge remote-tracking branch 'origin/type-check' into buy-refactor 2025-06-30 08:58:01 -03:00
5 changed files with 24 additions and 17 deletions

View File

@@ -10,7 +10,6 @@ import {
stringToHex, stringToHex,
toBytes, toBytes,
type Address, type Address,
type TransactionReceipt,
} from "viem"; } from "viem";
import type { TokenEnum } from "@/model/NetworkEnum"; import type { TokenEnum } from "@/model/NetworkEnum";
@@ -70,20 +69,24 @@ export const withdrawDeposit = async (
export const releaseLock = async ( export const releaseLock = async (
lockID: bigint, lockID: bigint,
pixTimestamp: `0x${string}`&{lenght:34}, pixtarget: string,
signature: `0x${string}` signature: string
): Promise<TransactionReceipt> => { ): Promise<any> => {
const { address, abi, wallet, client, account } = await getContract(); const { address, abi, wallet, client, account } = await getContract();
console.log("Releasing lock", { lockID, pixtarget, signature });
if (!wallet) { if (!wallet) {
throw new Error("Wallet not connected"); throw new Error("Wallet not connected");
} }
// Convert pixtarget to bytes32
const pixTimestamp = keccak256(stringToHex(pixtarget, { size: 32 }) );
const { request } = await client.simulateContract({ const { request } = await client.simulateContract({
address, address,
abi, abi,
functionName: "release", functionName: "release",
args: [BigInt(lockID), pixTimestamp, signature], args: [BigInt(lockID), pixTimestamp, stringToHex(signature)],
account account
}); });

View File

@@ -32,8 +32,8 @@ const getNetworksLiquidity = async (): Promise<void> => {
}; };
const getParticipantID = async ( const getParticipantID = async (
seller: Address, seller: string,
token: Address token: string
): Promise<string> => { ): Promise<string> => {
const { address, abi, client } = await getContract(); const { address, abi, client } = await getContract();

View File

@@ -18,7 +18,7 @@ const props = defineProps<Props>();
const qrCode = ref<string>(""); const qrCode = ref<string>("");
const qrCodeSvg = ref<string>(""); const qrCodeSvg = ref<string>("");
const showWarnModal = ref<boolean>(true); const showWarnModal = ref<boolean>(true);
const pixTimestamp = ref<string>(""); const pixTarget = ref<string>("");
const releaseSignature = ref<string>(""); const releaseSignature = ref<string>("");
const solicitationData = ref<any>(null); const solicitationData = ref<any>(null);
const pollingInterval = ref<NodeJS.Timeout | null>(null); const pollingInterval = ref<NodeJS.Timeout | null>(null);
@@ -56,7 +56,7 @@ const checkSolicitationStatus = async () => {
); );
if (response.signature) { if (response.signature) {
pixTimestamp.value = response.pixTimestamp; pixTarget.value = response.pixTarget;
releaseSignature.value = response.signature; releaseSignature.value = response.signature;
// Stop polling when payment is confirmed // Stop polling when payment is confirmed
if (pollingInterval.value) { if (pollingInterval.value) {
@@ -170,7 +170,7 @@ onUnmounted(() => {
releaseSignature ? 'Enviar para a rede' : 'Validando pagamento...' releaseSignature ? 'Enviar para a rede' : 'Validando pagamento...'
" "
@button-clicked=" @button-clicked="
emit('pixValidated', { pixTimestamp, signature: releaseSignature }) emit('pixValidated', { pixTarget, signature: releaseSignature })
" "
/> />
</div> </div>

View File

@@ -61,15 +61,15 @@ export const createSolicitation = async (offer: Offer) => {
return response.json(); return response.json();
}; };
export const getSolicitation = async (id: bigint): Promise<{pixTimestamp: `0x${string}`, signature: `0x${string}`}> => { export const getSolicitation = async (id: string) => {
const response = await fetch( const response = await fetch(
`${import.meta.env.VITE_APP_API_URL}/release/${id}` `${import.meta.env.VITE_APP_API_URL}/release/${id}`
); );
const obj = await response.json(); const obj: any = await response.json();
return { return {
pixTimestamp: obj.pixTimestamp, pixTarget: obj.pixTarget,
signature: obj.signature, signature: obj.signature,
}; };
}; };

View File

@@ -59,15 +59,19 @@ const confirmBuyClick = async (
} }
}; };
const releaseTransaction = async (params: { const releaseTransaction = async ({
pixTimestamp: `0x${string}`&{lenght:34}, pixTarget,
signature: `0x${string}`, signature,
}: {
pixTarget: string;
signature: string;
}) => { }) => {
flowStep.value = Step.List; flowStep.value = Step.List;
showBuyAlert.value = true; showBuyAlert.value = true;
loadingRelease.value = true; loadingRelease.value = true;
const release = await releaseLock(BigInt(lockID.value), params.pixTimestamp, params.signature); const release = await releaseLock(BigInt(lockID.value), pixTarget, signature);
await release.wait();
await updateWalletStatus(); await updateWalletStatus();
loadingRelease.value = false; loadingRelease.value = false;