add default page layout with header

Co-authored-by: brunoedcf <brest.dallacosta@outlook.com>
This commit is contained in:
RcleydsonR
2022-11-21 16:02:01 -03:00
parent 328bb9ad62
commit 35a92b2ca8
21 changed files with 231 additions and 546 deletions

View File

@@ -1,18 +1,7 @@
import qrcode from "qrcode";
import type { QRCodeToDataURLOptions } from "qrcode";
import { crc16ccitt } from "crc";
interface PixParams {
pixKey: string;
merchantCity?: string;
merchantName?: string;
value?: number;
transactionId?: string;
message?: string;
cep?: string;
currency?: number;
countryCode?: string;
}
import {type Pix } from "@/model/Pix";
const pix = ({
pixKey,
@@ -24,7 +13,7 @@ const pix = ({
transactionId = "***",
currency = 986,
countryCode = "BR",
}: PixParams) => {
}: Pix) => {
const payloadKeyString = generatePixKey(pixKey, message);
const payload: string[] = [
@@ -84,4 +73,4 @@ const formatEMV = (id: string, param: string): string => {
return `${id}${len}${param}`;
};
export { type PixParams, pix };
export { pix };

View File

@@ -8,12 +8,9 @@ import addresses from "../../../p2pix-smart-contracts/deploys/localhost.json"
const updateWalletStatus = async (walletAddress: string) => {
const etherStore = useEtherStore();
const window_ = window as any;
const connection = window_.ethereum;
if (!connection) return;
const provider = new ethers.providers.Web3Provider(connection);
const provider = getProvider();
if(!provider) return;
const signer = provider.getSigner();
const contract = new ethers.Contract(addresses.token, mocktoken.abi, signer);
@@ -29,33 +26,27 @@ const connectProvider = async () => {
const connection = window_.ethereum;
let provider: ethers.providers.Web3Provider | null = null;
if (connection) {
if (!connection) return;
provider = new ethers.providers.Web3Provider(connection);
const signer = provider.getSigner();
const contract = new ethers.Contract(addresses.token, mocktoken.abi, signer);
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]);
const walletAddress = await provider.send("eth_requestAccounts", []);
const balance = await contract.balanceOf(walletAddress[0]);
etherStore.setWalletAddress(walletAddress[0]);
etherStore.setBalance(String(balance));
etherStore.setWalletAddress(walletAddress[0]);
etherStore.setBalance(String(balance));
connection.on("accountsChanged", (accounts: string[]) => {
updateWalletStatus(accounts[0]);
});
}
connection.on("accountsChanged", (accounts: string[]) => {
updateWalletStatus(accounts[0]);
});
};
const makeTransaction = async () => {
const etherStore = useEtherStore();
const window_ = window as any;
const connection = window_.ethereum;
let provider: ethers.providers.Web3Provider | null = null;
const provider = getProvider();
if(!provider) return;
if (!connection) return;
provider = new ethers.providers.Web3Provider(connection);
const signer = provider.getSigner();
const contract = new ethers.Contract(addresses.token, mocktoken.abi, signer);
@@ -71,4 +62,13 @@ const formatEther = (balance: string) => {
return formatted;
};
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);
}
export default { connectProvider, formatEther, makeTransaction };