Merge branch 'mock-deposits' into search-tokens
This commit is contained in:
commit
ae0e96e6ef
@ -1,6 +1,7 @@
|
|||||||
import { createRouter, createWebHistory } from "vue-router";
|
import { createRouter, createWebHistory } from "vue-router";
|
||||||
import HomeView from "../views/HomeView.vue";
|
import HomeView from "../views/HomeView.vue";
|
||||||
import QrCodeFormVue from "../views/QrCodeForm.vue";
|
import QrCodeFormVue from "../views/QrCodeForm.vue";
|
||||||
|
import MockView from "../views/MockView.vue";
|
||||||
|
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
history: createWebHistory(import.meta.env.BASE_URL),
|
history: createWebHistory(import.meta.env.BASE_URL),
|
||||||
@ -15,6 +16,11 @@ const router = createRouter({
|
|||||||
name: "pix",
|
name: "pix",
|
||||||
component: QrCodeFormVue,
|
component: QrCodeFormVue,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: "/mock",
|
||||||
|
name: "mock",
|
||||||
|
component: MockView,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ export const useEtherStore = defineStore("ether", {
|
|||||||
state: () => ({
|
state: () => ({
|
||||||
walletAddress: "",
|
walletAddress: "",
|
||||||
balance: "",
|
balance: "",
|
||||||
|
depositList: {},
|
||||||
}),
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
setWalletAddress(walletAddress: string) {
|
setWalletAddress(walletAddress: string) {
|
||||||
@ -12,5 +13,8 @@ export const useEtherStore = defineStore("ether", {
|
|||||||
setBalance(balance: string) {
|
setBalance(balance: string) {
|
||||||
this.balance = balance;
|
this.balance = balance;
|
||||||
},
|
},
|
||||||
|
setDepositList(depositList: {}) {
|
||||||
|
this.depositList = depositList;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -3,9 +3,11 @@ import { ethers } from "ethers";
|
|||||||
|
|
||||||
// smart contract imports
|
// smart contract imports
|
||||||
import mockToken from "./smart_contract_files/MockToken.json";
|
import mockToken from "./smart_contract_files/MockToken.json";
|
||||||
//import p2pix from "./smart_contract_files/P2PIX.json";
|
import p2pix from "./smart_contract_files/P2PIX.json";
|
||||||
import addresses from "./smart_contract_files/localhost.json";
|
import addresses from "./smart_contract_files/localhost.json";
|
||||||
|
|
||||||
|
import { wallets } from "./smart_contract_files/wallets.json"
|
||||||
|
|
||||||
const updateWalletStatus = async (walletAddress: string) => {
|
const updateWalletStatus = async (walletAddress: string) => {
|
||||||
const etherStore = useEtherStore();
|
const etherStore = useEtherStore();
|
||||||
const provider = getProvider();
|
const provider = getProvider();
|
||||||
@ -37,29 +39,89 @@ const connectProvider = async () => {
|
|||||||
etherStore.setWalletAddress(walletAddress[0]);
|
etherStore.setWalletAddress(walletAddress[0]);
|
||||||
etherStore.setBalance(String(balance));
|
etherStore.setBalance(String(balance));
|
||||||
|
|
||||||
|
const p2pContract = new ethers.Contract(addresses.p2pix, p2pix.abi, signer);
|
||||||
|
|
||||||
|
const filter = p2pContract.filters.DepositAdded(null);
|
||||||
|
const events = await p2pContract.queryFilter(filter);
|
||||||
|
|
||||||
|
console.log(events)
|
||||||
|
|
||||||
|
etherStore.setDepositList(events);
|
||||||
|
|
||||||
connection.on("accountsChanged", (accounts: string[]) => {
|
connection.on("accountsChanged", (accounts: string[]) => {
|
||||||
updateWalletStatus(accounts[0]);
|
updateWalletStatus(accounts[0]);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const makeTransaction = async (
|
const splitTokens = async () => {
|
||||||
receiverAccountAddress = "0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
|
|
||||||
ammount = "100.0"
|
|
||||||
) => {
|
|
||||||
const etherStore = useEtherStore();
|
const etherStore = useEtherStore();
|
||||||
const provider = getProvider();
|
const window_ = window as any;
|
||||||
if (!provider) return;
|
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 signer = provider.getSigner();
|
||||||
const contract = new ethers.Contract(addresses.token, mockToken.abi, signer);
|
const contract = new ethers.Contract(addresses.token, mockToken.abi, signer);
|
||||||
|
|
||||||
const tx = await contract.transfer(
|
for (var i = 0; i < wallets.length; i++){
|
||||||
receiverAccountAddress,
|
const tx = await contract.transfer(wallets[i], ethers.utils.parseEther("4000000.0"));
|
||||||
ethers.utils.parseEther(ammount)
|
await tx.wait()
|
||||||
);
|
updateWalletStatus(etherStore.walletAddress);
|
||||||
await tx.wait();
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const mockDeposit = async () => {
|
||||||
|
const etherStore = useEtherStore();
|
||||||
|
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 tokenContract = new ethers.Contract(addresses.token, mockToken.abi, signer);
|
||||||
|
const p2pContract = new ethers.Contract(addresses.p2pix, p2pix.abi, signer);
|
||||||
|
|
||||||
|
// first get the approval
|
||||||
|
const apprv = await tokenContract.approve(addresses.p2pix, ethers.utils.parseEther("1000.0"));
|
||||||
|
await apprv.wait();
|
||||||
|
|
||||||
|
// deposit
|
||||||
|
const mockPixKey = "00011122233";
|
||||||
|
const deposit = await p2pContract.deposit(addresses.token, ethers.utils.parseEther("1000.0"), mockPixKey);
|
||||||
|
await deposit.wait();
|
||||||
|
|
||||||
updateWalletStatus(etherStore.walletAddress);
|
updateWalletStatus(etherStore.walletAddress);
|
||||||
|
|
||||||
|
const filter = p2pContract.filters.DepositAdded(null);
|
||||||
|
const events = await p2pContract.queryFilter(filter);
|
||||||
|
|
||||||
|
console.log(events)
|
||||||
|
|
||||||
|
etherStore.setDepositList(events);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const countDeposit = async () => {
|
||||||
|
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 contract = new ethers.Contract(addresses.p2pix, p2pix.abi, signer);
|
||||||
|
|
||||||
|
const count = await contract.depositCount();
|
||||||
|
|
||||||
|
console.log(Number(count))
|
||||||
};
|
};
|
||||||
|
|
||||||
const formatEther = (balance: string) => {
|
const formatEther = (balance: string) => {
|
||||||
@ -76,4 +138,4 @@ const getProvider = (): ethers.providers.Web3Provider | null => {
|
|||||||
return new ethers.providers.Web3Provider(connection);
|
return new ethers.providers.Web3Provider(connection);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default { connectProvider, formatEther, makeTransaction };
|
export default { connectProvider, formatEther, splitTokens, mockDeposit, countDeposit };
|
||||||
|
8
src/utils/smart_contract_files/wallets.json
Normal file
8
src/utils/smart_contract_files/wallets.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"wallets":[
|
||||||
|
"0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
|
||||||
|
"0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC",
|
||||||
|
"0x90F79bf6EB2c4f870365E785982E1f101E93b906",
|
||||||
|
"0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65"
|
||||||
|
]
|
||||||
|
}
|
85
src/views/MockView.vue
Normal file
85
src/views/MockView.vue
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { storeToRefs } from "pinia";
|
||||||
|
import { useEtherStore } from "../store/ether";
|
||||||
|
import blockchain from "../utils/blockchain";
|
||||||
|
|
||||||
|
const etherStore = useEtherStore();
|
||||||
|
|
||||||
|
const { walletAddress, balance, depositList } = storeToRefs(etherStore);
|
||||||
|
|
||||||
|
const splitTokens = () => {
|
||||||
|
blockchain.splitTokens();
|
||||||
|
};
|
||||||
|
|
||||||
|
const mockDeposit = () => {
|
||||||
|
blockchain.mockDeposit();
|
||||||
|
};
|
||||||
|
|
||||||
|
const countDeposit = () => {
|
||||||
|
blockchain.countDeposit();
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatWalletAddress = (): string => {
|
||||||
|
const walletAddressLength = walletAddress.value.length;
|
||||||
|
const initialText = walletAddress.value.substring(0, 5);
|
||||||
|
const finalText = walletAddress.value.substring(
|
||||||
|
walletAddressLength - 5,
|
||||||
|
walletAddressLength - 1
|
||||||
|
);
|
||||||
|
return `${initialText} ... ${finalText}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatWalletBalance = (): string => {
|
||||||
|
const formattedBalance = blockchain.formatEther(balance.value);
|
||||||
|
const fixed = formattedBalance.substring(0, 8);
|
||||||
|
|
||||||
|
return fixed;
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
|
||||||
|
<div class="flex gap-4 items-center">
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="p-2 rounded text-gray-50"
|
||||||
|
@click="countDeposit()"
|
||||||
|
>
|
||||||
|
Contar depósitos
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="p-2 rounded text-gray-50"
|
||||||
|
@click="mockDeposit()"
|
||||||
|
>
|
||||||
|
Mockar depósitos
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="p-2 rounded text-gray-50"
|
||||||
|
@click="splitTokens()"
|
||||||
|
>
|
||||||
|
Dividir tokens
|
||||||
|
</button>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<ul>
|
||||||
|
<center>
|
||||||
|
<li v-for="deposit in depositList" :key="deposit['blockNumber']">{{deposit['args']['0']}} : MRBZ {{blockchain.formatEther(deposit['args']['amount'])}} </li>
|
||||||
|
</center>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
header {
|
||||||
|
@apply flex flex-row justify-between w-full items-center;
|
||||||
|
}
|
||||||
|
</style>
|
Loading…
x
Reference in New Issue
Block a user