Refactored variable names to be concise.
This commit is contained in:
parent
cf61f5ecfd
commit
81c8b04c7a
@ -29,10 +29,13 @@ const getNetworksLiquidity = async (): Promise<void> => {
|
||||
user.setLoadingNetworkLiquidity(false);
|
||||
};
|
||||
|
||||
const getPixKey = async (seller: string, token: string): Promise<string> => {
|
||||
const getParticipantID = async (
|
||||
seller: string,
|
||||
token: string
|
||||
): Promise<string> => {
|
||||
const { address, abi, client } = await getContract();
|
||||
|
||||
const pixKeyHex = await client.readContract({
|
||||
const participantIDHex = await client.readContract({
|
||||
address: address as `0x${string}`,
|
||||
abi,
|
||||
functionName: "getPixTarget",
|
||||
@ -41,8 +44,10 @@ const getPixKey = async (seller: string, token: string): Promise<string> => {
|
||||
|
||||
// Remove '0x' prefix and convert hex to UTF-8 string
|
||||
const hexString =
|
||||
typeof pixKeyHex === "string" ? pixKeyHex : toHex(pixKeyHex as bigint);
|
||||
if (!hexString) throw new Error("PixKey not found");
|
||||
typeof participantIDHex === "string"
|
||||
? participantIDHex
|
||||
: toHex(participantIDHex as bigint);
|
||||
if (!hexString) throw new Error("Participant ID not found");
|
||||
const bytes = new Uint8Array(
|
||||
hexString
|
||||
.slice(2)
|
||||
@ -133,7 +138,7 @@ const getValidDeposits = async (
|
||||
remaining: Number(formatEther(mappedBalance.result as bigint)),
|
||||
seller: seller,
|
||||
network,
|
||||
pixKey: "",
|
||||
participantID: "",
|
||||
};
|
||||
depositList[seller + token] = validDeposit;
|
||||
}
|
||||
@ -177,5 +182,5 @@ export {
|
||||
getValidDeposits,
|
||||
getNetworksLiquidity,
|
||||
getUnreleasedLockById,
|
||||
getPixKey,
|
||||
getParticipantID,
|
||||
};
|
||||
|
@ -38,7 +38,7 @@ const selectedDeposits = ref<ValidDeposit[]>();
|
||||
|
||||
import ChevronDown from "@/assets/chevronDown.svg";
|
||||
import { useOnboard } from "@web3-onboard/vue";
|
||||
import { getPixKey } from "@/blockchain/events";
|
||||
import { getParticipantID } from "@/blockchain/events";
|
||||
|
||||
// Emits
|
||||
const emit = defineEmits(["tokenBuy"]);
|
||||
@ -54,7 +54,7 @@ const emitConfirmButton = async (): Promise<void> => {
|
||||
(d) => d.network === Number(networkName.value)
|
||||
);
|
||||
if (!deposit) return;
|
||||
deposit.pixKey = await getPixKey(deposit.seller, deposit.token);
|
||||
deposit.participantID = await getParticipantID(deposit.seller, deposit.token);
|
||||
emit("tokenBuy", deposit, tokenValue.value);
|
||||
};
|
||||
|
||||
|
@ -5,7 +5,7 @@ export type ValidDeposit = {
|
||||
blockNumber: number;
|
||||
remaining: number;
|
||||
seller: string;
|
||||
pixKey: string;
|
||||
participantID: string;
|
||||
network: NetworkEnum;
|
||||
open?: boolean;
|
||||
};
|
||||
|
@ -7,7 +7,7 @@ export const MockValidDeposits: ValidDeposit[] = [
|
||||
token: "1",
|
||||
remaining: 70,
|
||||
seller: "mockedSellerAddress",
|
||||
pixKey: "123456789",
|
||||
participantID: "123456789",
|
||||
network: NetworkEnum.sepolia,
|
||||
},
|
||||
{
|
||||
@ -15,7 +15,7 @@ export const MockValidDeposits: ValidDeposit[] = [
|
||||
token: "2",
|
||||
remaining: 200,
|
||||
seller: "mockedSellerAddress",
|
||||
pixKey: "123456789",
|
||||
participantID: "123456789",
|
||||
network: NetworkEnum.sepolia,
|
||||
},
|
||||
{
|
||||
@ -23,7 +23,7 @@ export const MockValidDeposits: ValidDeposit[] = [
|
||||
token: "3",
|
||||
remaining: 1250,
|
||||
seller: "mockedSellerAddress",
|
||||
pixKey: "123456789",
|
||||
participantID: "123456789",
|
||||
network: NetworkEnum.sepolia,
|
||||
},
|
||||
{
|
||||
@ -31,7 +31,7 @@ export const MockValidDeposits: ValidDeposit[] = [
|
||||
token: "4",
|
||||
remaining: 4000,
|
||||
seller: "mockedSellerAddress",
|
||||
pixKey: "123456789",
|
||||
participantID: "123456789",
|
||||
network: NetworkEnum.sepolia,
|
||||
},
|
||||
{
|
||||
@ -39,7 +39,7 @@ export const MockValidDeposits: ValidDeposit[] = [
|
||||
token: "5",
|
||||
remaining: 2000,
|
||||
seller: "mockedSellerAddress",
|
||||
pixKey: "123456789",
|
||||
participantID: "123456789",
|
||||
network: NetworkEnum.sepolia,
|
||||
},
|
||||
];
|
||||
|
@ -1,5 +1,3 @@
|
||||
import { off } from "process";
|
||||
|
||||
export interface Participant {
|
||||
offer: string;
|
||||
chainID: number;
|
||||
|
@ -25,7 +25,8 @@ user.setSellerView(false);
|
||||
// States
|
||||
const { loadingLock, walletAddress, networkName } = user;
|
||||
const flowStep = ref<Step>(Step.Search);
|
||||
const pixTarget = ref<string>();
|
||||
const participantID = ref<string>();
|
||||
const sellerAddress = ref<`0x${string}` | undefined>();
|
||||
const tokenAmount = ref<number>();
|
||||
const lockID = ref<string>("");
|
||||
const loadingRelease = ref<boolean>(false);
|
||||
@ -37,7 +38,7 @@ const confirmBuyClick = async (
|
||||
selectedDeposit: ValidDeposit,
|
||||
tokenValue: number
|
||||
) => {
|
||||
pixTarget.value = selectedDeposit.pixKey;
|
||||
participantID.value = selectedDeposit.participantID;
|
||||
tokenAmount.value = tokenValue;
|
||||
|
||||
if (selectedDeposit) {
|
||||
@ -78,7 +79,7 @@ const checkForUnreleasedLocks = async (): Promise<void> => {
|
||||
if (lock) {
|
||||
lockID.value = lock.lockID;
|
||||
tokenAmount.value = lock.amount;
|
||||
pixTarget.value = lock.sellerAddress;
|
||||
sellerAddress.value = lock.sellerAddress;
|
||||
showModal.value = true;
|
||||
} else {
|
||||
flowStep.value = Step.Search;
|
||||
@ -91,7 +92,7 @@ if (paramLockID) {
|
||||
if (lockToRedirect) {
|
||||
lockID.value = lockToRedirect.lockID;
|
||||
tokenAmount.value = lockToRedirect.amount;
|
||||
pixTarget.value = lockToRedirect.sellerAddress;
|
||||
sellerAddress.value = lockToRedirect.sellerAddress;
|
||||
flowStep.value = Step.Buy;
|
||||
} else {
|
||||
flowStep.value = Step.Search;
|
||||
@ -134,8 +135,6 @@ onMounted(async () => {
|
||||
/>
|
||||
<div v-if="flowStep == Step.Buy">
|
||||
<QrCodeComponent
|
||||
:sellerId="String(pixTarget)"
|
||||
:amount="tokenAmount || 0"
|
||||
:lockID="lockID"
|
||||
@pix-validated="releaseTransaction"
|
||||
v-if="!loadingLock"
|
||||
|
Loading…
x
Reference in New Issue
Block a user