Merge branch 'search-tokens' into creation_of_purchase_screens
This commit is contained in:
		
						commit
						fb7d648308
					
				| @ -9,7 +9,7 @@ import blockchain from "../utils/blockchain"; | ||||
| // Store reference | ||||
| const etherStore = useEtherStore(); | ||||
| 
 | ||||
| const { walletAddress, depositList } = storeToRefs(etherStore); | ||||
| const { walletAddress, depositsAddedList } = storeToRefs(etherStore); | ||||
| 
 | ||||
| // Reactive state | ||||
| const tokenValue = ref(0); | ||||
| @ -21,12 +21,13 @@ const selectedDeposit = ref(); | ||||
| // Emits | ||||
| const emit = defineEmits(["tokenBuy"]); | ||||
| 
 | ||||
| // Methods | ||||
| // Blockchain methods | ||||
| const connectAccount = async () => { | ||||
|   await blockchain.connectProvider(); | ||||
|   verifyLiquidity(); | ||||
| }; | ||||
| 
 | ||||
| // Debounce methods | ||||
| const handleInputEvent = (event: any) => { | ||||
|   const { value } = event.target; | ||||
| 
 | ||||
| @ -42,6 +43,8 @@ const handleInputEvent = (event: any) => { | ||||
|   verifyLiquidity(); | ||||
| }; | ||||
| 
 | ||||
| // Enable button methods | ||||
| // Check if has more than 2 decimal places | ||||
| const decimalCount = (num: Number) => { | ||||
|   const numStr = String(num); | ||||
|   if (numStr.includes(".")) { | ||||
| @ -49,17 +52,15 @@ const decimalCount = (num: Number) => { | ||||
|   } | ||||
|   return 0; | ||||
| }; | ||||
| 
 | ||||
| // Verify if there is a valid deposit to buy | ||||
| const verifyLiquidity = () => { | ||||
|   enableSelectButton.value = false; | ||||
|   selectedDeposit.value = null; | ||||
| 
 | ||||
|   if (!walletAddress.value || tokenValue.value == 0) return; | ||||
|   if (!walletAddress.value || tokenValue.value <= 0) return; | ||||
| 
 | ||||
|   const found = depositList.value.find((element) => { | ||||
|     const p2pixTokenValue = blockchain.verifyDepositAmmount( | ||||
|       element.args.amount | ||||
|     ); | ||||
|   depositsAddedList.value.find((element) => { | ||||
|     const p2pixTokenValue = blockchain.formatBigNumber(element.args.amount); | ||||
|     if ( | ||||
|       tokenValue.value!! <= Number(p2pixTokenValue) && | ||||
|       tokenValue.value!! != 0 && | ||||
| @ -68,7 +69,10 @@ const verifyLiquidity = () => { | ||||
|       enableSelectButton.value = true; | ||||
|       hasLiquidity.value = true; | ||||
|       selectedDeposit.value = element; | ||||
|       console.log("Selected is :", blockchain.verifyDepositAmmount(element.args.amount)) | ||||
|       console.log( | ||||
|         "Selected is :", | ||||
|         blockchain.formatBigNumber(element.args.amount) | ||||
|       ); | ||||
|       return true; | ||||
|     } | ||||
|     return false; | ||||
|  | ||||
| @ -39,7 +39,6 @@ const formatWalletBalance = (): string => { | ||||
|       src="@/assets/logo.svg" | ||||
|       width="75" | ||||
|       height="75" | ||||
|       @load="connectMetaMask()" | ||||
|     /> | ||||
|     <div class="flex gap-4 items-center"> | ||||
|       <button type="button" class="default-button">Quero vender</button> | ||||
|  | ||||
| @ -4,7 +4,14 @@ export const useEtherStore = defineStore("ether", { | ||||
|   state: () => ({ | ||||
|     walletAddress: "", | ||||
|     balance: "", | ||||
|     depositList: [{}], | ||||
|     // Depósitos válidos para compra
 | ||||
|     depositsValidList: [{}], | ||||
|     // Depósitos adicionados na blockchain
 | ||||
|     depositsAddedList: [{}], | ||||
|     // Depósitos expirados na blockchain
 | ||||
|     depositsExpiredList: [{}], | ||||
|     // Locks adicionados na blockchain
 | ||||
|     locksAddedList: [{}], | ||||
|   }), | ||||
|   actions: { | ||||
|     setWalletAddress(walletAddress: string) { | ||||
| @ -13,8 +20,17 @@ export const useEtherStore = defineStore("ether", { | ||||
|     setBalance(balance: string) { | ||||
|       this.balance = balance; | ||||
|     }, | ||||
|     setDepositList(depositList: any[]) { | ||||
|       this.depositList = depositList; | ||||
|     setDepositsValidList(depositsValidList: any[]) { | ||||
|       this.depositsValidList = depositsValidList; | ||||
|     }, | ||||
|     setDepositsAddedList(depositsAddedList: any[]) { | ||||
|       this.depositsAddedList = depositsAddedList; | ||||
|     }, | ||||
|     setDepositsExpiredList(depositsExpiredList: any[]) { | ||||
|       this.depositsExpiredList = depositsExpiredList; | ||||
|     }, | ||||
|     setLocksAddedList(locksAddedList: any[]) { | ||||
|       this.locksAddedList = locksAddedList; | ||||
|     }, | ||||
|   }, | ||||
| }); | ||||
|  | ||||
| @ -1,14 +1,70 @@ | ||||
| import { useEtherStore } from "@/store/ether"; | ||||
| import { BigNumber, ethers } from "ethers"; | ||||
| 
 | ||||
| // smart contract imports
 | ||||
| // Smart contract imports
 | ||||
| import mockToken from "./smart_contract_files/MockToken.json"; | ||||
| import p2pix from "./smart_contract_files/P2PIX.json"; | ||||
| import addresses from "./smart_contract_files/localhost.json"; | ||||
| import p2pEventsAndErrors from "./smart_contract_files/EventAndErrors.json" | ||||
| 
 | ||||
| // Mock wallets import
 | ||||
| import { wallets } from "./smart_contract_files/wallets.json"; | ||||
| 
 | ||||
| // Provider methods
 | ||||
| const connectProvider = 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 walletAddress = await provider.send("eth_requestAccounts", []); | ||||
|   const balance = await tokenContract.balanceOf(walletAddress[0]); | ||||
| 
 | ||||
|   etherStore.setWalletAddress(ethers.utils.getAddress(walletAddress[0])); | ||||
|   etherStore.setBalance(String(balance)); | ||||
| 
 | ||||
|   const p2pEvents = new ethers.Contract(addresses.p2pix, p2pix.abi, signer); | ||||
| 
 | ||||
|   const filterDeposits = p2pEvents.filters.DepositAdded(null); | ||||
|   const eventsDeposits = await p2pEvents.queryFilter(filterDeposits); | ||||
|   console.log("Deposits Added: ", eventsDeposits); | ||||
|   etherStore.setDepositsAddedList(eventsDeposits); | ||||
| 
 | ||||
|   const filterLocks = p2pEvents.filters.LockAdded(null); | ||||
|   const eventsLocks = await p2pEvents.queryFilter(filterLocks); | ||||
|   console.log("Locks Added: ", eventsLocks); | ||||
|   etherStore.setLocksAddedList(eventsLocks); | ||||
| 
 | ||||
|   const filterExpiredLocks = p2pEvents.filters.LockReturned(null); | ||||
|   const eventsExpiredLocks = await p2pEvents.queryFilter(filterExpiredLocks); | ||||
|   console.log("Expired Locks: ", eventsExpiredLocks); | ||||
|   etherStore.setDepositsExpiredList(eventsExpiredLocks); | ||||
| 
 | ||||
|   // (TO DO) Filter valid deposits
 | ||||
| 
 | ||||
|   connection.on("accountsChanged", (accounts: string[]) => { | ||||
|     updateWalletStatus(accounts[0]); | ||||
|   }); | ||||
| }; | ||||
| 
 | ||||
| const getProvider = (): ethers.providers.Web3Provider | null => { | ||||
|   const window_ = window as any; | ||||
|   const connection = window_.ethereum; | ||||
| 
 | ||||
|   if (!connection) return null; | ||||
| 
 | ||||
|   return new ethers.providers.Web3Provider(connection); | ||||
| }; | ||||
| 
 | ||||
| // Wallet methods
 | ||||
| // Update wallet state (balance and address)
 | ||||
| const updateWalletStatus = async (walletAddress: string) => { | ||||
|   const etherStore = useEtherStore(); | ||||
|   const provider = getProvider(); | ||||
| @ -23,36 +79,7 @@ const updateWalletStatus = async (walletAddress: string) => { | ||||
|   etherStore.setWalletAddress(ethers.utils.getAddress(walletAddress)); | ||||
| }; | ||||
| 
 | ||||
| const connectProvider = 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 contract = new ethers.Contract(addresses.token, mockToken.abi, signer); | ||||
| 
 | ||||
|   const walletAddress = await provider.send("eth_requestAccounts", []); | ||||
|   const balance = await contract.balanceOf(walletAddress[0]); | ||||
| 
 | ||||
|   etherStore.setWalletAddress(ethers.utils.getAddress(walletAddress[0])); | ||||
|   etherStore.setBalance(String(balance)); | ||||
| 
 | ||||
|   const p2pContract = new ethers.Contract(addresses.p2pix, p2pEventsAndErrors.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[]) => { | ||||
|     updateWalletStatus(accounts[0]); | ||||
|   }); | ||||
| }; | ||||
| 
 | ||||
| //  Split tokens between wallets in wallets.json
 | ||||
| const splitTokens = async () => { | ||||
|   const etherStore = useEtherStore(); | ||||
|   const provider = getProvider(); | ||||
| @ -71,13 +98,14 @@ const splitTokens = async () => { | ||||
|   } | ||||
| }; | ||||
| 
 | ||||
| const mockDeposit = async (tokenQty = "1000.0", pixKey = "00011122233") => { | ||||
| // Deposit methods
 | ||||
| // Gets value and pix key from user's form to create a deposit in the blockchain
 | ||||
| const addDeposit = async (tokenQty = "1000.0", pixKey = "00011122233") => { | ||||
|   const etherStore = useEtherStore(); | ||||
|   const provider = getProvider(); | ||||
| 
 | ||||
|   if (!provider) return; | ||||
| 
 | ||||
|   const signer = provider.getSigner(); | ||||
| 
 | ||||
|   const tokenContract = new ethers.Contract( | ||||
|     addresses.token, | ||||
|     mockToken.abi, | ||||
| @ -85,14 +113,14 @@ const mockDeposit = async (tokenQty = "1000.0", pixKey = "00011122233") => { | ||||
|   ); | ||||
|   const p2pContract = new ethers.Contract(addresses.p2pix, p2pix.abi, signer); | ||||
| 
 | ||||
|   // first get the approval
 | ||||
|   // First get the approval
 | ||||
|   const apprv = await tokenContract.approve( | ||||
|     addresses.p2pix, | ||||
|     ethers.utils.parseEther(tokenQty) | ||||
|   ); | ||||
|   await apprv.wait(); | ||||
| 
 | ||||
|   // deposit
 | ||||
|   // Now we make the deposit
 | ||||
|   const deposit = await p2pContract.deposit( | ||||
|     addresses.token, | ||||
|     ethers.utils.parseEther(tokenQty), | ||||
| @ -102,65 +130,91 @@ const mockDeposit = async (tokenQty = "1000.0", pixKey = "00011122233") => { | ||||
| 
 | ||||
|   updateWalletStatus(etherStore.walletAddress); | ||||
| 
 | ||||
|   const p2pEvents = new ethers.Contract(addresses.p2pix, p2pEventsAndErrors.abi, signer); | ||||
| 
 | ||||
|   const p2pEvents = new ethers.Contract(addresses.p2pix, p2pix.abi, signer); | ||||
|   const filter = p2pEvents.filters.DepositAdded(null); | ||||
|   const events = await p2pEvents.queryFilter(filter); | ||||
| 
 | ||||
|   console.log(events); | ||||
| 
 | ||||
|   etherStore.setDepositList(events); | ||||
| }; | ||||
| 
 | ||||
| const countDeposit = async () => { | ||||
|   const provider = getProvider(); | ||||
|   if (!provider) return; | ||||
| 
 | ||||
|   const signer = provider.getSigner(); | ||||
|   const contract = new ethers.Contract(addresses.p2pix, p2pix.abi, signer); | ||||
| 
 | ||||
|   const count = await contract.depositCount(); | ||||
| 
 | ||||
|   console.log(Number(count)); | ||||
|   etherStore.setDepositsAddedList(events); | ||||
| }; | ||||
| 
 | ||||
| // Get specific deposit data by its ID
 | ||||
| const mapDeposits = async (depositId: BigNumber) => { | ||||
|   const provider = getProvider(); | ||||
| 
 | ||||
|   if (!provider) return; | ||||
| 
 | ||||
|   const signer = provider.getSigner(); | ||||
|   const contract = new ethers.Contract(addresses.p2pix, p2pix.abi, signer); | ||||
| 
 | ||||
|   const deposit = await contract.mapDeposits(depositId); | ||||
|   const deposit = await contract.mapDeposits(depositId.toNumber()); | ||||
| 
 | ||||
|   console.log(deposit); | ||||
|   return deposit; | ||||
| }; | ||||
| 
 | ||||
| // Lock methods
 | ||||
| // Gets value from user's form to create a lock in the blockchain
 | ||||
| const addLock = async (depositId: Number, amount: Number) => { | ||||
|   const etherStore = useEtherStore(); | ||||
|   const provider = getProvider(); | ||||
| 
 | ||||
|   if (!provider) return; | ||||
|   const signer = provider.getSigner(); | ||||
|   const p2pContract = new ethers.Contract(addresses.p2pix, p2pix.abi, signer); | ||||
| 
 | ||||
|   // Make lock
 | ||||
|   await p2pContract.lock( | ||||
|     depositId, | ||||
|     etherStore.walletAddress, | ||||
|     ethers.constants.AddressZero, | ||||
|     0, | ||||
|     ethers.utils.parseEther(amount.toString()), | ||||
|     [] | ||||
|   ); | ||||
| 
 | ||||
|   const filterLocks = p2pContract.filters.LockAdded(null); | ||||
|   const eventsLocks = await p2pContract.queryFilter(filterLocks); | ||||
|   etherStore.setLocksAddedList(eventsLocks); | ||||
| }; | ||||
| 
 | ||||
| // Get specific lock data by its ID
 | ||||
| const mapLocks = async (lockId: string) => { | ||||
|   const provider = getProvider(); | ||||
| 
 | ||||
|   if (!provider) return; | ||||
| 
 | ||||
|   const signer = provider.getSigner(); | ||||
|   const contract = new ethers.Contract(addresses.p2pix, p2pix.abi, signer); | ||||
|   const lock = await contract.mapLocks(lockId); | ||||
| 
 | ||||
|   console.log(lock); | ||||
|   return lock; | ||||
| }; | ||||
| 
 | ||||
| // Releases lock by specific ID and other additional data
 | ||||
| // (TO DO)
 | ||||
| const releaseLock = async () => { | ||||
|   return; | ||||
| }; | ||||
| 
 | ||||
| // Formatting methods
 | ||||
| const formatEther = (balance: string) => { | ||||
|   const formatted = ethers.utils.formatEther(balance); | ||||
|   return formatted; | ||||
| }; | ||||
| 
 | ||||
| const verifyDepositAmmount = (ammountBigNumber: BigNumber): string => { | ||||
|   return ethers.utils.formatEther(ammountBigNumber); | ||||
| }; | ||||
| 
 | ||||
| const getProvider = (): ethers.providers.Web3Provider | null => { | ||||
|   const window_ = window as any; | ||||
|   const connection = window_.ethereum; | ||||
| 
 | ||||
|   if (!connection) return null; | ||||
| 
 | ||||
|   return new ethers.providers.Web3Provider(connection); | ||||
| const formatBigNumber = (num: BigNumber) => { | ||||
|   const formattedNum = ethers.utils.formatEther(num); | ||||
|   return formattedNum; | ||||
| }; | ||||
| 
 | ||||
| export default { | ||||
|   connectProvider, | ||||
|   formatEther, | ||||
|   splitTokens, | ||||
|   mockDeposit, | ||||
|   countDeposit, | ||||
|   addDeposit, | ||||
|   mapDeposits, | ||||
|   verifyDepositAmmount, | ||||
|   formatBigNumber, | ||||
|   addLock, | ||||
|   mapLocks, | ||||
|   releaseLock, | ||||
| }; | ||||
|  | ||||
| @ -1,219 +0,0 @@ | ||||
| { | ||||
|   "_format": "hh-sol-artifact-1", | ||||
|   "contractName": "EventAndErrors", | ||||
|   "sourceName": "contracts/EventAndErrors.sol", | ||||
|   "abi": [ | ||||
|     { | ||||
|       "inputs": [], | ||||
|       "name": "AlreadyReleased", | ||||
|       "type": "error" | ||||
|     }, | ||||
|     { | ||||
|       "inputs": [], | ||||
|       "name": "DepositAlreadyExists", | ||||
|       "type": "error" | ||||
|     }, | ||||
|     { | ||||
|       "inputs": [], | ||||
|       "name": "InvalidDeposit", | ||||
|       "type": "error" | ||||
|     }, | ||||
|     { | ||||
|       "inputs": [], | ||||
|       "name": "InvalidSigner", | ||||
|       "type": "error" | ||||
|     }, | ||||
|     { | ||||
|       "inputs": [], | ||||
|       "name": "LoopOverflow", | ||||
|       "type": "error" | ||||
|     }, | ||||
|     { | ||||
|       "inputs": [], | ||||
|       "name": "NotEnoughTokens", | ||||
|       "type": "error" | ||||
|     }, | ||||
|     { | ||||
|       "inputs": [], | ||||
|       "name": "NotExpired", | ||||
|       "type": "error" | ||||
|     }, | ||||
|     { | ||||
|       "inputs": [], | ||||
|       "name": "OnlySeller", | ||||
|       "type": "error" | ||||
|     }, | ||||
|     { | ||||
|       "inputs": [], | ||||
|       "name": "TxAlreadyUsed", | ||||
|       "type": "error" | ||||
|     }, | ||||
|     { | ||||
|       "anonymous": false, | ||||
|       "inputs": [ | ||||
|         { | ||||
|           "indexed": true, | ||||
|           "internalType": "address", | ||||
|           "name": "seller", | ||||
|           "type": "address" | ||||
|         }, | ||||
|         { | ||||
|           "indexed": false, | ||||
|           "internalType": "uint256", | ||||
|           "name": "depositID", | ||||
|           "type": "uint256" | ||||
|         }, | ||||
|         { | ||||
|           "indexed": false, | ||||
|           "internalType": "address", | ||||
|           "name": "token", | ||||
|           "type": "address" | ||||
|         }, | ||||
|         { | ||||
|           "indexed": false, | ||||
|           "internalType": "uint256", | ||||
|           "name": "amount", | ||||
|           "type": "uint256" | ||||
|         } | ||||
|       ], | ||||
|       "name": "DepositAdded", | ||||
|       "type": "event" | ||||
|     }, | ||||
|     { | ||||
|       "anonymous": false, | ||||
|       "inputs": [ | ||||
|         { | ||||
|           "indexed": true, | ||||
|           "internalType": "address", | ||||
|           "name": "seller", | ||||
|           "type": "address" | ||||
|         }, | ||||
|         { | ||||
|           "indexed": false, | ||||
|           "internalType": "uint256", | ||||
|           "name": "depositID", | ||||
|           "type": "uint256" | ||||
|         } | ||||
|       ], | ||||
|       "name": "DepositClosed", | ||||
|       "type": "event" | ||||
|     }, | ||||
|     { | ||||
|       "anonymous": false, | ||||
|       "inputs": [ | ||||
|         { | ||||
|           "indexed": true, | ||||
|           "internalType": "address", | ||||
|           "name": "seller", | ||||
|           "type": "address" | ||||
|         }, | ||||
|         { | ||||
|           "indexed": false, | ||||
|           "internalType": "uint256", | ||||
|           "name": "depositID", | ||||
|           "type": "uint256" | ||||
|         }, | ||||
|         { | ||||
|           "indexed": false, | ||||
|           "internalType": "uint256", | ||||
|           "name": "amount", | ||||
|           "type": "uint256" | ||||
|         } | ||||
|       ], | ||||
|       "name": "DepositWithdrawn", | ||||
|       "type": "event" | ||||
|     }, | ||||
|     { | ||||
|       "anonymous": false, | ||||
|       "inputs": [ | ||||
|         { | ||||
|           "indexed": false, | ||||
|           "internalType": "address", | ||||
|           "name": "owner", | ||||
|           "type": "address" | ||||
|         }, | ||||
|         { | ||||
|           "indexed": false, | ||||
|           "internalType": "uint256", | ||||
|           "name": "amount", | ||||
|           "type": "uint256" | ||||
|         } | ||||
|       ], | ||||
|       "name": "FundsWithdrawn", | ||||
|       "type": "event" | ||||
|     }, | ||||
|     { | ||||
|       "anonymous": false, | ||||
|       "inputs": [ | ||||
|         { | ||||
|           "indexed": true, | ||||
|           "internalType": "address", | ||||
|           "name": "buyer", | ||||
|           "type": "address" | ||||
|         }, | ||||
|         { | ||||
|           "indexed": true, | ||||
|           "internalType": "bytes32", | ||||
|           "name": "lockID", | ||||
|           "type": "bytes32" | ||||
|         }, | ||||
|         { | ||||
|           "indexed": false, | ||||
|           "internalType": "uint256", | ||||
|           "name": "depositID", | ||||
|           "type": "uint256" | ||||
|         }, | ||||
|         { | ||||
|           "indexed": false, | ||||
|           "internalType": "uint256", | ||||
|           "name": "amount", | ||||
|           "type": "uint256" | ||||
|         } | ||||
|       ], | ||||
|       "name": "LockAdded", | ||||
|       "type": "event" | ||||
|     }, | ||||
|     { | ||||
|       "anonymous": false, | ||||
|       "inputs": [ | ||||
|         { | ||||
|           "indexed": true, | ||||
|           "internalType": "address", | ||||
|           "name": "buyer", | ||||
|           "type": "address" | ||||
|         }, | ||||
|         { | ||||
|           "indexed": false, | ||||
|           "internalType": "bytes32", | ||||
|           "name": "lockId", | ||||
|           "type": "bytes32" | ||||
|         } | ||||
|       ], | ||||
|       "name": "LockReleased", | ||||
|       "type": "event" | ||||
|     }, | ||||
|     { | ||||
|       "anonymous": false, | ||||
|       "inputs": [ | ||||
|         { | ||||
|           "indexed": true, | ||||
|           "internalType": "address", | ||||
|           "name": "buyer", | ||||
|           "type": "address" | ||||
|         }, | ||||
|         { | ||||
|           "indexed": false, | ||||
|           "internalType": "bytes32", | ||||
|           "name": "lockId", | ||||
|           "type": "bytes32" | ||||
|         } | ||||
|       ], | ||||
|       "name": "LockReturned", | ||||
|       "type": "event" | ||||
|     } | ||||
|   ], | ||||
|   "bytecode": "0x", | ||||
|   "deployedBytecode": "0x", | ||||
|   "linkReferences": {}, | ||||
|   "deployedLinkReferences": {} | ||||
| } | ||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							| @ -3,6 +3,12 @@ import SearchComponent from "../components/SearchComponent.vue"; | ||||
| import ValidationComponent from "../components/ValidationComponent.vue"; | ||||
| import blockchain from "../utils/blockchain"; | ||||
| 
 | ||||
| // (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 { ethers } from "ethers"; | ||||
| 
 | ||||
| const confirmBuyClick = async ({ selectedDeposit, tokenValue }: any) => { | ||||
|   // finish buy screen | ||||
|   console.log(selectedDeposit); | ||||
| @ -12,6 +18,32 @@ const confirmBuyClick = async ({ selectedDeposit, tokenValue }: any) => { | ||||
|     .then((deposit) => (depositDetail = deposit)); | ||||
|   console.log(tokenValue); | ||||
|   console.log(depositDetail); | ||||
| 
 | ||||
|   // Makes lock with deposit ID and the Amount | ||||
|   if (depositDetail) { | ||||
|     const lock = await blockchain.addLock( | ||||
|       depositDetail.args.depositID, | ||||
|       tokenValue | ||||
|     ); | ||||
|     console.log(lock); | ||||
| 
 | ||||
|     // (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 etherStore = useEtherStore(); | ||||
|     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); | ||||
| 
 | ||||
|     // Data to QRCode | ||||
|     // Chave Pix = depositDetail.pixTarget | ||||
|     // Valor = tokenValue | ||||
|   } | ||||
| }; | ||||
| </script> | ||||
| 
 | ||||
|  | ||||
| @ -5,38 +5,59 @@ import { ref } from "vue"; | ||||
| import { useEtherStore } from "../store/ether"; | ||||
| import blockchain from "../utils/blockchain"; | ||||
| 
 | ||||
| // Blockchain Data | ||||
| const etherStore = useEtherStore(); | ||||
| const { depositsAddedList } = storeToRefs(etherStore); | ||||
| const { locksAddedList } = storeToRefs(etherStore); | ||||
| 
 | ||||
| const { depositList } = storeToRefs(etherStore); | ||||
| 
 | ||||
| // Buyer's flow Data | ||||
| const depositValue = ref<Number>(); | ||||
| const depositPixKey = ref<string>(""); | ||||
| 
 | ||||
| //  Split tokens between wallets in wallets.json | ||||
| const splitTokens = () => { | ||||
|   blockchain.splitTokens(); | ||||
| }; | ||||
| 
 | ||||
| // Formatting methods | ||||
| // Formats wallet address in 0x000...0000 format | ||||
| const formatWalletAddress = (wallet: string): string => { | ||||
|   const walletAddressLength = wallet.length; | ||||
|   const initialText = wallet.substring(0, 5); | ||||
|   const finalText = wallet.substring( | ||||
|     walletAddressLength - 4, | ||||
|     walletAddressLength | ||||
|   ); | ||||
|   return `${initialText}...${finalText}`; | ||||
| }; | ||||
| 
 | ||||
| // Deposit methods | ||||
| // Gets value and pix key from user's form to create a deposit in the blockchain | ||||
| const mockDeposit = () => { | ||||
|   if (!depositValue.value || !depositPixKey.value) return; | ||||
|   blockchain.mockDeposit(depositValue.value.toString(), depositPixKey.value); | ||||
| }; | ||||
| 
 | ||||
| const countDeposit = () => { | ||||
|   blockchain.countDeposit(); | ||||
|   blockchain.addDeposit(depositValue.value.toString(), depositPixKey.value); | ||||
| }; | ||||
| 
 | ||||
| // Get specific deposit data by its ID | ||||
| const mapDeposit = (depositId: BigNumber) => { | ||||
|   blockchain.mapDeposits(depositId); | ||||
| }; | ||||
| 
 | ||||
| // Lock methods | ||||
| // (TO DO) Releases lock by specific ID and other additional data | ||||
| const releaseLock = () => { | ||||
|   blockchain.releaseLock(); | ||||
| }; | ||||
| 
 | ||||
| // Get specific lock data by its ID | ||||
| const mapLock = (lockId: string) => { | ||||
|   blockchain.mapLocks(lockId); | ||||
| }; | ||||
| </script> | ||||
| 
 | ||||
| <template> | ||||
|   <div class="page"> | ||||
|     <div class="flex flex-col gap-4 justify-start items-start w-2/3"> | ||||
|       <button type="button" class="default-button" @click="countDeposit()"> | ||||
|         Contar depósitos | ||||
|       </button> | ||||
| 
 | ||||
|       <div class="flex gap-4 w-full justify-between"> | ||||
|         <input | ||||
|           type="number" | ||||
| @ -60,17 +81,32 @@ const mapDeposit = (depositId: BigNumber) => { | ||||
|       <button type="button" class="default-button" @click="splitTokens()"> | ||||
|         Dividir tokens | ||||
|       </button> | ||||
| 
 | ||||
|       <button type="button" class="default-button" @click="releaseLock()"> | ||||
|         Release Lock | ||||
|       </button> | ||||
|     </div> | ||||
| 
 | ||||
|     <ul class="flex flex-col justify-center items-center gap-4"> | ||||
|       <li | ||||
|         class="text-gray-900 font-semibold text-lg cursor-pointer border-2 border-amber-400 p-2 rounded-md bg-amber-200" | ||||
|         v-for="deposit in depositList" | ||||
|         :key="deposit['blockNumber']" | ||||
|         @click="mapDeposit(deposit['args']['depositID'])" | ||||
|         v-for="deposit in depositsAddedList" | ||||
|         :key="deposit.blockNumber" | ||||
|         @click="mapDeposit(deposit.args.depositID)" | ||||
|       > | ||||
|         Address:<br />{{ deposit["args"]["0"] }}<br /> | ||||
|         MRBZ: {{ blockchain.formatEther(deposit["args"]["amount"]) }} | ||||
|         Seller:<br />{{ formatWalletAddress(deposit.args.seller) }}<br /> | ||||
|         MRBZ: {{ blockchain.formatEther(deposit.args.amount) }} | ||||
|       </li> | ||||
|     </ul> | ||||
|     <ul class="flex flex-col justify-center items-center gap-4"> | ||||
|       <li | ||||
|         class="text-gray-900 font-semibold text-lg cursor-pointer border-2 border-amber-400 p-2 rounded-md bg-amber-200" | ||||
|         v-for="lock in locksAddedList" | ||||
|         :key="lock.blockNumber" | ||||
|         @click="mapLock(lock.args.lockID)" | ||||
|       > | ||||
|         Buyer:<br />{{ formatWalletAddress(lock.args.buyer) }}<br /> | ||||
|         MRBZ: {{ blockchain.formatEther(lock.args.amount) }} | ||||
|       </li> | ||||
|     </ul> | ||||
|   </div> | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user