Finished refactoring for Sellet flow.
This commit is contained in:
parent
c4dae86b5f
commit
c90f468d3c
@ -5,12 +5,14 @@ import { encodeBytes32String, Contract, parseEther } from "ethers";
|
|||||||
|
|
||||||
import mockToken from "../utils/smart_contract_files/MockToken.json";
|
import mockToken from "../utils/smart_contract_files/MockToken.json";
|
||||||
import { useEtherStore } from "@/store/ether";
|
import { useEtherStore } from "@/store/ether";
|
||||||
|
import { createParticipant, Participant } from "@/utils/bbPay";
|
||||||
|
|
||||||
const approveTokens = async (tokenQty: string): Promise<any> => {
|
const approveTokens = async (participant: Participant): Promise<any> => {
|
||||||
const provider = getProvider();
|
const provider = getProvider();
|
||||||
const signer = await provider?.getSigner();
|
const signer = await provider?.getSigner();
|
||||||
const etherStore = useEtherStore();
|
const etherStore = useEtherStore();
|
||||||
|
|
||||||
|
etherStore.setSeller(participant);
|
||||||
const tokenContract = new Contract(
|
const tokenContract = new Contract(
|
||||||
getTokenAddress(etherStore.selectedToken),
|
getTokenAddress(etherStore.selectedToken),
|
||||||
mockToken.abi,
|
mockToken.abi,
|
||||||
@ -22,11 +24,11 @@ const approveTokens = async (tokenQty: string): Promise<any> => {
|
|||||||
await signer?.getAddress(),
|
await signer?.getAddress(),
|
||||||
getP2PixAddress()
|
getP2PixAddress()
|
||||||
);
|
);
|
||||||
if (approved < parseEther(tokenQty)) {
|
if (approved < parseEther(participant.offer)) {
|
||||||
// Approve tokens
|
// Approve tokens
|
||||||
const apprv = await tokenContract.approve(
|
const apprv = await tokenContract.approve(
|
||||||
getP2PixAddress(),
|
getP2PixAddress(),
|
||||||
parseEther(tokenQty)
|
parseEther(participant.offer)
|
||||||
);
|
);
|
||||||
await apprv.wait();
|
await apprv.wait();
|
||||||
return true;
|
return true;
|
||||||
@ -34,15 +36,18 @@ const approveTokens = async (tokenQty: string): Promise<any> => {
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
const addDeposit = async (tokenQty: string, pixKey: string): Promise<any> => {
|
const addDeposit = async (): Promise<any> => {
|
||||||
const p2pContract = await getContract();
|
const p2pContract = await getContract();
|
||||||
const etherStore = useEtherStore();
|
const etherStore = useEtherStore();
|
||||||
|
|
||||||
|
const sellerId = await createParticipant(etherStore.seller);
|
||||||
|
etherStore.setSellerId(sellerId.id);
|
||||||
|
|
||||||
const deposit = await p2pContract.deposit(
|
const deposit = await p2pContract.deposit(
|
||||||
pixKey,
|
sellerId,
|
||||||
encodeBytes32String(""),
|
encodeBytes32String(""),
|
||||||
getTokenAddress(etherStore.selectedToken),
|
getTokenAddress(etherStore.selectedToken),
|
||||||
parseEther(tokenQty),
|
parseEther(etherStore.seller.offer),
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ const selectedBank = ref<Bank | null>(null);
|
|||||||
|
|
||||||
// Import the bank list
|
// Import the bank list
|
||||||
import bankList from "@/utils/files/isbpList.json";
|
import bankList from "@/utils/files/isbpList.json";
|
||||||
|
import { Participant } from "@/utils/bbPay";
|
||||||
|
|
||||||
const filteredBanks = computed(() => {
|
const filteredBanks = computed(() => {
|
||||||
if (!bankSearchQuery.value) return [];
|
if (!bankSearchQuery.value) return [];
|
||||||
@ -70,7 +71,7 @@ const handleSubmit = (e: Event): void => {
|
|||||||
|
|
||||||
const processedIdentification = postProcessKey(identification.value);
|
const processedIdentification = postProcessKey(identification.value);
|
||||||
|
|
||||||
const data = {
|
const data: Participant = {
|
||||||
offer: offer.value,
|
offer: offer.value,
|
||||||
fullName: fullName.value,
|
fullName: fullName.value,
|
||||||
identification: processedIdentification,
|
identification: processedIdentification,
|
||||||
@ -78,7 +79,6 @@ const handleSubmit = (e: Event): void => {
|
|||||||
accountType: accountType.value,
|
accountType: accountType.value,
|
||||||
account: account.value,
|
account: account.value,
|
||||||
branch: branch.value,
|
branch: branch.value,
|
||||||
|
|
||||||
savingsVariation: savingsVariation.value || "",
|
savingsVariation: savingsVariation.value || "",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { NetworkEnum, TokenEnum } from "../model/NetworkEnum";
|
import { NetworkEnum, TokenEnum } from "../model/NetworkEnum";
|
||||||
import type { ValidDeposit } from "@/model/ValidDeposit";
|
import type { ValidDeposit } from "@/model/ValidDeposit";
|
||||||
|
import { Participant } from "@/utils/bbPay";
|
||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
|
|
||||||
export const useEtherStore = defineStore("ether", {
|
export const useEtherStore = defineStore("ether", {
|
||||||
@ -13,6 +14,8 @@ export const useEtherStore = defineStore("ether", {
|
|||||||
depositsValidList: [] as ValidDeposit[],
|
depositsValidList: [] as ValidDeposit[],
|
||||||
loadingWalletTransactions: false,
|
loadingWalletTransactions: false,
|
||||||
loadingNetworkLiquidity: false,
|
loadingNetworkLiquidity: false,
|
||||||
|
seller: {} as Participant,
|
||||||
|
sellerId: "",
|
||||||
}),
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
setWalletAddress(walletAddress: string) {
|
setWalletAddress(walletAddress: string) {
|
||||||
@ -42,6 +45,12 @@ export const useEtherStore = defineStore("ether", {
|
|||||||
setLoadingNetworkLiquidity(isLoadingNetworkLiquidity: boolean) {
|
setLoadingNetworkLiquidity(isLoadingNetworkLiquidity: boolean) {
|
||||||
this.loadingNetworkLiquidity = isLoadingNetworkLiquidity;
|
this.loadingNetworkLiquidity = isLoadingNetworkLiquidity;
|
||||||
},
|
},
|
||||||
|
setSeller(seller: Participant) {
|
||||||
|
this.seller = seller;
|
||||||
|
},
|
||||||
|
setSellerId(sellerId: string) {
|
||||||
|
this.sellerId = sellerId;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
getValidDepositByWalletAddress: (state) => {
|
getValidDepositByWalletAddress: (state) => {
|
||||||
|
@ -7,7 +7,7 @@ import { approveTokens, addDeposit } from "@/blockchain/sellerMethods";
|
|||||||
import { ref } from "vue";
|
import { ref } from "vue";
|
||||||
import { useEtherStore } from "@/store/ether";
|
import { useEtherStore } from "@/store/ether";
|
||||||
import CustomAlert from "@/components/CustomAlert/CustomAlert.vue";
|
import CustomAlert from "@/components/CustomAlert/CustomAlert.vue";
|
||||||
import { createParticipant, Participant } from "@/utils/bbPay";
|
import { Participant } from "@/utils/bbPay";
|
||||||
|
|
||||||
enum Step {
|
enum Step {
|
||||||
Search,
|
Search,
|
||||||
@ -21,16 +21,13 @@ etherStore.setSellerView(true);
|
|||||||
const flowStep = ref<Step>(Step.Sell);
|
const flowStep = ref<Step>(Step.Sell);
|
||||||
const loading = ref<boolean>(false);
|
const loading = ref<boolean>(false);
|
||||||
|
|
||||||
const seller = ref<Participant>();
|
|
||||||
const sellerId = ref<string>();
|
|
||||||
const showAlert = ref<boolean>(false);
|
const showAlert = ref<boolean>(false);
|
||||||
|
|
||||||
// Verificar tipagem
|
// Verificar tipagem
|
||||||
const approveOffer = async (args: Participant) => {
|
const approveOffer = async (args: Participant) => {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
try {
|
try {
|
||||||
seller.value = args;
|
await approveTokens(args);
|
||||||
await approveTokens(args.offer);
|
|
||||||
flowStep.value = Step.Network;
|
flowStep.value = Step.Network;
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -43,10 +40,8 @@ const approveOffer = async (args: Participant) => {
|
|||||||
const sendNetwork = async () => {
|
const sendNetwork = async () => {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
try {
|
try {
|
||||||
if (seller.value) {
|
if (etherStore.seller) {
|
||||||
const participantWithId = await createParticipant(seller.value);
|
await addDeposit();
|
||||||
sellerId.value = participantWithId.id;
|
|
||||||
await addDeposit(String(seller.value.offer), participantWithId.id);
|
|
||||||
flowStep.value = Step.Sell;
|
flowStep.value = Step.Sell;
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
showAlert.value = true;
|
showAlert.value = true;
|
||||||
@ -75,8 +70,8 @@ const sendNetwork = async () => {
|
|||||||
/>
|
/>
|
||||||
<div v-if="flowStep == Step.Network">
|
<div v-if="flowStep == Step.Network">
|
||||||
<SendNetwork
|
<SendNetwork
|
||||||
:sellerId="sellerId"
|
:sellerId="etherStore.sellerId"
|
||||||
:offer="Number(seller?.offer)"
|
:offer="Number(etherStore.seller.offer)"
|
||||||
:selected-token="etherStore.selectedToken"
|
:selected-token="etherStore.selectedToken"
|
||||||
v-if="!loading"
|
v-if="!loading"
|
||||||
@send-network="sendNetwork"
|
@send-network="sendNetwork"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user