Release integration with qrcode component and list component
This commit is contained in:
parent
4aec263463
commit
19b307343d
@ -1,14 +1,28 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import CustomButton from "@/components/CustomButton.vue";
|
import CustomButton from "@/components/CustomButton.vue";
|
||||||
import { useEtherStore } from "@/store/ether";
|
import { BigNumber } from "ethers";
|
||||||
import blockchain from "../utils/blockchain";
|
import blockchain from "../utils/blockchain";
|
||||||
|
|
||||||
// props and store references
|
// props and store references
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
lastWalletTransactions: Array,
|
lastWalletTransactions: Array,
|
||||||
tokenAmmount: Number,
|
tokenAmmount: BigNumber,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const teste = (amount: any) => {
|
||||||
|
console.log(amount);
|
||||||
|
console.log("Teste");
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatEventsAmount = (amount: any) => {
|
||||||
|
try {
|
||||||
|
const formated = blockchain.formatBigNumber(amount);
|
||||||
|
return formated;
|
||||||
|
} catch {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const openEtherscanUrl = (url: string) => {
|
const openEtherscanUrl = (url: string) => {
|
||||||
window.open(url, "_blank");
|
window.open(url, "_blank");
|
||||||
};
|
};
|
||||||
@ -28,7 +42,9 @@ const openEtherscanUrl = (url: string) => {
|
|||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
<p>Tokens recebidos</p>
|
<p>Tokens recebidos</p>
|
||||||
<p class="text-2xl text-gray-900">{{ props.tokenAmmount }} BRZ</p>
|
<p class="text-2xl text-gray-900">
|
||||||
|
{{ teste(props.tokenAmmount) }} BRZ
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="my-5">
|
<div class="my-5">
|
||||||
<p>
|
<p>
|
||||||
@ -70,7 +86,7 @@ const openEtherscanUrl = (url: string) => {
|
|||||||
:key="deposit?.blockNumber"
|
:key="deposit?.blockNumber"
|
||||||
>
|
>
|
||||||
<p class="last-deposit-info">
|
<p class="last-deposit-info">
|
||||||
{{ blockchain.formatBigNumber(deposit?.args.amount) }} BRZ
|
{{ formatEventsAmount(deposit?.args.amount) }} BRZ
|
||||||
</p>
|
</p>
|
||||||
<p class="last-deposit-info">
|
<p class="last-deposit-info">
|
||||||
{{
|
{{
|
||||||
|
@ -69,7 +69,7 @@ const validatePix = async () => {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="page">
|
<div class="page">
|
||||||
<h2>{{e2eId}}</h2>
|
<h2>{{ e2eId }}</h2>
|
||||||
<div class="text-container">
|
<div class="text-container">
|
||||||
<span class="text font-extrabold text-2xl max-w-[30rem]">
|
<span class="text font-extrabold text-2xl max-w-[30rem]">
|
||||||
Utilize o QR Code ou copie o código para realizar o Pix
|
Utilize o QR Code ou copie o código para realizar o Pix
|
||||||
@ -147,7 +147,7 @@ const validatePix = async () => {
|
|||||||
<CustomButton
|
<CustomButton
|
||||||
:is-disabled="isPixValid == false"
|
:is-disabled="isPixValid == false"
|
||||||
:text="'Enviar para a rede'"
|
:text="'Enviar para a rede'"
|
||||||
@button-clicked="emit('pixValidated', e2eId)"
|
@button-clicked="emit('pixValidated', { e2eId })"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -196,7 +196,6 @@ const mapDeposits = async (depositId: BigNumber) => {
|
|||||||
const contract = new ethers.Contract(addresses.p2pix, p2pix.abi, signer);
|
const contract = new ethers.Contract(addresses.p2pix, p2pix.abi, signer);
|
||||||
const deposit = await contract.mapDeposits(depositId.toNumber());
|
const deposit = await contract.mapDeposits(depositId.toNumber());
|
||||||
|
|
||||||
console.log(deposit);
|
|
||||||
return deposit;
|
return deposit;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -211,6 +210,7 @@ const addLock = async (depositId: Number, amount: Number) => {
|
|||||||
const p2pContract = new ethers.Contract(addresses.p2pix, p2pix.abi, signer);
|
const p2pContract = new ethers.Contract(addresses.p2pix, p2pix.abi, signer);
|
||||||
|
|
||||||
// Make lock
|
// Make lock
|
||||||
|
const oldEventsLen = etherStore.locksAddedList.length;
|
||||||
const lock = await p2pContract.lock(
|
const lock = await p2pContract.lock(
|
||||||
depositId,
|
depositId,
|
||||||
etherStore.walletAddress,
|
etherStore.walletAddress,
|
||||||
@ -220,8 +220,9 @@ const addLock = async (depositId: Number, amount: Number) => {
|
|||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
lock.wait();
|
lock.wait();
|
||||||
|
while (etherStore.locksAddedList.length === oldEventsLen) {
|
||||||
updateLockAddedEvents();
|
await updateLockAddedEvents();
|
||||||
|
}
|
||||||
return lock;
|
return lock;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -269,9 +270,9 @@ const releaseLock = async (
|
|||||||
|
|
||||||
const release = await p2pContract.release(lockId, e2eId, sig.r, sig.s, sig.v);
|
const release = await p2pContract.release(lockId, e2eId, sig.r, sig.s, sig.v);
|
||||||
release.wait();
|
release.wait();
|
||||||
|
await updateLockReleasedEvents();
|
||||||
|
|
||||||
updateLockReleasedEvents();
|
return release;
|
||||||
return release
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Formatting methods
|
// Formatting methods
|
||||||
@ -296,4 +297,5 @@ export default {
|
|||||||
addLock,
|
addLock,
|
||||||
mapLocks,
|
mapLocks,
|
||||||
releaseLock,
|
releaseLock,
|
||||||
|
updateLockAddedEvents,
|
||||||
};
|
};
|
||||||
|
@ -5,11 +5,7 @@ import ListComponent from "@/components/ListComponent.vue";
|
|||||||
import blockchain from "../utils/blockchain";
|
import blockchain from "../utils/blockchain";
|
||||||
import { ref } from "vue";
|
import { ref } from "vue";
|
||||||
|
|
||||||
// (TO DO) Tirar isso tudo daqui
|
|
||||||
import p2pix from "../utils/smart_contract_files/P2PIX.json";
|
|
||||||
import addresses from "../utils/smart_contract_files/localhost.json";
|
|
||||||
import { useEtherStore } from "@/store/ether";
|
import { useEtherStore } from "@/store/ether";
|
||||||
import { ethers } from "ethers";
|
|
||||||
import QrCodeComponent from "../components/QrCodeComponent.vue";
|
import QrCodeComponent from "../components/QrCodeComponent.vue";
|
||||||
import { storeToRefs } from "pinia";
|
import { storeToRefs } from "pinia";
|
||||||
|
|
||||||
@ -26,6 +22,7 @@ const flowStep = ref<Step>(Step.Search);
|
|||||||
const pixTarget = ref<string>("");
|
const pixTarget = ref<string>("");
|
||||||
const tokenAmount = ref<number>();
|
const tokenAmount = ref<number>();
|
||||||
const lockTransactionHash = ref<string>("");
|
const lockTransactionHash = ref<string>("");
|
||||||
|
const lockId = ref<string>("");
|
||||||
const loadingRelease = ref<Boolean>(false);
|
const loadingRelease = ref<Boolean>(false);
|
||||||
const lastWalletTransactions = ref<any[] | undefined>([]);
|
const lastWalletTransactions = ref<any[] | undefined>([]);
|
||||||
|
|
||||||
@ -45,52 +42,56 @@ const confirmBuyClick = async ({ selectedDeposit, tokenValue }: any) => {
|
|||||||
flowStep.value = Step.Buy;
|
flowStep.value = Step.Buy;
|
||||||
etherStore.setLoadingLock(true);
|
etherStore.setLoadingLock(true);
|
||||||
|
|
||||||
await blockchain.addLock(depositId, tokenValue)
|
await blockchain
|
||||||
.then((lock) => {
|
.addLock(depositId, tokenValue)
|
||||||
console.log(lock)
|
.then((lock) => {
|
||||||
lockTransactionHash.value = lock.hash
|
lockTransactionHash.value = lock.hash;
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
flowStep.value = Step.Search;
|
flowStep.value = Step.Search;
|
||||||
});
|
});
|
||||||
|
|
||||||
// (TO DO) Tirar isso daqui
|
|
||||||
const window_ = window as any;
|
|
||||||
const connection = window_.ethereum;
|
|
||||||
let provider: ethers.providers.Web3Provider | null = null;
|
|
||||||
if (!connection) return;
|
|
||||||
provider = new ethers.providers.Web3Provider(connection);
|
|
||||||
const signer = provider.getSigner();
|
|
||||||
const p2pContract = new ethers.Contract(addresses.p2pix, p2pix.abi, signer);
|
|
||||||
const filterLocks = p2pContract.filters.LockAdded(null);
|
|
||||||
const eventsLocks = await p2pContract.queryFilter(filterLocks);
|
|
||||||
etherStore.setLocksAddedList(eventsLocks);
|
|
||||||
etherStore.setLoadingLock(false);
|
etherStore.setLoadingLock(false);
|
||||||
|
|
||||||
// Data to QRCode
|
|
||||||
// Chave Pix = depositDetail.pixTarget
|
|
||||||
// Valor = tokenValue
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const releaseTransaction = async ({ e2eId }: any) => {
|
const releaseTransaction = async ({ e2eId }: any) => {
|
||||||
console.log(e2eId);
|
|
||||||
flowStep.value = Step.List;
|
flowStep.value = Step.List;
|
||||||
loadingRelease.value = true;
|
loadingRelease.value = true;
|
||||||
console.log(lockTransactionHash.value);
|
|
||||||
console.log(locksAddedList.value);
|
|
||||||
|
|
||||||
// make lock release
|
const findLockId = locksAddedList.value.find((element) => {
|
||||||
// need to find lockId
|
if (element.transactionHash === lockTransactionHash.value) {
|
||||||
// const release = await blockchain.releaseLock(pixTarget.value, String(tokenAmount.value), Number(e2eId), lockTransactionHash.value)
|
lockId.value = element.args.lockID;
|
||||||
// console.log(release);
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
lastWalletTransactions.value =
|
if (findLockId) {
|
||||||
await blockchain.listTransactionByWalletAddress(
|
console.log(
|
||||||
walletAddress.value.toLowerCase()
|
pixTarget.value,
|
||||||
|
String(tokenAmount.value),
|
||||||
|
Number(e2eId),
|
||||||
|
lockId.value
|
||||||
);
|
);
|
||||||
|
|
||||||
loadingRelease.value = false
|
const release = await blockchain.releaseLock(
|
||||||
|
pixTarget.value,
|
||||||
|
String(tokenAmount.value),
|
||||||
|
Number(e2eId),
|
||||||
|
lockId.value
|
||||||
|
);
|
||||||
|
release.wait();
|
||||||
|
|
||||||
|
lastWalletTransactions.value =
|
||||||
|
await blockchain.listTransactionByWalletAddress(
|
||||||
|
walletAddress.value.toLowerCase()
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(tokenAmount);
|
||||||
|
|
||||||
|
loadingRelease.value = false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -112,7 +113,11 @@ const releaseTransaction = async ({ e2eId }: any) => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="flowStep == Step.List">
|
<div v-if="flowStep == Step.List">
|
||||||
<ListComponent v-if="!loadingRelease" :tokenAmount="tokenAmount" :last-wallet-transactions="lastWalletTransactions" />
|
<ListComponent
|
||||||
|
v-if="!loadingRelease"
|
||||||
|
:tokenAmount="tokenAmount"
|
||||||
|
:last-wallet-transactions="lastWalletTransactions"
|
||||||
|
/>
|
||||||
<ValidationComponent
|
<ValidationComponent
|
||||||
v-if="loadingRelease"
|
v-if="loadingRelease"
|
||||||
:message="'A transação está sendo enviada para a rede. Em breve os tokens serão depositados em sua carteira.'"
|
:message="'A transação está sendo enviada para a rede. Em breve os tokens serão depositados em sua carteira.'"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user