Compare commits
24 Commits
buy-refact
...
refactor/n
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9e5516972a | ||
|
|
a3e3f0506c | ||
|
|
976c48ac4b | ||
|
|
7bcf5d90c2 | ||
|
|
358ae7410f | ||
|
|
a906fa136d | ||
|
|
7ec73e8c6f | ||
|
|
84afed78fb | ||
|
|
2b6be86b2e | ||
|
|
fdc03068f2 | ||
|
|
c58e91e073 | ||
|
|
13c0fcc681 | ||
|
|
5c1d560d0c | ||
|
|
a24ee193d4 | ||
|
|
9b325ac917 | ||
|
|
c3d770f713 | ||
|
|
3ef1694217 | ||
|
|
2b707e81c2 | ||
|
|
f6a9ab854c | ||
|
|
474af2fbfc | ||
|
|
4af059f6b7 | ||
|
|
23163be99d | ||
|
|
b956c8ec2b | ||
|
|
1d429f039a |
12285
package-lock.json
generated
Normal file
29
src/App.vue
@@ -1,34 +1,25 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useRoute } from "vue-router";
|
import { useRoute } from "vue-router";
|
||||||
import TopBar from "@/components/TopBar/TopBar.vue";
|
import TopBar from "@/components/TopBar/TopBar.vue";
|
||||||
import SpinnerComponent from "@/components/SpinnerComponent.vue";
|
import SpinnerComponent from "@/components/ui/SpinnerComponent.vue";
|
||||||
import ToasterComponent from "@/components/ToasterComponent.vue";
|
import ToasterComponent from "@/components/ui/ToasterComponent.vue";
|
||||||
import { init, useOnboard } from "@web3-onboard/vue";
|
import { init, useOnboard } from "@web3-onboard/vue";
|
||||||
import injectedModule from "@web3-onboard/injected-wallets";
|
import injectedModule from "@web3-onboard/injected-wallets";
|
||||||
import { Networks } from "./model/Networks";
|
import { Networks, DEFAULT_NETWORK } from "@/config/networks";
|
||||||
import { NetworkEnum } from "./model/NetworkEnum";
|
|
||||||
import { ref } from "vue";
|
import { ref } from "vue";
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const injected = injectedModule();
|
const injected = injectedModule();
|
||||||
const targetNetwork = ref(NetworkEnum.sepolia);
|
const targetNetwork = ref(DEFAULT_NETWORK);
|
||||||
|
|
||||||
const web3Onboard = init({
|
const web3Onboard = init({
|
||||||
wallets: [injected],
|
wallets: [injected],
|
||||||
chains: [
|
chains: Object.values(Networks).map((network) => ({
|
||||||
{
|
id: network.id,
|
||||||
id: Networks[NetworkEnum.sepolia].chainId,
|
token: network.nativeCurrency.symbol,
|
||||||
token: "ETH",
|
label: network.name,
|
||||||
label: "Sepolia",
|
rpcUrl: network.rpcUrls.default.http[0],
|
||||||
rpcUrl: import.meta.env.VITE_SEPOLIA_API_URL,
|
})),
|
||||||
},
|
|
||||||
{
|
|
||||||
id: Networks[NetworkEnum.rootstock].chainId,
|
|
||||||
token: "tRBTC",
|
|
||||||
label: "Rootstock Testnet",
|
|
||||||
rpcUrl: import.meta.env.VITE_ROOTSTOCK_API_URL,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
connect: {
|
connect: {
|
||||||
autoConnectLastWallet: true,
|
autoConnectLastWallet: true,
|
||||||
},
|
},
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
76
src/assets/networks/rootstock-testnet.svg
Normal file
|
After Width: | Height: | Size: 79 KiB |
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 644 B After Width: | Height: | Size: 644 B |
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
@@ -1,70 +0,0 @@
|
|||||||
import { useUser } from "@/composables/useUser";
|
|
||||||
import { NetworkEnum, TokenEnum } from "@/model/NetworkEnum";
|
|
||||||
import { createPublicClient, http, type Address } from "viem";
|
|
||||||
import { sepolia, rootstock } from "viem/chains";
|
|
||||||
|
|
||||||
const Tokens: { [key in NetworkEnum]: { [key in TokenEnum]: Address } } = {
|
|
||||||
[NetworkEnum.sepolia]: {
|
|
||||||
BRZ: "0x3eBE67A2C7bdB2081CBd34ba3281E90377462289",
|
|
||||||
// BRX: "0x3eBE67A2C7bdB2081CBd34ba3281E90377462289",
|
|
||||||
},
|
|
||||||
[NetworkEnum.rootstock]: {
|
|
||||||
BRZ: "0xfE841c74250e57640390f46d914C88d22C51e82e",
|
|
||||||
// BRX: "0xfE841c74250e57640390f46d914C88d22C51e82e",
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getTokenByAddress = (address: Address) => {
|
|
||||||
const user = useUser();
|
|
||||||
const networksTokens = Tokens[user.networkName.value];
|
|
||||||
for (const [token, tokenAddress] of Object.entries(networksTokens)) {
|
|
||||||
if (tokenAddress.toLowerCase() === address.toLowerCase()) {
|
|
||||||
return token;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getTokenAddress = (
|
|
||||||
token: TokenEnum,
|
|
||||||
network?: NetworkEnum
|
|
||||||
): Address => {
|
|
||||||
const user = useUser();
|
|
||||||
return Tokens[network ? network : user.networkName.value][
|
|
||||||
token
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getP2PixAddress = (network?: NetworkEnum): Address => {
|
|
||||||
const user = useUser();
|
|
||||||
const possibleP2PixAddresses: { [key in NetworkEnum]: Address } = {
|
|
||||||
[NetworkEnum.sepolia]: "0xb7cD135F5eFD9760981e02E2a898790b688939fe",
|
|
||||||
[NetworkEnum.rootstock]: "0x98ba35eb14b38D6Aa709338283af3e922476dE34",
|
|
||||||
};
|
|
||||||
|
|
||||||
return possibleP2PixAddresses[
|
|
||||||
network ? network : user.networkName.value
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getProviderUrl = (network?: NetworkEnum): string => {
|
|
||||||
const user = useUser();
|
|
||||||
const possibleProvidersUrls: { [key in NetworkEnum]: string } = {
|
|
||||||
[NetworkEnum.sepolia]: import.meta.env.VITE_SEPOLIA_API_URL,
|
|
||||||
[NetworkEnum.rootstock]: import.meta.env.VITE_RSK_API_URL,
|
|
||||||
};
|
|
||||||
|
|
||||||
return possibleProvidersUrls[network || user.networkName.value];
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getProviderByNetwork = (network: NetworkEnum) => {
|
|
||||||
const chain = network === NetworkEnum.sepolia ? sepolia : rootstock;
|
|
||||||
return createPublicClient({
|
|
||||||
chain,
|
|
||||||
transport: http(getProviderUrl(network)),
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export const isPossibleNetwork = (networkChain: NetworkEnum): boolean => {
|
|
||||||
return Number(networkChain) in NetworkEnum;
|
|
||||||
};
|
|
||||||
@@ -1,17 +1,10 @@
|
|||||||
import { getContract } from "./provider";
|
import { getContract } from "./provider";
|
||||||
import { getTokenAddress } from "./addresses";
|
import { ChainContract } from "viem";
|
||||||
import {
|
import {
|
||||||
bytesToHex,
|
|
||||||
encodeAbiParameters,
|
|
||||||
keccak256,
|
|
||||||
parseAbiParameters,
|
|
||||||
parseEther,
|
parseEther,
|
||||||
stringToBytes,
|
|
||||||
stringToHex,
|
|
||||||
toBytes,
|
|
||||||
type Address,
|
type Address,
|
||||||
|
type TransactionReceipt,
|
||||||
} from "viem";
|
} from "viem";
|
||||||
import type { TokenEnum } from "@/model/NetworkEnum";
|
|
||||||
|
|
||||||
export const addLock = async (
|
export const addLock = async (
|
||||||
sellerAddress: Address,
|
sellerAddress: Address,
|
||||||
@@ -43,7 +36,7 @@ export const addLock = async (
|
|||||||
|
|
||||||
export const withdrawDeposit = async (
|
export const withdrawDeposit = async (
|
||||||
amount: string,
|
amount: string,
|
||||||
token: TokenEnum
|
token: Address
|
||||||
): Promise<boolean> => {
|
): Promise<boolean> => {
|
||||||
const { address, abi, wallet, client, account } = await getContract();
|
const { address, abi, wallet, client, account } = await getContract();
|
||||||
|
|
||||||
@@ -51,13 +44,11 @@ export const withdrawDeposit = async (
|
|||||||
throw new Error("Wallet not connected");
|
throw new Error("Wallet not connected");
|
||||||
}
|
}
|
||||||
|
|
||||||
const tokenAddress = getTokenAddress(token);
|
|
||||||
|
|
||||||
const { request } = await client.simulateContract({
|
const { request } = await client.simulateContract({
|
||||||
address,
|
address,
|
||||||
abi,
|
abi,
|
||||||
functionName: "withdraw",
|
functionName: "withdraw",
|
||||||
args: [tokenAddress, parseEther(amount), []],
|
args: [token, parseEther(amount), []],
|
||||||
account
|
account
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -69,24 +60,20 @@ export const withdrawDeposit = async (
|
|||||||
|
|
||||||
export const releaseLock = async (
|
export const releaseLock = async (
|
||||||
lockID: bigint,
|
lockID: bigint,
|
||||||
pixtarget: string,
|
pixTimestamp: `0x${string}`&{lenght:34},
|
||||||
signature: string
|
signature: `0x${string}`
|
||||||
): Promise<any> => {
|
): Promise<TransactionReceipt> => {
|
||||||
const { address, abi, wallet, client, account } = await getContract();
|
const { address, abi, wallet, client, account } = await getContract();
|
||||||
|
|
||||||
console.log("Releasing lock", { lockID, pixtarget, signature });
|
|
||||||
if (!wallet) {
|
if (!wallet) {
|
||||||
throw new Error("Wallet not connected");
|
throw new Error("Wallet not connected");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert pixtarget to bytes32
|
|
||||||
const pixTimestamp = keccak256(stringToHex(pixtarget, { size: 32 }) );
|
|
||||||
|
|
||||||
const { request } = await client.simulateContract({
|
const { request } = await client.simulateContract({
|
||||||
address,
|
address,
|
||||||
abi,
|
abi,
|
||||||
functionName: "release",
|
functionName: "release",
|
||||||
args: [BigInt(lockID), pixTimestamp, stringToHex(signature)],
|
args: [BigInt(lockID), pixTimestamp, signature],
|
||||||
account
|
account
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
import { useUser } from "@/composables/useUser";
|
import { useUser } from "@/composables/useUser";
|
||||||
import { formatEther, toHex, stringToHex } from "viem";
|
import { formatEther, toHex, stringToHex } from "viem";
|
||||||
import type { PublicClient, Address } from "viem";
|
import type { PublicClient, Address } from "viem";
|
||||||
|
import { Networks } from "@/config/networks";
|
||||||
import { getContract } from "./provider";
|
import { getContract } from "./provider";
|
||||||
import { getP2PixAddress, getTokenAddress } from "./addresses";
|
|
||||||
import { p2PixAbi } from "./abi"
|
import { p2PixAbi } from "./abi"
|
||||||
import type { ValidDeposit } from "@/model/ValidDeposit";
|
import type { ValidDeposit } from "@/model/ValidDeposit";
|
||||||
import { getNetworkSubgraphURL, NetworkEnum, TokenEnum } from "@/model/NetworkEnum";
|
import type { NetworkConfig } from "@/model/NetworkEnum";
|
||||||
import type { UnreleasedLock } from "@/model/UnreleasedLock";
|
import type { UnreleasedLock } from "@/model/UnreleasedLock";
|
||||||
import type { LockStatus } from "@/model/LockStatus"
|
import { ChainContract } from "viem";
|
||||||
|
|
||||||
const getNetworksLiquidity = async (): Promise<void> => {
|
const getNetworksLiquidity = async (): Promise<void> => {
|
||||||
const user = useUser();
|
const user = useUser();
|
||||||
@@ -16,12 +15,10 @@ const getNetworksLiquidity = async (): Promise<void> => {
|
|||||||
|
|
||||||
const depositLists: ValidDeposit[][] = [];
|
const depositLists: ValidDeposit[][] = [];
|
||||||
|
|
||||||
for (const network of Object.values(NetworkEnum).filter(
|
for (const network of Object.values(Networks)) {
|
||||||
(v) => !isNaN(Number(v))
|
|
||||||
)) {
|
|
||||||
const deposits = await getValidDeposits(
|
const deposits = await getValidDeposits(
|
||||||
getTokenAddress(user.selectedToken.value),
|
user.network.value.tokens[user.selectedToken.value].address,
|
||||||
Number(network)
|
network
|
||||||
);
|
);
|
||||||
if (deposits) depositLists.push(deposits);
|
if (deposits) depositLists.push(deposits);
|
||||||
}
|
}
|
||||||
@@ -32,8 +29,8 @@ const getNetworksLiquidity = async (): Promise<void> => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getParticipantID = async (
|
const getParticipantID = async (
|
||||||
seller: string,
|
seller: Address,
|
||||||
token: string
|
token: Address
|
||||||
): Promise<string> => {
|
): Promise<string> => {
|
||||||
const { address, abi, client } = await getContract();
|
const { address, abi, client } = await getContract();
|
||||||
|
|
||||||
@@ -62,7 +59,7 @@ const getParticipantID = async (
|
|||||||
|
|
||||||
const getValidDeposits = async (
|
const getValidDeposits = async (
|
||||||
token: Address,
|
token: Address,
|
||||||
network: NetworkEnum,
|
network: NetworkConfig,
|
||||||
contractInfo?: { client: PublicClient; address: Address }
|
contractInfo?: { client: PublicClient; address: Address }
|
||||||
): Promise<ValidDeposit[]> => {
|
): Promise<ValidDeposit[]> => {
|
||||||
let client: PublicClient, abi;
|
let client: PublicClient, abi;
|
||||||
@@ -74,9 +71,6 @@ const getValidDeposits = async (
|
|||||||
({ abi, client } = await getContract(true));
|
({ abi, client } = await getContract(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Remove this once we have a subgraph for rootstock
|
|
||||||
if (network === NetworkEnum.rootstock) return [];
|
|
||||||
|
|
||||||
const body = {
|
const body = {
|
||||||
query: `
|
query: `
|
||||||
{
|
{
|
||||||
@@ -90,7 +84,7 @@ const getValidDeposits = async (
|
|||||||
`,
|
`,
|
||||||
};
|
};
|
||||||
|
|
||||||
const depositLogs = await fetch(getNetworkSubgraphURL(network), {
|
const depositLogs = await fetch( network.subgraphUrls[0], {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -119,7 +113,7 @@ const getValidDeposits = async (
|
|||||||
const sellersList = Object.keys(uniqueSellers) as Address[];
|
const sellersList = Object.keys(uniqueSellers) as Address[];
|
||||||
// Use multicall to batch all getBalance requests
|
// Use multicall to batch all getBalance requests
|
||||||
const balanceCalls = sellersList.map((seller) => ({
|
const balanceCalls = sellersList.map((seller) => ({
|
||||||
address: getP2PixAddress(network),
|
address: (network.contracts?.p2pix as ChainContract).address,
|
||||||
abi,
|
abi,
|
||||||
functionName: "getBalance",
|
functionName: "getBalance",
|
||||||
args: [seller, token],
|
args: [seller, token],
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { p2PixAbi } from "./abi";
|
import { p2PixAbi } from "./abi";
|
||||||
import { updateWalletStatus } from "./wallet";
|
import { updateWalletStatus } from "./wallet";
|
||||||
import { getProviderUrl, getP2PixAddress } from "./addresses";
|
|
||||||
import {
|
import {
|
||||||
createPublicClient,
|
createPublicClient,
|
||||||
createWalletClient,
|
createWalletClient,
|
||||||
@@ -9,17 +8,19 @@ import {
|
|||||||
PublicClient,
|
PublicClient,
|
||||||
WalletClient,
|
WalletClient,
|
||||||
} from "viem";
|
} from "viem";
|
||||||
import { sepolia, rootstock } from "viem/chains";
|
|
||||||
import { useUser } from "@/composables/useUser";
|
import { useUser } from "@/composables/useUser";
|
||||||
|
import type { NetworkConfig } from "@/model/NetworkEnum";
|
||||||
|
import type { ChainContract } from "viem";
|
||||||
|
|
||||||
let walletClient: WalletClient | null = null;
|
let walletClient: WalletClient | null = null;
|
||||||
|
|
||||||
const getPublicClient = (): PublicClient => {
|
const getPublicClient = (): PublicClient => {
|
||||||
const user = useUser();
|
const user = useUser();
|
||||||
const rpcUrl = getProviderUrl();
|
const rpcUrl = (user.network.value as NetworkConfig).rpcUrls.default.http[0];
|
||||||
|
const chain = user.network.value;
|
||||||
|
|
||||||
return createPublicClient({
|
return createPublicClient({
|
||||||
chain:
|
chain,
|
||||||
Number(user.networkName.value) === sepolia.id ? sepolia : rootstock,
|
|
||||||
transport: http(rpcUrl),
|
transport: http(rpcUrl),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -30,7 +31,8 @@ const getWalletClient = (): WalletClient | null => {
|
|||||||
|
|
||||||
const getContract = async (onlyRpcProvider = false) => {
|
const getContract = async (onlyRpcProvider = false) => {
|
||||||
const client = getPublicClient();
|
const client = getPublicClient();
|
||||||
const address = getP2PixAddress();
|
const user = useUser();
|
||||||
|
const address = (user.network.value.contracts?.p2pix as ChainContract).address;
|
||||||
const abi = p2PixAbi;
|
const abi = p2PixAbi;
|
||||||
const wallet = onlyRpcProvider ? null : getWalletClient();
|
const wallet = onlyRpcProvider ? null : getWalletClient();
|
||||||
|
|
||||||
@@ -45,8 +47,7 @@ const getContract = async (onlyRpcProvider = false) => {
|
|||||||
|
|
||||||
const connectProvider = async (p: any): Promise<void> => {
|
const connectProvider = async (p: any): Promise<void> => {
|
||||||
const user = useUser();
|
const user = useUser();
|
||||||
const chain =
|
const chain = user.network.value;
|
||||||
Number(user.networkName.value) === sepolia.id ? sepolia : rootstock;
|
|
||||||
|
|
||||||
const [account] = await p!.request({ method: "eth_requestAccounts" });
|
const [account] = await p!.request({ method: "eth_requestAccounts" });
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
import { getContract, getPublicClient, getWalletClient } from "./provider";
|
import { getContract, getPublicClient, getWalletClient } from "./provider";
|
||||||
import { getTokenAddress, getP2PixAddress } from "./addresses";
|
import { parseEther, toHex, ChainContract } from "viem";
|
||||||
import { parseEther, toHex } from "viem";
|
|
||||||
import { sepolia, rootstock } from "viem/chains";
|
|
||||||
|
|
||||||
import { mockTokenAbi } from "./abi";
|
import { mockTokenAbi } from "./abi";
|
||||||
import { useUser } from "@/composables/useUser";
|
import { useUser } from "@/composables/useUser";
|
||||||
import { createParticipant } from "@/utils/bbPay";
|
import { createParticipant } from "@/utils/bbPay";
|
||||||
import type { Participant } from "@/utils/bbPay";
|
import type { Participant } from "@/utils/bbPay";
|
||||||
|
import type { Address } from "viem";
|
||||||
|
|
||||||
|
const getP2PixAddress = (): Address => {
|
||||||
|
const user = useUser();
|
||||||
|
return (user.network.value.contracts?.p2pix as ChainContract).address;
|
||||||
|
};
|
||||||
|
|
||||||
const approveTokens = async (participant: Participant): Promise<any> => {
|
const approveTokens = async (participant: Participant): Promise<any> => {
|
||||||
const user = useUser();
|
const user = useUser();
|
||||||
@@ -21,7 +24,7 @@ const approveTokens = async (participant: Participant): Promise<any> => {
|
|||||||
const [account] = await walletClient.getAddresses();
|
const [account] = await walletClient.getAddresses();
|
||||||
|
|
||||||
// Get token address
|
// Get token address
|
||||||
const tokenAddress = getTokenAddress(user.selectedToken.value);
|
const tokenAddress = user.network.value.tokens[user.selectedToken.value].address;
|
||||||
|
|
||||||
// Check if the token is already approved
|
// Check if the token is already approved
|
||||||
const allowance = await publicClient.readContract({
|
const allowance = await publicClient.readContract({
|
||||||
@@ -33,7 +36,7 @@ const approveTokens = async (participant: Participant): Promise<any> => {
|
|||||||
|
|
||||||
if ( allowance < parseEther(participant.offer.toString()) ) {
|
if ( allowance < parseEther(participant.offer.toString()) ) {
|
||||||
// Approve tokens
|
// Approve tokens
|
||||||
const chain = user.networkId.value === sepolia.id ? sepolia : rootstock;
|
const chain = user.network.value;
|
||||||
const hash = await walletClient.writeContract({
|
const hash = await walletClient.writeContract({
|
||||||
address: tokenAddress,
|
address: tokenAddress,
|
||||||
abi: mockTokenAbi,
|
abi: mockTokenAbi,
|
||||||
@@ -65,15 +68,15 @@ const addDeposit = async (): Promise<any> => {
|
|||||||
if (!sellerId.id) {
|
if (!sellerId.id) {
|
||||||
throw new Error("Failed to create participant");
|
throw new Error("Failed to create participant");
|
||||||
}
|
}
|
||||||
const chain = user.networkId.value === sepolia.id ? sepolia : rootstock;
|
const chain = user.network.value;
|
||||||
const hash = await walletClient.writeContract({
|
const hash = await walletClient.writeContract({
|
||||||
address,
|
address,
|
||||||
abi,
|
abi,
|
||||||
functionName: "deposit",
|
functionName: "deposit",
|
||||||
args: [
|
args: [
|
||||||
user.networkId.value + "-" + sellerId.id,
|
user.network.value.id + "-" + sellerId.id,
|
||||||
toHex("", { size: 32 }),
|
toHex("", { size: 32 }),
|
||||||
getTokenAddress(user.selectedToken.value),
|
user.network.value.tokens[user.selectedToken.value].address,
|
||||||
parseEther(user.seller.value.offer.toString()),
|
parseEther(user.seller.value.offer.toString()),
|
||||||
true,
|
true,
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import { formatEther, hexToString, type Address } from "viem";
|
import { formatEther, type Address } from "viem";
|
||||||
import { useUser } from "@/composables/useUser";
|
import { useUser } from "@/composables/useUser";
|
||||||
|
|
||||||
import { getPublicClient, getWalletClient, getContract } from "./provider";
|
import { getPublicClient, getWalletClient, getContract } from "./provider";
|
||||||
import { getTokenAddress } from "./addresses";
|
|
||||||
|
|
||||||
import { getValidDeposits, getUnreleasedLockById } from "./events";
|
import { getValidDeposits, getUnreleasedLockById } from "./events";
|
||||||
|
|
||||||
@@ -10,7 +9,6 @@ import type { ValidDeposit } from "@/model/ValidDeposit";
|
|||||||
import type { WalletTransaction } from "@/model/WalletTransaction";
|
import type { WalletTransaction } from "@/model/WalletTransaction";
|
||||||
import type { UnreleasedLock } from "@/model/UnreleasedLock";
|
import type { UnreleasedLock } from "@/model/UnreleasedLock";
|
||||||
import { LockStatus } from "@/model/LockStatus";
|
import { LockStatus } from "@/model/LockStatus";
|
||||||
import { getNetworkSubgraphURL } from "@/model/NetworkEnum";
|
|
||||||
|
|
||||||
export const updateWalletStatus = async (): Promise<void> => {
|
export const updateWalletStatus = async (): Promise<void> => {
|
||||||
const user = useUser();
|
const user = useUser();
|
||||||
@@ -36,8 +34,8 @@ export const listValidDepositTransactionsByWalletAddress = async (
|
|||||||
): Promise<ValidDeposit[]> => {
|
): Promise<ValidDeposit[]> => {
|
||||||
const user = useUser();
|
const user = useUser();
|
||||||
const walletDeposits = await getValidDeposits(
|
const walletDeposits = await getValidDeposits(
|
||||||
getTokenAddress(user.selectedToken.value),
|
user.network.value.tokens[user.selectedToken.value].address,
|
||||||
user.networkName.value
|
user.network.value
|
||||||
);
|
);
|
||||||
if (walletDeposits) {
|
if (walletDeposits) {
|
||||||
return walletDeposits
|
return walletDeposits
|
||||||
@@ -67,7 +65,7 @@ export const listAllTransactionByWalletAddress = async (
|
|||||||
const user = useUser();
|
const user = useUser();
|
||||||
|
|
||||||
// Get the current network for the subgraph URL
|
// Get the current network for the subgraph URL
|
||||||
const network = user.networkName.value;
|
const network = user.network.value;
|
||||||
|
|
||||||
// Query subgraph for all relevant transactions
|
// Query subgraph for all relevant transactions
|
||||||
const subgraphQuery = {
|
const subgraphQuery = {
|
||||||
@@ -110,7 +108,7 @@ export const listAllTransactionByWalletAddress = async (
|
|||||||
`,
|
`,
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await fetch(getNetworkSubgraphURL(network), {
|
const response = await fetch(network.subgraphUrls[0], {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -200,7 +198,7 @@ export const listReleaseTransactionByWalletAddress = async (
|
|||||||
walletAddress: Address
|
walletAddress: Address
|
||||||
) => {
|
) => {
|
||||||
const user = useUser();
|
const user = useUser();
|
||||||
const network = user.networkName.value;
|
const network = user.network.value;
|
||||||
|
|
||||||
// Query subgraph for release transactions
|
// Query subgraph for release transactions
|
||||||
const subgraphQuery = {
|
const subgraphQuery = {
|
||||||
@@ -219,7 +217,7 @@ export const listReleaseTransactionByWalletAddress = async (
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Fetch data from subgraph
|
// Fetch data from subgraph
|
||||||
const response = await fetch(getNetworkSubgraphURL(network), {
|
const response = await fetch(network.subgraphUrls[0], {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -263,7 +261,7 @@ export const listReleaseTransactionByWalletAddress = async (
|
|||||||
|
|
||||||
const listLockTransactionByWalletAddress = async (walletAddress: Address) => {
|
const listLockTransactionByWalletAddress = async (walletAddress: Address) => {
|
||||||
const user = useUser();
|
const user = useUser();
|
||||||
const network = user.networkName.value;
|
const network = user.network.value;
|
||||||
|
|
||||||
// Query subgraph for lock added transactions
|
// Query subgraph for lock added transactions
|
||||||
const subgraphQuery = {
|
const subgraphQuery = {
|
||||||
@@ -284,7 +282,7 @@ const listLockTransactionByWalletAddress = async (walletAddress: Address) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Fetch data from subgraph
|
// Fetch data from subgraph
|
||||||
const response = await fetch(getNetworkSubgraphURL(network), {
|
const response = await fetch(network.subgraphUrls[0], {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -332,7 +330,7 @@ const listLockTransactionByWalletAddress = async (walletAddress: Address) => {
|
|||||||
|
|
||||||
const listLockTransactionBySellerAddress = async (sellerAddress: Address) => {
|
const listLockTransactionBySellerAddress = async (sellerAddress: Address) => {
|
||||||
const user = useUser();
|
const user = useUser();
|
||||||
const network = user.networkName.value;
|
const network = user.network.value;
|
||||||
|
|
||||||
// Query subgraph for lock added transactions where seller matches
|
// Query subgraph for lock added transactions where seller matches
|
||||||
const subgraphQuery = {
|
const subgraphQuery = {
|
||||||
@@ -354,7 +352,7 @@ const listLockTransactionBySellerAddress = async (sellerAddress: Address) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Fetch data from subgraph
|
// Fetch data from subgraph
|
||||||
const response = await fetch(getNetworkSubgraphURL(network), {
|
const response = await fetch(network.subgraphUrls[0], {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -463,18 +461,3 @@ export const getActiveLockAmount = async (
|
|||||||
return total;
|
return total;
|
||||||
}, 0);
|
}, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getSellerParticipantId = async (
|
|
||||||
sellerAddress: Address,
|
|
||||||
tokenAddress: Address
|
|
||||||
): Promise<string> => {
|
|
||||||
const { address, abi, client } = await getContract();
|
|
||||||
|
|
||||||
const participantId = await client.readContract({
|
|
||||||
address,
|
|
||||||
abi,
|
|
||||||
functionName: "getPixTarget",
|
|
||||||
args: [sellerAddress, tokenAddress],
|
|
||||||
});
|
|
||||||
return hexToString(participantId);
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ import {
|
|||||||
listAllTransactionByWalletAddress,
|
listAllTransactionByWalletAddress,
|
||||||
listValidDepositTransactionsByWalletAddress,
|
listValidDepositTransactionsByWalletAddress,
|
||||||
} from "@/blockchain/wallet";
|
} from "@/blockchain/wallet";
|
||||||
import CustomButton from "@/components/CustomButton/CustomButton.vue";
|
import CustomButton from "@/components/ui/CustomButton.vue";
|
||||||
import type { ValidDeposit } from "@/model/ValidDeposit";
|
import type { ValidDeposit } from "@/model/ValidDeposit";
|
||||||
import type { WalletTransaction } from "@/model/WalletTransaction";
|
import type { WalletTransaction } from "@/model/WalletTransaction";
|
||||||
import { useUser } from "@/composables/useUser";
|
import { useUser } from "@/composables/useUser";
|
||||||
import { onMounted, ref, watch } from "vue";
|
import { onMounted, ref, watch } from "vue";
|
||||||
import ListingComponent from "../ListingComponent/ListingComponent.vue";
|
import ListingComponent from "@/components/ListingComponent/ListingComponent.vue";
|
||||||
|
|
||||||
// props
|
// props
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
@@ -53,7 +53,7 @@ const getWalletTransactions = async () => {
|
|||||||
const callWithdraw = async (amount: string) => {
|
const callWithdraw = async (amount: string) => {
|
||||||
if (amount) {
|
if (amount) {
|
||||||
user.setLoadingWalletTransactions(true);
|
user.setLoadingWalletTransactions(true);
|
||||||
const withdraw = await withdrawDeposit(amount, user.selectedToken.value);
|
const withdraw = await withdrawDeposit(amount, user.network.value.tokens[user.selectedToken.value].address);
|
||||||
if (withdraw) {
|
if (withdraw) {
|
||||||
console.log("Saque realizado!");
|
console.log("Saque realizado!");
|
||||||
await getWalletTransactions();
|
await getWalletTransactions();
|
||||||
@@ -1,16 +1,15 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, watch } from "vue";
|
import { ref, watch } from "vue";
|
||||||
import { useUser } from "@/composables/useUser";
|
import { useUser } from "@/composables/useUser";
|
||||||
import SpinnerComponent from "@/components/SpinnerComponent.vue";
|
import SpinnerComponent from "@/components/ui/SpinnerComponent.vue";
|
||||||
import CustomButton from "@/components/CustomButton/CustomButton.vue";
|
import CustomButton from "@/components/ui/CustomButton.vue";
|
||||||
import { debounce } from "@/utils/debounce";
|
import { debounce } from "@/utils/debounce";
|
||||||
import { verifyNetworkLiquidity } from "@/utils/networkLiquidity";
|
import { verifyNetworkLiquidity } from "@/utils/networkLiquidity";
|
||||||
import { NetworkEnum } from "@/model/NetworkEnum";
|
|
||||||
import type { ValidDeposit } from "@/model/ValidDeposit";
|
import type { ValidDeposit } from "@/model/ValidDeposit";
|
||||||
import { decimalCount } from "@/utils/decimalCount";
|
import { decimalCount } from "@/utils/decimalCount";
|
||||||
import { getTokenImage } from "@/utils/imagesPath";
|
import { getTokenImage } from "@/utils/imagesPath";
|
||||||
import { onClickOutside } from "@vueuse/core";
|
import { onClickOutside } from "@vueuse/core";
|
||||||
|
import { Networks } from "@/config/networks";
|
||||||
import { TokenEnum } from "@/model/NetworkEnum";
|
import { TokenEnum } from "@/model/NetworkEnum";
|
||||||
|
|
||||||
// Store reference
|
// Store reference
|
||||||
@@ -19,7 +18,7 @@ const selectTokenToggle = ref<boolean>(false);
|
|||||||
|
|
||||||
const {
|
const {
|
||||||
walletAddress,
|
walletAddress,
|
||||||
networkName,
|
network,
|
||||||
selectedToken,
|
selectedToken,
|
||||||
depositsValidList,
|
depositsValidList,
|
||||||
loadingNetworkLiquidity,
|
loadingNetworkLiquidity,
|
||||||
@@ -51,7 +50,7 @@ const connectAccount = async (): Promise<void> => {
|
|||||||
|
|
||||||
const emitConfirmButton = async (): Promise<void> => {
|
const emitConfirmButton = async (): Promise<void> => {
|
||||||
const deposit = selectedDeposits.value?.find(
|
const deposit = selectedDeposits.value?.find(
|
||||||
(d) => d.network === Number(networkName.value)
|
(d) => d.network === network.value
|
||||||
);
|
);
|
||||||
if (!deposit) return;
|
if (!deposit) return;
|
||||||
deposit.participantID = await getParticipantID(deposit.seller, deposit.token);
|
deposit.participantID = await getParticipantID(deposit.seller, deposit.token);
|
||||||
@@ -99,7 +98,7 @@ const verifyLiquidity = (): void => {
|
|||||||
);
|
);
|
||||||
selectedDeposits.value = selDeposits;
|
selectedDeposits.value = selDeposits;
|
||||||
hasLiquidity.value = !!selDeposits.find(
|
hasLiquidity.value = !!selDeposits.find(
|
||||||
(d) => d.network === Number(networkName.value)
|
(d) => d.network === network.value
|
||||||
);
|
);
|
||||||
enableOrDisableConfirmButton();
|
enableOrDisableConfirmButton();
|
||||||
};
|
};
|
||||||
@@ -110,7 +109,7 @@ const enableOrDisableConfirmButton = (): void => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!selectedDeposits.value.find((d) => d.network === networkName.value)) {
|
if (!selectedDeposits.value.find((d) => d.network === network.value)) {
|
||||||
enableConfirmButton.value = false;
|
enableConfirmButton.value = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -118,7 +117,7 @@ const enableOrDisableConfirmButton = (): void => {
|
|||||||
enableConfirmButton.value = true;
|
enableConfirmButton.value = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
watch(networkName, (): void => {
|
watch(network, (): void => {
|
||||||
verifyLiquidity();
|
verifyLiquidity();
|
||||||
enableOrDisableConfirmButton();
|
enableOrDisableConfirmButton();
|
||||||
});
|
});
|
||||||
@@ -239,7 +238,7 @@ const handleSubmit = async (e: Event): Promise<void> => {
|
|||||||
height="24"
|
height="24"
|
||||||
v-if="
|
v-if="
|
||||||
selectedDeposits &&
|
selectedDeposits &&
|
||||||
selectedDeposits.find((d) => d.network == NetworkEnum.rootstock)
|
selectedDeposits.find((d) => d.network == Networks.rootstockTestnet)
|
||||||
"
|
"
|
||||||
/>
|
/>
|
||||||
<img
|
<img
|
||||||
@@ -249,7 +248,7 @@ const handleSubmit = async (e: Event): Promise<void> => {
|
|||||||
height="24"
|
height="24"
|
||||||
v-if="
|
v-if="
|
||||||
selectedDeposits &&
|
selectedDeposits &&
|
||||||
selectedDeposits.find((d) => d.network == NetworkEnum.sepolia)
|
selectedDeposits.find((d) => d.network == Networks.sepolia)
|
||||||
"
|
"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted, onUnmounted } from "vue";
|
import { ref, onMounted, onUnmounted } from "vue";
|
||||||
import CustomButton from "@/components/CustomButton/CustomButton.vue";
|
import CustomButton from "@/components/ui/CustomButton.vue";
|
||||||
import CustomModal from "@/components//CustomModal/CustomModal.vue";
|
import CustomModal from "@/components/ui/CustomModal.vue";
|
||||||
import SpinnerComponent from "@/components/SpinnerComponent.vue";
|
import SpinnerComponent from "@/components/ui/SpinnerComponent.vue";
|
||||||
import { createSolicitation, getSolicitation, type Offer } from "@/utils/bbPay";
|
import { createSolicitation, getSolicitation, type Offer } from "@/utils/bbPay";
|
||||||
import { getSellerParticipantId } from "@/blockchain/wallet";
|
import { getParticipantID } from "@/blockchain/events";
|
||||||
import { getUnreleasedLockById } from "@/blockchain/events";
|
import { getUnreleasedLockById } from "@/blockchain/events";
|
||||||
import QRCode from "qrcode";
|
import QRCode from "qrcode";
|
||||||
|
|
||||||
@@ -18,10 +18,12 @@ const props = defineProps<Props>();
|
|||||||
const qrCode = ref<string>("");
|
const qrCode = ref<string>("");
|
||||||
const qrCodeSvg = ref<string>("");
|
const qrCodeSvg = ref<string>("");
|
||||||
const showWarnModal = ref<boolean>(true);
|
const showWarnModal = ref<boolean>(true);
|
||||||
const pixTarget = ref<string>("");
|
const pixTimestamp = ref<string>("");
|
||||||
const releaseSignature = ref<string>("");
|
const releaseSignature = ref<string>("");
|
||||||
const solicitationData = ref<any>(null);
|
const solicitationData = ref<any>(null);
|
||||||
const pollingInterval = ref<NodeJS.Timeout | null>(null);
|
const pollingInterval = ref<NodeJS.Timeout | null>(null);
|
||||||
|
const copyFeedback = ref<boolean>(false);
|
||||||
|
const copyFeedbackTimeout = ref<NodeJS.Timeout | null>(null);
|
||||||
|
|
||||||
// Function to generate QR code SVG
|
// Function to generate QR code SVG
|
||||||
const generateQrCodeSvg = async (text: string) => {
|
const generateQrCodeSvg = async (text: string) => {
|
||||||
@@ -56,7 +58,7 @@ const checkSolicitationStatus = async () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (response.signature) {
|
if (response.signature) {
|
||||||
pixTarget.value = response.pixTarget;
|
pixTimestamp.value = response.pixTimestamp;
|
||||||
releaseSignature.value = response.signature;
|
releaseSignature.value = response.signature;
|
||||||
// Stop polling when payment is confirmed
|
// Stop polling when payment is confirmed
|
||||||
if (pollingInterval.value) {
|
if (pollingInterval.value) {
|
||||||
@@ -80,13 +82,36 @@ const startPolling = () => {
|
|||||||
pollingInterval.value = setInterval(checkSolicitationStatus, 10000);
|
pollingInterval.value = setInterval(checkSolicitationStatus, 10000);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const copyToClipboard = async () => {
|
||||||
|
if (!qrCode.value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await navigator.clipboard.writeText(qrCode.value);
|
||||||
|
|
||||||
|
if (copyFeedbackTimeout.value) {
|
||||||
|
clearTimeout(copyFeedbackTimeout.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
copyFeedback.value = true;
|
||||||
|
|
||||||
|
copyFeedbackTimeout.value = setTimeout(() => {
|
||||||
|
copyFeedback.value = false;
|
||||||
|
}, 2000);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error copying to clipboard:", error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
try {
|
try {
|
||||||
const { tokenAddress, sellerAddress, amount } = await getUnreleasedLockById(
|
const { tokenAddress, sellerAddress, amount } = await getUnreleasedLockById(
|
||||||
BigInt(props.lockID)
|
BigInt(props.lockID)
|
||||||
);
|
);
|
||||||
|
|
||||||
const participantId = await getSellerParticipantId(
|
const participantId = await getParticipantID(
|
||||||
sellerAddress,
|
sellerAddress,
|
||||||
tokenAddress
|
tokenAddress
|
||||||
);
|
);
|
||||||
@@ -119,6 +144,10 @@ onUnmounted(() => {
|
|||||||
clearInterval(pollingInterval.value);
|
clearInterval(pollingInterval.value);
|
||||||
pollingInterval.value = null;
|
pollingInterval.value = null;
|
||||||
}
|
}
|
||||||
|
if (copyFeedbackTimeout.value) {
|
||||||
|
clearTimeout(copyFeedbackTimeout.value);
|
||||||
|
copyFeedbackTimeout.value = null;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -156,13 +185,24 @@ onUnmounted(() => {
|
|||||||
{{ qrCode }}
|
{{ qrCode }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="flex flex-col items-center gap-1">
|
||||||
<img
|
<img
|
||||||
alt="Copy PIX code"
|
alt="Copy PIX code"
|
||||||
src="@/assets/copyPix.svg?url"
|
src="@/assets/copyPix.svg?url"
|
||||||
width="16"
|
width="16"
|
||||||
height="16"
|
height="16"
|
||||||
class="pt-2 lg:mb-5 cursor-pointer"
|
class="pt-2 cursor-pointer hover:opacity-70 transition-opacity"
|
||||||
|
@click="copyToClipboard"
|
||||||
/>
|
/>
|
||||||
|
<transition name="fade">
|
||||||
|
<span
|
||||||
|
v-if="copyFeedback"
|
||||||
|
class="text-xs text-emerald-500 font-semibold"
|
||||||
|
>
|
||||||
|
Código copiado!
|
||||||
|
</span>
|
||||||
|
</transition>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<CustomButton
|
<CustomButton
|
||||||
:is-disabled="releaseSignature === ''"
|
:is-disabled="releaseSignature === ''"
|
||||||
@@ -170,7 +210,7 @@ onUnmounted(() => {
|
|||||||
releaseSignature ? 'Enviar para a rede' : 'Validando pagamento...'
|
releaseSignature ? 'Enviar para a rede' : 'Validando pagamento...'
|
||||||
"
|
"
|
||||||
@button-clicked="
|
@button-clicked="
|
||||||
emit('pixValidated', { pixTarget, signature: releaseSignature })
|
emit('pixValidated', { pixTimestamp, signature: releaseSignature })
|
||||||
"
|
"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -240,4 +280,15 @@ input[type="number"]::-webkit-inner-spin-button,
|
|||||||
input[type="number"]::-webkit-outer-spin-button {
|
input[type="number"]::-webkit-outer-spin-button {
|
||||||
-webkit-appearance: none;
|
-webkit-appearance: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Fade transition for copy feedback */
|
||||||
|
.fade-enter-active,
|
||||||
|
.fade-leave-active {
|
||||||
|
transition: opacity 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fade-enter-from,
|
||||||
|
.fade-leave-to {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
const props = defineProps({
|
|
||||||
text: String,
|
|
||||||
isDisabled: Boolean,
|
|
||||||
});
|
|
||||||
|
|
||||||
const emit = defineEmits(["buttonClicked"]);
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class="button"
|
|
||||||
@click="emit('buttonClicked')"
|
|
||||||
v-bind:class="{ 'opacity-70': props.isDisabled }"
|
|
||||||
:disabled="props.isDisabled ? props.isDisabled : false"
|
|
||||||
>
|
|
||||||
{{ props.text }}
|
|
||||||
</button>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
.button {
|
|
||||||
@apply rounded-lg w-full text-base font-semibold text-gray-900 p-4 bg-amber-400;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
215
src/components/ListingComponent/BalanceCard.vue
Normal file
@@ -0,0 +1,215 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { ValidDeposit } from "@/model/ValidDeposit";
|
||||||
|
import { ref, watch, onMounted, computed } from "vue";
|
||||||
|
import { debounce } from "@/utils/debounce";
|
||||||
|
import { decimalCount } from "@/utils/decimalCount";
|
||||||
|
import { useFloating, arrow, offset, flip, shift } from "@floating-ui/vue";
|
||||||
|
import IconButton from "../ui/IconButton.vue";
|
||||||
|
import withdrawIcon from "@/assets/withdraw.svg?url";
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
validDeposits: ValidDeposit[];
|
||||||
|
activeLockAmount: number;
|
||||||
|
selectedToken: string;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
withdraw: [amount: string];
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const withdrawAmount = ref<string>("");
|
||||||
|
const isCollapsibleOpen = ref<boolean>(false);
|
||||||
|
const validDecimals = ref<boolean>(true);
|
||||||
|
const validWithdrawAmount = ref<boolean>(true);
|
||||||
|
const enableConfirmButton = ref<boolean>(false);
|
||||||
|
const showInfoTooltip = ref<boolean>(false);
|
||||||
|
const floatingArrow = ref(null);
|
||||||
|
|
||||||
|
const reference = ref<HTMLElement | null>(null);
|
||||||
|
const floating = ref<HTMLElement | null>(null);
|
||||||
|
const infoText = ref<HTMLElement | null>(null);
|
||||||
|
|
||||||
|
const remaining = computed(() => {
|
||||||
|
if (props.validDeposits.length > 0) {
|
||||||
|
const deposit = props.validDeposits[0];
|
||||||
|
return deposit ? deposit.remaining : 0;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleInputEvent = (event: any): void => {
|
||||||
|
const { value } = event.target;
|
||||||
|
|
||||||
|
if (decimalCount(String(value)) > 2) {
|
||||||
|
validDecimals.value = false;
|
||||||
|
enableConfirmButton.value = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
validDecimals.value = true;
|
||||||
|
|
||||||
|
if (value > remaining.value) {
|
||||||
|
validWithdrawAmount.value = false;
|
||||||
|
enableConfirmButton.value = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
validWithdrawAmount.value = true;
|
||||||
|
enableConfirmButton.value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const callWithdraw = () => {
|
||||||
|
if (enableConfirmButton.value && withdrawAmount.value) {
|
||||||
|
emit("withdraw", withdrawAmount.value);
|
||||||
|
// Reset form after withdraw
|
||||||
|
withdrawAmount.value = "";
|
||||||
|
isCollapsibleOpen.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const openWithdrawForm = () => {
|
||||||
|
isCollapsibleOpen.value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const cancelWithdraw = () => {
|
||||||
|
isCollapsibleOpen.value = false;
|
||||||
|
withdrawAmount.value = "";
|
||||||
|
validDecimals.value = true;
|
||||||
|
validWithdrawAmount.value = true;
|
||||||
|
enableConfirmButton.value = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
useFloating(reference, floating, {
|
||||||
|
placement: "right",
|
||||||
|
middleware: [
|
||||||
|
offset(10),
|
||||||
|
flip(),
|
||||||
|
shift(),
|
||||||
|
arrow({ element: floatingArrow }),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="w-full bg-white p-4 sm:p-6 rounded-lg">
|
||||||
|
<div class="flex justify-between items-center">
|
||||||
|
<div>
|
||||||
|
<p class="text-sm leading-5 font-medium text-gray-600">
|
||||||
|
Saldo disponível
|
||||||
|
</p>
|
||||||
|
<p class="text-xl leading-7 font-semibold text-gray-900">
|
||||||
|
{{ remaining }} {{ selectedToken }}
|
||||||
|
</p>
|
||||||
|
<div class="flex gap-2 w-32 sm:w-56" v-if="activeLockAmount != 0">
|
||||||
|
<span class="text-xs font-normal text-gray-400" ref="infoText">
|
||||||
|
{{ `com ${activeLockAmount.toFixed(2)} ${selectedToken} em lock` }}
|
||||||
|
</span>
|
||||||
|
<div
|
||||||
|
class="absolute mt-[2px] md-view"
|
||||||
|
:style="{ left: `${(infoText?.clientWidth ?? 108) + 4}px` }"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
alt="info image"
|
||||||
|
src="@/assets/info.svg?url"
|
||||||
|
aria-describedby="tooltip"
|
||||||
|
ref="reference"
|
||||||
|
@mouseover="showInfoTooltip = true"
|
||||||
|
@mouseout="showInfoTooltip = false"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
role="tooltip"
|
||||||
|
ref="floating"
|
||||||
|
class="w-56 z-50 tooltip md-view"
|
||||||
|
v-if="showInfoTooltip"
|
||||||
|
>
|
||||||
|
Valor "em lock" significa que a quantia está aguardando
|
||||||
|
confirmação de compra e só estará disponível para saque caso a
|
||||||
|
transação expire.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div v-show="!isCollapsibleOpen" class="flex justify-end items-center">
|
||||||
|
<IconButton
|
||||||
|
text="Sacar"
|
||||||
|
:icon="withdrawIcon"
|
||||||
|
variant="outline"
|
||||||
|
size="md"
|
||||||
|
:full-width="false"
|
||||||
|
@click="openWithdrawForm"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="pt-5">
|
||||||
|
<div v-show="isCollapsibleOpen" class="py-2 w-100">
|
||||||
|
<p class="text-sm leading-5 font-medium">Valor do saque</p>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
@input="debounce(handleInputEvent, 500)($event)"
|
||||||
|
placeholder="0"
|
||||||
|
class="text-2xl text-gray-900 w-full outline-none"
|
||||||
|
v-model="withdrawAmount"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="flex justify-center" v-if="!validDecimals">
|
||||||
|
<span class="text-red-500 font-normal text-sm">
|
||||||
|
Por favor utilize no máximo 2 casas decimais
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex justify-center" v-else-if="!validWithdrawAmount">
|
||||||
|
<span class="text-red-500 font-normal text-sm">
|
||||||
|
Saldo insuficiente
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<hr v-show="isCollapsibleOpen" class="pb-3" />
|
||||||
|
<div
|
||||||
|
v-show="isCollapsibleOpen"
|
||||||
|
class="flex justify-between items-center"
|
||||||
|
>
|
||||||
|
<h1
|
||||||
|
@click="cancelWithdraw"
|
||||||
|
class="text-black font-medium cursor-pointer hover:text-gray-600 transition-colors"
|
||||||
|
>
|
||||||
|
Cancelar
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
<IconButton
|
||||||
|
text="Sacar"
|
||||||
|
:icon="withdrawIcon"
|
||||||
|
variant="outline"
|
||||||
|
size="md"
|
||||||
|
:full-width="false"
|
||||||
|
:disabled="!enableConfirmButton"
|
||||||
|
@click="callWithdraw"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
p {
|
||||||
|
@apply text-gray-900;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tooltip {
|
||||||
|
@apply bg-white text-gray-900 font-medium text-xs md:text-base px-3 py-2 rounded border-2 border-emerald-500 left-5 top-[-3rem];
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type="number"] {
|
||||||
|
appearance: textfield;
|
||||||
|
-moz-appearance: textfield;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type="number"]::-webkit-inner-spin-button,
|
||||||
|
input[type="number"]::-webkit-outer-spin-button {
|
||||||
|
-webkit-appearance: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 640px) {
|
||||||
|
.md-view {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
@@ -1,13 +1,11 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { NetworkEnum } from "@/model/NetworkEnum";
|
|
||||||
import type { ValidDeposit } from "@/model/ValidDeposit";
|
import type { ValidDeposit } from "@/model/ValidDeposit";
|
||||||
import type { WalletTransaction } from "@/model/WalletTransaction";
|
import type { WalletTransaction } from "@/model/WalletTransaction";
|
||||||
import { useUser } from "@/composables/useUser";
|
import { useUser } from "@/composables/useUser";
|
||||||
import { ref, watch, onMounted } from "vue";
|
import { ref, watch } from "vue";
|
||||||
import SpinnerComponent from "../SpinnerComponent.vue";
|
import SpinnerComponent from "../ui/SpinnerComponent.vue";
|
||||||
import { decimalCount } from "@/utils/decimalCount";
|
import BalanceCard from "./BalanceCard.vue";
|
||||||
import { debounce } from "@/utils/debounce";
|
import TransactionCard from "./TransactionCard.vue";
|
||||||
import { useFloating, arrow, offset, flip, shift } from "@floating-ui/vue";
|
|
||||||
|
|
||||||
const user = useUser();
|
const user = useUser();
|
||||||
|
|
||||||
@@ -22,80 +20,10 @@ const emit = defineEmits(["depositWithdrawn"]);
|
|||||||
|
|
||||||
const { loadingWalletTransactions } = user;
|
const { loadingWalletTransactions } = user;
|
||||||
|
|
||||||
const remaining = ref<number>(0);
|
|
||||||
const itemsToShow = ref<WalletTransaction[]>([]);
|
const itemsToShow = ref<WalletTransaction[]>([]);
|
||||||
const withdrawAmount = ref<string>("");
|
|
||||||
const withdrawButtonOpacity = ref<number>(0.6);
|
|
||||||
const withdrawButtonCursor = ref<string>("not-allowed");
|
|
||||||
const isCollapsibleOpen = ref<boolean>(false);
|
|
||||||
const validDecimals = ref<boolean>(true);
|
|
||||||
const validWithdrawAmount = ref<boolean>(true);
|
|
||||||
const enableConfirmButton = ref<boolean>(false);
|
|
||||||
const showInfoTooltip = ref<boolean>(false);
|
|
||||||
const floatingArrow = ref(null);
|
|
||||||
|
|
||||||
const reference = ref<HTMLElement | null>(null);
|
const callWithdraw = (amount: string) => {
|
||||||
const floating = ref<HTMLElement | null>(null);
|
emit("depositWithdrawn", amount);
|
||||||
const infoText = ref<HTMLElement | null>(null);
|
|
||||||
|
|
||||||
// Debounce methods
|
|
||||||
const handleInputEvent = (event: any): void => {
|
|
||||||
const { value } = event.target;
|
|
||||||
|
|
||||||
if (decimalCount(String(value)) > 2) {
|
|
||||||
validDecimals.value = false;
|
|
||||||
enableConfirmButton.value = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
validDecimals.value = true;
|
|
||||||
|
|
||||||
if (value > remaining.value) {
|
|
||||||
validWithdrawAmount.value = false;
|
|
||||||
enableConfirmButton.value = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
validWithdrawAmount.value = true;
|
|
||||||
enableConfirmButton.value = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
const callWithdraw = () => {
|
|
||||||
emit("depositWithdrawn", withdrawAmount.value);
|
|
||||||
};
|
|
||||||
|
|
||||||
watch(enableConfirmButton, (): void => {
|
|
||||||
if (!enableConfirmButton.value) {
|
|
||||||
withdrawButtonOpacity.value = 0.7;
|
|
||||||
withdrawButtonCursor.value = "not-allowed";
|
|
||||||
} else {
|
|
||||||
withdrawButtonOpacity.value = 1;
|
|
||||||
withdrawButtonCursor.value = "pointer";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
watch(withdrawAmount, (): void => {
|
|
||||||
if (!withdrawAmount.value || !enableConfirmButton.value) {
|
|
||||||
withdrawButtonOpacity.value = 0.7;
|
|
||||||
withdrawButtonCursor.value = "not-allowed";
|
|
||||||
} else {
|
|
||||||
withdrawButtonOpacity.value = 1;
|
|
||||||
withdrawButtonCursor.value = "pointer";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const getRemaining = (): number => {
|
|
||||||
if (props.validDeposits.length > 0) {
|
|
||||||
// in this release only the BRL token is being used.
|
|
||||||
const deposit = props.validDeposits[0];
|
|
||||||
remaining.value = deposit ? deposit.remaining : 0;
|
|
||||||
return deposit ? deposit.remaining : 0;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
const getExplorer = (): string => {
|
|
||||||
return user.networkName.value == NetworkEnum.sepolia
|
|
||||||
? "Etherscan"
|
|
||||||
: "Polygonscan";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const showInitialItems = (): void => {
|
const showInitialItems = (): void => {
|
||||||
@@ -103,10 +31,7 @@ const showInitialItems = (): void => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const openEtherscanUrl = (transactionHash: string): void => {
|
const openEtherscanUrl = (transactionHash: string): void => {
|
||||||
const networkUrl =
|
const networkUrl = user.network.value.blockExplorers?.default.url;
|
||||||
user.networkName.value == NetworkEnum.sepolia
|
|
||||||
? "sepolia.etherscan.io"
|
|
||||||
: "mumbai.polygonscan.com";
|
|
||||||
const url = `https://${networkUrl}/tx/${transactionHash}`;
|
const url = `https://${networkUrl}/tx/${transactionHash}`;
|
||||||
window.open(url, "_blank");
|
window.open(url, "_blank");
|
||||||
};
|
};
|
||||||
@@ -118,31 +43,6 @@ const loadMore = (): void => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const getEventName = (event: string | undefined): string => {
|
|
||||||
if (!event) return "Desconhecido";
|
|
||||||
|
|
||||||
const possibleEventName: { [key: string]: string } = {
|
|
||||||
DepositAdded: "Oferta",
|
|
||||||
LockAdded: "Reserva",
|
|
||||||
LockReleased: "Compra",
|
|
||||||
DepositWithdrawn: "Retirada",
|
|
||||||
};
|
|
||||||
|
|
||||||
return possibleEventName[event];
|
|
||||||
};
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
useFloating(reference, floating, {
|
|
||||||
placement: "right",
|
|
||||||
middleware: [
|
|
||||||
offset(10),
|
|
||||||
flip(),
|
|
||||||
shift(),
|
|
||||||
arrow({ element: floatingArrow }),
|
|
||||||
],
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// watch props changes
|
// watch props changes
|
||||||
watch(props, async (): Promise<void> => {
|
watch(props, async (): Promise<void> => {
|
||||||
const itemsToShowQty = itemsToShow.value.length;
|
const itemsToShowQty = itemsToShow.value.length;
|
||||||
@@ -167,179 +67,23 @@ showInitialItems();
|
|||||||
<SpinnerComponent width="8" height="8"></SpinnerComponent>
|
<SpinnerComponent width="8" height="8"></SpinnerComponent>
|
||||||
</div>
|
</div>
|
||||||
<div class="main-container max-w-md" v-else>
|
<div class="main-container max-w-md" v-else>
|
||||||
<div
|
<BalanceCard
|
||||||
class="w-full bg-white p-4 sm:p-6 rounded-lg"
|
|
||||||
v-if="props.validDeposits.length > 0"
|
v-if="props.validDeposits.length > 0"
|
||||||
>
|
:valid-deposits="props.validDeposits"
|
||||||
<div class="flex justify-between items-center">
|
:active-lock-amount="activeLockAmount"
|
||||||
<div>
|
:selected-token="user.selectedToken.value"
|
||||||
<p class="text-sm leading-5 font-medium text-gray-600">
|
@withdraw="callWithdraw"
|
||||||
Saldo disponível
|
|
||||||
</p>
|
|
||||||
<p class="text-xl leading-7 font-semibold text-gray-900">
|
|
||||||
{{ getRemaining() }} {{ user.selectedToken.value }}
|
|
||||||
</p>
|
|
||||||
<div class="flex gap-2 w-32 sm:w-56" v-if="activeLockAmount != 0">
|
|
||||||
<span class="text-xs font-normal text-gray-400" ref="infoText">{{
|
|
||||||
`com ${activeLockAmount.toFixed(2)} ${
|
|
||||||
user.selectedToken.value
|
|
||||||
} em lock`
|
|
||||||
}}</span>
|
|
||||||
<div
|
|
||||||
class="absolute mt-[2px] md-view"
|
|
||||||
:style="{ left: `${(infoText?.clientWidth ?? 108) + 4}px` }"
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
alt="info image"
|
|
||||||
src="@/assets/info.svg?url"
|
|
||||||
aria-describedby="tooltip"
|
|
||||||
ref="reference"
|
|
||||||
@mouseover="showInfoTooltip = true"
|
|
||||||
@mouseout="showInfoTooltip = false"
|
|
||||||
/>
|
/>
|
||||||
<div
|
|
||||||
role="tooltip"
|
|
||||||
ref="floating"
|
|
||||||
class="w-56 z-50 tooltip md-view"
|
|
||||||
v-if="showInfoTooltip"
|
|
||||||
>
|
|
||||||
Valor “em lock” significa que a quantia está aguardando
|
|
||||||
confirmação de compra e só estará disponível para saque caso a
|
|
||||||
transação expire.
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div v-show="!isCollapsibleOpen" class="flex justify-end items-center">
|
|
||||||
<div
|
|
||||||
class="flex gap-2 cursor-pointer items-center justify-self-center border-2 p-2 border-amber-300 rounded-md"
|
|
||||||
@click="[(isCollapsibleOpen = true)]"
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
alt="Withdraw image"
|
|
||||||
src="@/assets/withdraw.svg?url"
|
|
||||||
class="w-3 h-3 sm:w-4 sm:h-4"
|
|
||||||
/>
|
|
||||||
<span class="last-release-info">Sacar</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="pt-5">
|
|
||||||
<div v-show="isCollapsibleOpen" class="py-2 w-100">
|
|
||||||
<p class="text-sm leading-5 font-medium">Valor do saque</p>
|
|
||||||
<input
|
|
||||||
type="number"
|
|
||||||
name=""
|
|
||||||
@input="debounce(handleInputEvent, 500)($event)"
|
|
||||||
placeholder="0"
|
|
||||||
class="text-2xl text-gray-900 w-full outline-none"
|
|
||||||
v-model="withdrawAmount"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div class="flex justify-center" v-if="!validDecimals">
|
|
||||||
<span class="text-red-500 font-normal text-sm"
|
|
||||||
>Por favor utilize no máximo 2 casas decimais</span
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
<div class="flex justify-center" v-else-if="!validWithdrawAmount">
|
|
||||||
<span class="text-red-500 font-normal text-sm"
|
|
||||||
>Saldo insuficiente</span
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
<hr v-show="isCollapsibleOpen" class="pb-3" />
|
|
||||||
<div
|
|
||||||
v-show="isCollapsibleOpen"
|
|
||||||
class="flex justify-between items-center"
|
|
||||||
>
|
|
||||||
<h1
|
|
||||||
@click="[(isCollapsibleOpen = false)]"
|
|
||||||
class="text-black font-medium cursor-pointer"
|
|
||||||
>
|
|
||||||
Cancelar
|
|
||||||
</h1>
|
|
||||||
|
|
||||||
<div
|
<TransactionCard
|
||||||
class="withdraw-button flex gap-2 items-center justify-self-center border-2 p-2 border-amber-300 rounded-md"
|
|
||||||
@click="callWithdraw"
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
alt="Withdraw image"
|
|
||||||
src="@/assets/withdraw.svg?url"
|
|
||||||
class="w-3 h-3 sm:w-4 sm:h-4"
|
|
||||||
/>
|
|
||||||
<span class="last-release-info">Sacar</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
class="w-full bg-white p-4 sm:p-6 rounded-lg"
|
|
||||||
v-for="item in itemsToShow"
|
v-for="item in itemsToShow"
|
||||||
:key="item.blockNumber"
|
:key="item.blockNumber"
|
||||||
>
|
:selected-token="user.selectedToken.value"
|
||||||
<div class="item-container">
|
:transaction="item"
|
||||||
<div class="flex flex-col self-start">
|
:network-name="user.network.value.name"
|
||||||
<span class="text-xs sm:text-sm leading-5 font-medium text-gray-600">
|
@open-explorer="openEtherscanUrl"
|
||||||
{{ getEventName(item.event) }}
|
|
||||||
</span>
|
|
||||||
<span
|
|
||||||
class="text-xl sm:text-xl leading-7 font-semibold text-gray-900"
|
|
||||||
>
|
|
||||||
{{ item.amount }}
|
|
||||||
<!-- {{ getTokenByAddress(item.token) }} -->
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="flex flex-col items-center justify-center">
|
|
||||||
<div
|
|
||||||
class="bg-amber-300 status-text"
|
|
||||||
v-if="getEventName(item.event) == 'Reserva' && item.lockStatus == 1"
|
|
||||||
>
|
|
||||||
Em Aberto
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
class="bg-[#94A3B8] status-text"
|
|
||||||
v-if="getEventName(item.event) == 'Reserva' && item.lockStatus == 2"
|
|
||||||
>
|
|
||||||
Expirado
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
class="bg-emerald-300 status-text"
|
|
||||||
v-if="
|
|
||||||
(getEventName(item.event) == 'Reserva' && item.lockStatus == 3) ||
|
|
||||||
getEventName(item.event) != 'Reserva'
|
|
||||||
"
|
|
||||||
>
|
|
||||||
Finalizado
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
class="flex gap-2 cursor-pointer items-center justify-self-center w-full"
|
|
||||||
@click="openEtherscanUrl(item.transactionHash)"
|
|
||||||
v-if="getEventName(item.event) != 'Reserva' || item.lockStatus != 1"
|
|
||||||
>
|
|
||||||
<span class="last-release-info">{{ getExplorer() }}</span>
|
|
||||||
<img
|
|
||||||
alt="Redirect image"
|
|
||||||
src="@/assets/redirect.svg?url"
|
|
||||||
class="w-3 h-3 sm:w-4 sm:h-4"
|
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
class="flex gap-2 justify-self-center w-full"
|
|
||||||
v-if="getEventName(item.event) == 'Reserva' && item.lockStatus == 1"
|
|
||||||
>
|
|
||||||
<RouterLink
|
|
||||||
:to="{
|
|
||||||
name: 'home',
|
|
||||||
force: true,
|
|
||||||
state: { lockID: item.transactionID },
|
|
||||||
}"
|
|
||||||
class="router-button"
|
|
||||||
>Continuar</RouterLink
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div
|
<div
|
||||||
class="flex flex-col justify-center items-center w-full mt-2 gap-2"
|
class="flex flex-col justify-center items-center w-full mt-2 gap-2"
|
||||||
v-if="
|
v-if="
|
||||||
@@ -349,14 +93,14 @@ showInitialItems();
|
|||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="text-white font-semibold"
|
class="text-white font-semibold border-2 border-amber-300 rounded-lg px-4 py-2 hover:bg-amber-300/10 transition-colors cursor-pointer"
|
||||||
@click="loadMore()"
|
@click="loadMore()"
|
||||||
>
|
>
|
||||||
Carregar mais
|
Carregar mais
|
||||||
</button>
|
</button>
|
||||||
<span class="text-gray-300">
|
<span class="text-gray-300 text-sm">
|
||||||
({{ itemsToShow.length }} de {{ props.walletTransactions.length }}
|
{{ itemsToShow.length }} de {{ props.walletTransactions.length }}
|
||||||
transações )
|
transações
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -367,63 +111,5 @@ showInitialItems();
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.page {
|
/* Minimal styles - most styles moved to child components */
|
||||||
@apply flex flex-col items-center justify-center w-full mt-16;
|
|
||||||
}
|
|
||||||
|
|
||||||
p {
|
|
||||||
@apply text-gray-900;
|
|
||||||
}
|
|
||||||
|
|
||||||
.text-container {
|
|
||||||
@apply flex flex-col items-center justify-center gap-4;
|
|
||||||
}
|
|
||||||
|
|
||||||
.item-container {
|
|
||||||
@apply flex justify-between items-center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.status-text {
|
|
||||||
@apply text-xs sm:text-base font-medium text-gray-900 rounded-lg text-center mb-2 px-2 py-1 mt-4;
|
|
||||||
}
|
|
||||||
.text {
|
|
||||||
@apply text-white text-center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.grid-container {
|
|
||||||
@apply grid grid-cols-4 grid-flow-row items-center px-8 py-6 gap-4 rounded-lg shadow-md shadow-gray-600 backdrop-blur-md mt-10 w-auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.last-release-info {
|
|
||||||
@apply font-medium text-xs sm:text-sm text-gray-900 justify-self-center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tooltip {
|
|
||||||
@apply bg-white text-gray-900 font-medium text-xs md:text-base px-3 py-2 rounded border-2 border-emerald-500 left-5 top-[-3rem];
|
|
||||||
}
|
|
||||||
|
|
||||||
.router-button {
|
|
||||||
@apply rounded-lg border-amber-300 border-2 px-3 py-2 text-gray-900 font-semibold sm:text-base text-xs hover:bg-transparent w-full text-center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.withdraw-button {
|
|
||||||
opacity: v-bind(withdrawButtonOpacity);
|
|
||||||
cursor: v-bind(withdrawButtonCursor);
|
|
||||||
}
|
|
||||||
|
|
||||||
input[type="number"] {
|
|
||||||
appearance: textfield;
|
|
||||||
-moz-appearance: textfield;
|
|
||||||
}
|
|
||||||
|
|
||||||
input[type="number"]::-webkit-inner-spin-button,
|
|
||||||
input[type="number"]::-webkit-outer-spin-button {
|
|
||||||
-webkit-appearance: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media screen and (max-width: 640px) {
|
|
||||||
.md-view {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
124
src/components/ListingComponent/TransactionCard.vue
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { WalletTransaction } from "@/model/WalletTransaction";
|
||||||
|
import { TokenEnum } from "@/model/NetworkEnum";
|
||||||
|
import { computed } from "vue";
|
||||||
|
import StatusBadge, { type StatusType } from "../ui/StatusBadge.vue";
|
||||||
|
import { Networks } from "@/config/networks";
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
transaction: WalletTransaction;
|
||||||
|
networkName: keyof typeof Networks;
|
||||||
|
selectedToken: TokenEnum;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
openExplorer: [transactionHash: string];
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const eventName = computed(() => {
|
||||||
|
if (!props.transaction.event) return "Desconhecido";
|
||||||
|
|
||||||
|
const possibleEventName: { [key: string]: string } = {
|
||||||
|
DepositAdded: "Oferta",
|
||||||
|
LockAdded: "Reserva",
|
||||||
|
LockReleased: "Compra",
|
||||||
|
DepositWithdrawn: "Retirada",
|
||||||
|
};
|
||||||
|
|
||||||
|
return possibleEventName[props.transaction.event] || "Desconhecido";
|
||||||
|
});
|
||||||
|
|
||||||
|
const explorerName = computed(() => {
|
||||||
|
return Networks[props.networkName].blockExplorers?.default.name;
|
||||||
|
});
|
||||||
|
|
||||||
|
const statusType = computed((): StatusType => {
|
||||||
|
if (eventName.value === "Reserva") {
|
||||||
|
switch (props.transaction.lockStatus) {
|
||||||
|
case 1:
|
||||||
|
return "open";
|
||||||
|
case 2:
|
||||||
|
return "expired";
|
||||||
|
case 3:
|
||||||
|
return "completed";
|
||||||
|
default:
|
||||||
|
return "completed";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "completed";
|
||||||
|
});
|
||||||
|
|
||||||
|
const showExplorerLink = computed(() => {
|
||||||
|
return eventName.value !== "Reserva" || props.transaction.lockStatus !== 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
const showContinueButton = computed(() => {
|
||||||
|
return eventName.value === "Reserva" && props.transaction.lockStatus === 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleExplorerClick = () => {
|
||||||
|
emit("openExplorer", props.transaction.transactionHash);
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="w-full bg-white p-4 sm:p-6 rounded-lg">
|
||||||
|
<div class="item-container">
|
||||||
|
<div class="flex flex-col self-start">
|
||||||
|
<span class="text-xs sm:text-sm leading-5 font-medium text-gray-600">
|
||||||
|
{{ eventName }}
|
||||||
|
</span>
|
||||||
|
<span class="text-xl sm:text-xl leading-7 font-semibold text-gray-900">
|
||||||
|
{{ transaction.amount }} {{ selectedToken }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-col items-center justify-center">
|
||||||
|
<div class="mb-2 mt-4">
|
||||||
|
<StatusBadge :status="statusType" />
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
v-if="showExplorerLink"
|
||||||
|
class="flex gap-2 cursor-pointer items-center justify-self-center w-full"
|
||||||
|
@click="handleExplorerClick"
|
||||||
|
>
|
||||||
|
<span class="last-release-info">{{ explorerName }}</span>
|
||||||
|
<img
|
||||||
|
alt="Redirect image"
|
||||||
|
src="@/assets/redirect.svg?url"
|
||||||
|
class="w-3 h-3 sm:w-4 sm:h-4"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
v-if="showContinueButton"
|
||||||
|
class="flex gap-2 justify-self-center w-full"
|
||||||
|
>
|
||||||
|
<RouterLink
|
||||||
|
:to="{
|
||||||
|
name: 'home',
|
||||||
|
force: true,
|
||||||
|
state: { lockID: transaction.transactionID },
|
||||||
|
}"
|
||||||
|
class="router-button"
|
||||||
|
>
|
||||||
|
Continuar
|
||||||
|
</RouterLink>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.item-container {
|
||||||
|
@apply flex justify-between items-center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.last-release-info {
|
||||||
|
@apply font-medium text-xs sm:text-sm text-gray-900 justify-self-center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.router-button {
|
||||||
|
@apply rounded-lg border-amber-300 border-2 px-3 py-2 text-gray-900 font-semibold sm:text-base text-xs hover:bg-transparent w-full text-center;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed } from "vue";
|
import { ref, computed } from "vue";
|
||||||
import { useUser } from "@/composables/useUser";
|
import { useUser } from "@/composables/useUser";
|
||||||
import CustomButton from "@/components/CustomButton/CustomButton.vue";
|
import CustomButton from "@/components/ui/CustomButton.vue";
|
||||||
import { postProcessKey } from "@/utils/pixKeyFormat";
|
import { postProcessKey } from "@/utils/pixKeyFormat";
|
||||||
import { TokenEnum } from "@/model/NetworkEnum";
|
import { TokenEnum } from "@/model/NetworkEnum";
|
||||||
import { getTokenImage } from "@/utils/imagesPath";
|
import { getTokenImage } from "@/utils/imagesPath";
|
||||||
@@ -71,7 +71,7 @@ const handleSubmit = (e: Event): void => {
|
|||||||
|
|
||||||
const data: Participant = {
|
const data: Participant = {
|
||||||
offer: offer.value,
|
offer: offer.value,
|
||||||
chainID: user.networkId.value,
|
chainID: user.network.value.id,
|
||||||
identification: processedIdentification,
|
identification: processedIdentification,
|
||||||
bankIspb: selectedBank.value?.ISPB,
|
bankIspb: selectedBank.value?.ISPB,
|
||||||
accountType: accountType.value,
|
accountType: accountType.value,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref } from "vue";
|
import { ref } from "vue";
|
||||||
import { useUser } from "@/composables/useUser";
|
import { useUser } from "@/composables/useUser";
|
||||||
import CustomButton from "@/components/CustomButton/CustomButton.vue";
|
import CustomButton from "@/components/ui/CustomButton.vue";
|
||||||
import { debounce } from "@/utils/debounce";
|
import { debounce } from "@/utils/debounce";
|
||||||
import { decimalCount } from "@/utils/decimalCount";
|
import { decimalCount } from "@/utils/decimalCount";
|
||||||
import { getTokenImage } from "@/utils/imagesPath";
|
import { getTokenImage } from "@/utils/imagesPath";
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import CustomButton from "@/components/CustomButton/CustomButton.vue";
|
import CustomButton from "@/components/ui/CustomButton.vue";
|
||||||
|
|
||||||
// Emits
|
// Emits
|
||||||
const emit = defineEmits(["sendNetwork"]);
|
const emit = defineEmits(["sendNetwork"]);
|
||||||
|
|||||||
@@ -2,10 +2,8 @@
|
|||||||
import { ref, watch } from "vue";
|
import { ref, watch } from "vue";
|
||||||
import { useUser } from "@/composables/useUser";
|
import { useUser } from "@/composables/useUser";
|
||||||
import { onClickOutside } from "@vueuse/core";
|
import { onClickOutside } from "@vueuse/core";
|
||||||
import { NetworkEnum } from "@/model/NetworkEnum";
|
|
||||||
import { getNetworkImage } from "@/utils/imagesPath";
|
import { getNetworkImage } from "@/utils/imagesPath";
|
||||||
import { Networks } from "@/model/Networks";
|
import { Networks } from "@/config/networks";
|
||||||
|
|
||||||
import { useOnboard } from "@web3-onboard/vue";
|
import { useOnboard } from "@web3-onboard/vue";
|
||||||
|
|
||||||
import ChevronDown from "@/assets/chevronDown.svg";
|
import ChevronDown from "@/assets/chevronDown.svg";
|
||||||
@@ -13,10 +11,12 @@ import TwitterIcon from "@/assets/twitterIcon.svg";
|
|||||||
import LinkedinIcon from "@/assets/linkedinIcon.svg";
|
import LinkedinIcon from "@/assets/linkedinIcon.svg";
|
||||||
import GithubIcon from "@/assets/githubIcon.svg";
|
import GithubIcon from "@/assets/githubIcon.svg";
|
||||||
import { connectProvider } from "@/blockchain/provider";
|
import { connectProvider } from "@/blockchain/provider";
|
||||||
|
import { DEFAULT_NETWORK } from "@/config/networks";
|
||||||
|
import type { NetworkConfig } from "@/model/NetworkEnum";
|
||||||
|
|
||||||
// Use the new composable
|
// Use the new composable
|
||||||
const user = useUser();
|
const user = useUser();
|
||||||
const { walletAddress, sellerView, networkId } = user;
|
const { walletAddress, sellerView, network } = user;
|
||||||
|
|
||||||
const menuOpenToggle = ref<boolean>(false);
|
const menuOpenToggle = ref<boolean>(false);
|
||||||
const infoMenuOpenToggle = ref<boolean>(false);
|
const infoMenuOpenToggle = ref<boolean>(false);
|
||||||
@@ -40,20 +40,20 @@ watch(connectedWallet, async (newVal: any) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
watch(connectedChain, (newVal: any) => {
|
watch(connectedChain, (newVal: any) => {
|
||||||
// Check if connected chain is valid, otherwise default to Sepolia (NetworkEnum.SEPOLIA)
|
// Check if connected chain is valid, otherwise default to Sepolia
|
||||||
if (
|
if (
|
||||||
!newVal ||
|
!newVal ||
|
||||||
!Object.values(Networks).some(
|
!Object.values(Networks).some(
|
||||||
(network) => Number(network.chainId) === Number(newVal.id)
|
(network) => network.id === Number(newVal.id)
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
console.log(
|
console.log(
|
||||||
"Invalid or unsupported network detected, defaulting to Sepolia"
|
"Invalid or unsupported network detected, defaulting to Sepolia"
|
||||||
);
|
);
|
||||||
user.setNetworkId(user.networkId.value);
|
user.setNetwork(DEFAULT_NETWORK);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
user.setNetworkId(newVal?.id);
|
user.setNetworkById(newVal?.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
const formatWalletAddress = (): string => {
|
const formatWalletAddress = (): string => {
|
||||||
@@ -78,14 +78,15 @@ const closeMenu = (): void => {
|
|||||||
menuOpenToggle.value = false;
|
menuOpenToggle.value = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
const networkChange = async (network: NetworkEnum): Promise<void> => {
|
const networkChange = async (network: NetworkConfig): Promise<void> => {
|
||||||
currencyMenuOpenToggle.value = false;
|
currencyMenuOpenToggle.value = false;
|
||||||
|
const chainId = network.id.toString(16)
|
||||||
try {
|
try {
|
||||||
await setChain({
|
await setChain({
|
||||||
chainId: Networks[network].chainId,
|
chainId: `0x${chainId}`,
|
||||||
wallet: connectedWallet.value?.label || "",
|
wallet: connectedWallet.value?.label || "",
|
||||||
});
|
});
|
||||||
user.setNetworkId(network);
|
user.setNetwork(network);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("Error changing network", error);
|
console.log("Error changing network", error);
|
||||||
}
|
}
|
||||||
@@ -258,7 +259,7 @@ onClickOutside(infoMenuRef, () => {
|
|||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
alt="Choosed network image"
|
alt="Choosed network image"
|
||||||
:src="getNetworkImage(NetworkEnum[user.networkName.value])"
|
:src="getNetworkImage(network.name)"
|
||||||
height="24"
|
height="24"
|
||||||
width="24"
|
width="24"
|
||||||
/>
|
/>
|
||||||
@@ -267,9 +268,7 @@ onClickOutside(infoMenuRef, () => {
|
|||||||
:class="{ '!text-gray-900': currencyMenuOpenToggle }"
|
:class="{ '!text-gray-900': currencyMenuOpenToggle }"
|
||||||
>
|
>
|
||||||
{{
|
{{
|
||||||
Networks[user.networkName.value]
|
user.network.value.name || "Invalid Chain"
|
||||||
? Networks[user.networkName.value].chainName
|
|
||||||
: "Invalid Chain"
|
|
||||||
}}
|
}}
|
||||||
</span>
|
</span>
|
||||||
<div
|
<div
|
||||||
@@ -292,20 +291,20 @@ onClickOutside(infoMenuRef, () => {
|
|||||||
class="mt-2 bg-white rounded-md border border-gray-300 drop-shadow-md shadow-md overflow-clip"
|
class="mt-2 bg-white rounded-md border border-gray-300 drop-shadow-md shadow-md overflow-clip"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
v-for="(chainData, network) in Networks"
|
v-for="network in Networks"
|
||||||
:key="network"
|
:key="network.id"
|
||||||
class="menu-button p-4 gap-2 cursor-pointer hover:bg-gray-200 flex items-center !justify-start whitespace-nowrap transition-colors duration-150 ease-in-out"
|
class="menu-button p-4 gap-2 cursor-pointer hover:bg-gray-200 flex items-center !justify-start whitespace-nowrap transition-colors duration-150 ease-in-out"
|
||||||
@click="networkChange(network)"
|
@click="networkChange(network)"
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
:alt="chainData.chainName + ' image'"
|
:alt="network.name + ' image'"
|
||||||
width="20"
|
width="20"
|
||||||
height="20"
|
height="20"
|
||||||
:src="getNetworkImage(NetworkEnum[network])"
|
:src="getNetworkImage(network.name)"
|
||||||
class="mr-2 ml-1"
|
class="mr-2 ml-1"
|
||||||
/>
|
/>
|
||||||
<span class="text-gray-900 font-semibold text-sm">
|
<span class="text-gray-900 font-semibold text-sm">
|
||||||
{{ chainData.chainName }}
|
{{ network.name }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="w-full flex justify-center">
|
<div class="w-full flex justify-center">
|
||||||
@@ -462,19 +461,19 @@ onClickOutside(infoMenuRef, () => {
|
|||||||
<div class="pl-4 mt-2 h-full">
|
<div class="pl-4 mt-2 h-full">
|
||||||
<div class="bg-white rounded-md z-10 h-full">
|
<div class="bg-white rounded-md z-10 h-full">
|
||||||
<div
|
<div
|
||||||
v-for="(chainData, network) in Networks"
|
v-for="network in Networks"
|
||||||
:key="network"
|
:key="network.id"
|
||||||
class="menu-button gap-2 sm:px-4 rounded-md cursor-pointer py-2 px-4"
|
class="menu-button gap-2 sm:px-4 rounded-md cursor-pointer py-2 px-4"
|
||||||
@click="networkChange(network)"
|
@click="networkChange(network)"
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
:alt="chainData.chainName + 'image'"
|
:alt="network.name + 'image'"
|
||||||
width="20"
|
width="20"
|
||||||
height="20"
|
height="20"
|
||||||
:src="getNetworkImage(NetworkEnum[network])"
|
:src="getNetworkImage(network.name)"
|
||||||
/>
|
/>
|
||||||
<span class="text-gray-900 py-4 text-end font-bold text-sm">
|
<span class="text-gray-900 py-4 text-end font-bold text-sm">
|
||||||
{{ chainData.chainName }}
|
{{ network.name }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
208
src/components/ui/AmountInput.vue
Normal file
@@ -0,0 +1,208 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, watch, computed } from "vue";
|
||||||
|
import { TokenEnum } from "@/model/NetworkEnum";
|
||||||
|
import { decimalCount } from "@/utils/decimalCount";
|
||||||
|
import { debounce } from "@/utils/debounce";
|
||||||
|
import TokenSelector from "./TokenSelector.vue";
|
||||||
|
import ErrorMessage from "./ErrorMessage.vue";
|
||||||
|
|
||||||
|
const props = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
modelValue: number;
|
||||||
|
selectedToken: TokenEnum;
|
||||||
|
placeholder?: string;
|
||||||
|
showTokenSelector?: boolean;
|
||||||
|
showConversion?: boolean;
|
||||||
|
conversionRate?: number;
|
||||||
|
minValue?: number;
|
||||||
|
maxValue?: number;
|
||||||
|
disabled?: boolean;
|
||||||
|
required?: boolean;
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
placeholder: "0",
|
||||||
|
showTokenSelector: true,
|
||||||
|
showConversion: true,
|
||||||
|
conversionRate: 1,
|
||||||
|
minValue: 0,
|
||||||
|
disabled: false,
|
||||||
|
required: false,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
"update:modelValue": [value: number];
|
||||||
|
"update:selectedToken": [token: TokenEnum];
|
||||||
|
error: [message: string | null];
|
||||||
|
valid: [isValid: boolean];
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const inputValue = ref<string>(String(props.modelValue || ""));
|
||||||
|
const validDecimals = ref(true);
|
||||||
|
const validRange = ref(true);
|
||||||
|
|
||||||
|
const convertedValue = computed(() => {
|
||||||
|
return (props.modelValue * props.conversionRate).toFixed(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
const errorMessage = computed(() => {
|
||||||
|
if (!validDecimals.value) {
|
||||||
|
return "Por favor utilize no máximo 2 casas decimais";
|
||||||
|
}
|
||||||
|
if (!validRange.value) {
|
||||||
|
if (props.minValue && props.modelValue < props.minValue) {
|
||||||
|
return `Valor mínimo: ${props.minValue}`;
|
||||||
|
}
|
||||||
|
if (props.maxValue && props.modelValue > props.maxValue) {
|
||||||
|
return `Valor máximo: ${props.maxValue}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
const isValid = computed(() => {
|
||||||
|
return validDecimals.value && validRange.value;
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleInput = (event: Event) => {
|
||||||
|
const target = event.target as HTMLInputElement;
|
||||||
|
const value = target.value;
|
||||||
|
inputValue.value = value;
|
||||||
|
|
||||||
|
const numValue = Number(value);
|
||||||
|
|
||||||
|
// Validar decimais
|
||||||
|
if (decimalCount(value) > 2) {
|
||||||
|
validDecimals.value = false;
|
||||||
|
emit("error", "Por favor utilize no máximo 2 casas decimais");
|
||||||
|
emit("valid", false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
validDecimals.value = true;
|
||||||
|
|
||||||
|
// Validar range
|
||||||
|
if (props.minValue !== undefined && numValue < props.minValue) {
|
||||||
|
validRange.value = false;
|
||||||
|
emit("error", `Valor mínimo: ${props.minValue}`);
|
||||||
|
emit("valid", false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (props.maxValue !== undefined && numValue > props.maxValue) {
|
||||||
|
validRange.value = false;
|
||||||
|
emit("error", `Valor máximo: ${props.maxValue}`);
|
||||||
|
emit("valid", false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
validRange.value = true;
|
||||||
|
|
||||||
|
emit("update:modelValue", numValue);
|
||||||
|
emit("error", null);
|
||||||
|
emit("valid", true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const debouncedHandleInput = debounce(handleInput, 500);
|
||||||
|
|
||||||
|
const handleTokenChange = (token: TokenEnum) => {
|
||||||
|
emit("update:selectedToken", token);
|
||||||
|
};
|
||||||
|
|
||||||
|
watch(() => props.modelValue, (newVal) => {
|
||||||
|
if (newVal !== Number(inputValue.value)) {
|
||||||
|
inputValue.value = String(newVal || "");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="amount-input-container">
|
||||||
|
<div class="input-row">
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
:value="inputValue"
|
||||||
|
:placeholder="placeholder"
|
||||||
|
:disabled="disabled"
|
||||||
|
:required="required"
|
||||||
|
class="amount-input"
|
||||||
|
:class="{
|
||||||
|
'font-semibold text-xl': modelValue > 0,
|
||||||
|
'has-error': !isValid,
|
||||||
|
}"
|
||||||
|
step="0.01"
|
||||||
|
@input="debouncedHandleInput"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<TokenSelector
|
||||||
|
v-if="showTokenSelector"
|
||||||
|
:model-value="selectedToken"
|
||||||
|
:disabled="disabled"
|
||||||
|
size="md"
|
||||||
|
@update:model-value="handleTokenChange"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div v-else class="token-display">
|
||||||
|
{{ selectedToken }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="divider"></div>
|
||||||
|
|
||||||
|
<div class="info-row">
|
||||||
|
<p v-if="showConversion" class="conversion-text">
|
||||||
|
~ R$ {{ convertedValue }}
|
||||||
|
</p>
|
||||||
|
<slot name="extra-info"></slot>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<ErrorMessage
|
||||||
|
v-if="errorMessage"
|
||||||
|
:message="errorMessage"
|
||||||
|
type="error"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.amount-input-container {
|
||||||
|
@apply flex flex-col w-full gap-2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-row {
|
||||||
|
@apply flex justify-between items-center w-full gap-4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.amount-input {
|
||||||
|
@apply border-none outline-none text-lg text-gray-900 flex-1 bg-transparent;
|
||||||
|
appearance: textfield;
|
||||||
|
-moz-appearance: textfield;
|
||||||
|
}
|
||||||
|
|
||||||
|
.amount-input::-webkit-inner-spin-button,
|
||||||
|
.amount-input::-webkit-outer-spin-button {
|
||||||
|
-webkit-appearance: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.amount-input:disabled {
|
||||||
|
@apply opacity-50 cursor-not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.amount-input.has-error {
|
||||||
|
@apply text-red-500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.token-display {
|
||||||
|
@apply flex items-center px-3 py-2 bg-gray-300 rounded-3xl min-w-fit text-gray-900 font-medium;
|
||||||
|
}
|
||||||
|
|
||||||
|
.divider {
|
||||||
|
@apply w-full border-b border-gray-300 my-2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-row {
|
||||||
|
@apply flex justify-between items-center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.conversion-text {
|
||||||
|
@apply text-gray-500 font-normal text-sm;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
137
src/components/ui/BankSelector.vue
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed } from "vue";
|
||||||
|
import bankList from "@/utils/files/isbpList.json";
|
||||||
|
|
||||||
|
export interface Bank {
|
||||||
|
ISPB: string;
|
||||||
|
longName: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const props = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
modelValue: string | null;
|
||||||
|
disabled?: boolean;
|
||||||
|
placeholder?: string;
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
disabled: false,
|
||||||
|
placeholder: "Busque e selecione seu banco",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
"update:modelValue": [value: string];
|
||||||
|
change: [bank: Bank];
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const bankItems = computed(() => {
|
||||||
|
return bankList.map((bank) => ({
|
||||||
|
value: bank.ISPB,
|
||||||
|
label: bank.longName,
|
||||||
|
bank: bank,
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
const selectedItem = computed(() => {
|
||||||
|
if (!props.modelValue) return null;
|
||||||
|
return bankItems.value.find((item) => item.value === props.modelValue);
|
||||||
|
});
|
||||||
|
|
||||||
|
const searchQuery = computed({
|
||||||
|
get: () => selectedItem.value?.label || "",
|
||||||
|
set: (value: string) => {
|
||||||
|
// Handled by input
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const filteredBanks = computed(() => {
|
||||||
|
if (!searchQuery.value) return [];
|
||||||
|
|
||||||
|
const query = searchQuery.value.toLowerCase();
|
||||||
|
return bankList
|
||||||
|
.filter((bank) => bank.longName.toLowerCase().includes(query))
|
||||||
|
.slice(0, 10);
|
||||||
|
});
|
||||||
|
|
||||||
|
const showBankList = computed(() => {
|
||||||
|
return filteredBanks.value.length > 0 && searchQuery.value.length > 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
const selectBank = (bank: Bank) => {
|
||||||
|
emit("update:modelValue", bank.ISPB);
|
||||||
|
emit("change", bank);
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="bank-selector">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
v-model="searchQuery"
|
||||||
|
:placeholder="placeholder"
|
||||||
|
:disabled="disabled"
|
||||||
|
class="bank-input"
|
||||||
|
autocomplete="off"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<transition name="dropdown-fade">
|
||||||
|
<div v-if="showBankList" class="bank-list">
|
||||||
|
<div
|
||||||
|
v-for="bank in filteredBanks"
|
||||||
|
:key="bank.ISPB"
|
||||||
|
class="bank-item"
|
||||||
|
@click="selectBank(bank)"
|
||||||
|
>
|
||||||
|
<span class="bank-name">{{ bank.longName }}</span>
|
||||||
|
<span class="bank-ispb">{{ bank.ISPB }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</transition>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.bank-selector {
|
||||||
|
@apply relative w-full;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bank-input {
|
||||||
|
@apply w-full px-4 py-3 border-none outline-none rounded-lg bg-white text-gray-900 text-sm;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bank-input:focus {
|
||||||
|
@apply ring-2 ring-indigo-800;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bank-input:disabled {
|
||||||
|
@apply opacity-50 cursor-not-allowed bg-gray-100;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bank-list {
|
||||||
|
@apply absolute top-full left-0 right-0 mt-2 bg-white rounded-lg border border-gray-300 shadow-lg z-50 max-h-64 overflow-y-auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bank-item {
|
||||||
|
@apply flex justify-between items-center px-4 py-3 cursor-pointer hover:bg-gray-100 transition-colors;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bank-name {
|
||||||
|
@apply text-gray-900 font-medium text-sm flex-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bank-ispb {
|
||||||
|
@apply text-gray-500 text-xs ml-2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Animação */
|
||||||
|
.dropdown-fade-enter-active,
|
||||||
|
.dropdown-fade-leave-active {
|
||||||
|
@apply transition-all duration-200;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-fade-enter-from,
|
||||||
|
.dropdown-fade-leave-to {
|
||||||
|
@apply opacity-0 -translate-y-2;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
161
src/components/ui/CustomButton.vue
Normal file
@@ -0,0 +1,161 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
export type ButtonVariant = "primary" | "secondary" | "outline" | "ghost";
|
||||||
|
export type ButtonSize = "sm" | "md" | "lg" | "xl";
|
||||||
|
|
||||||
|
const props = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
text: string;
|
||||||
|
isDisabled?: boolean;
|
||||||
|
variant?: ButtonVariant;
|
||||||
|
size?: ButtonSize;
|
||||||
|
icon?: string;
|
||||||
|
iconPosition?: "left" | "right";
|
||||||
|
fullWidth?: boolean;
|
||||||
|
loading?: boolean;
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
isDisabled: false,
|
||||||
|
variant: "primary",
|
||||||
|
size: "xl",
|
||||||
|
iconPosition: "left",
|
||||||
|
fullWidth: true,
|
||||||
|
loading: false,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const emit = defineEmits(["buttonClicked"]);
|
||||||
|
|
||||||
|
const handleClick = () => {
|
||||||
|
if (!props.isDisabled && !props.loading) {
|
||||||
|
emit("buttonClicked");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
:class="[
|
||||||
|
'button',
|
||||||
|
`variant-${variant}`,
|
||||||
|
`size-${size}`,
|
||||||
|
{ 'is-disabled': isDisabled || loading, 'full-width': fullWidth },
|
||||||
|
]"
|
||||||
|
:disabled="isDisabled || loading"
|
||||||
|
@click="handleClick"
|
||||||
|
>
|
||||||
|
<span v-if="loading" class="loader"></span>
|
||||||
|
<template v-else>
|
||||||
|
<img
|
||||||
|
v-if="icon && iconPosition === 'left'"
|
||||||
|
:src="icon"
|
||||||
|
:alt="`${text} icon`"
|
||||||
|
class="button-icon"
|
||||||
|
/>
|
||||||
|
<span class="button-text">{{ text }}</span>
|
||||||
|
<img
|
||||||
|
v-if="icon && iconPosition === 'right'"
|
||||||
|
:src="icon"
|
||||||
|
:alt="`${text} icon`"
|
||||||
|
class="button-icon"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.button {
|
||||||
|
@apply rounded-lg font-semibold transition-all duration-200 cursor-pointer flex items-center justify-center gap-2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button:hover:not(.is-disabled) {
|
||||||
|
@apply transform scale-[1.02];
|
||||||
|
}
|
||||||
|
|
||||||
|
.button.is-disabled {
|
||||||
|
@apply opacity-70 cursor-not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button.full-width {
|
||||||
|
@apply w-full;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Variantes */
|
||||||
|
.variant-primary {
|
||||||
|
@apply bg-amber-400 text-gray-900 border-2 border-amber-400;
|
||||||
|
}
|
||||||
|
|
||||||
|
.variant-primary:hover:not(.is-disabled) {
|
||||||
|
@apply bg-amber-500 border-amber-500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.variant-secondary {
|
||||||
|
@apply bg-gray-200 text-gray-900 border-2 border-gray-300;
|
||||||
|
}
|
||||||
|
|
||||||
|
.variant-secondary:hover:not(.is-disabled) {
|
||||||
|
@apply bg-gray-300 border-gray-400;
|
||||||
|
}
|
||||||
|
|
||||||
|
.variant-outline {
|
||||||
|
@apply bg-transparent text-gray-900 border-2 border-amber-400;
|
||||||
|
}
|
||||||
|
|
||||||
|
.variant-outline:hover:not(.is-disabled) {
|
||||||
|
@apply bg-amber-400/10;
|
||||||
|
}
|
||||||
|
|
||||||
|
.variant-ghost {
|
||||||
|
@apply bg-transparent text-gray-900 border-2 border-transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.variant-ghost:hover:not(.is-disabled) {
|
||||||
|
@apply bg-gray-100;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Tamanhos */
|
||||||
|
.size-sm {
|
||||||
|
@apply px-2 py-1 text-xs;
|
||||||
|
}
|
||||||
|
|
||||||
|
.size-sm .button-icon {
|
||||||
|
@apply w-3 h-3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.size-md {
|
||||||
|
@apply px-3 py-2 text-sm;
|
||||||
|
}
|
||||||
|
|
||||||
|
.size-md .button-icon {
|
||||||
|
@apply w-4 h-4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.size-lg {
|
||||||
|
@apply px-4 py-3 text-base;
|
||||||
|
}
|
||||||
|
|
||||||
|
.size-lg .button-icon {
|
||||||
|
@apply w-5 h-5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.size-xl {
|
||||||
|
@apply p-4 text-base;
|
||||||
|
}
|
||||||
|
|
||||||
|
.size-xl .button-icon {
|
||||||
|
@apply w-5 h-5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button-icon {
|
||||||
|
@apply flex-shrink-0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button-text {
|
||||||
|
@apply font-semibold;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Loader animation */
|
||||||
|
.loader {
|
||||||
|
@apply w-5 h-5 border-2 border-gray-900 border-t-transparent rounded-full animate-spin;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
248
src/components/ui/Dropdown.vue
Normal file
@@ -0,0 +1,248 @@
|
|||||||
|
<script setup lang="ts" generic="T">
|
||||||
|
import { ref, computed } from "vue";
|
||||||
|
import { onClickOutside } from "@vueuse/core";
|
||||||
|
import ChevronDown from "@/assets/chevronDown.svg";
|
||||||
|
|
||||||
|
export interface DropdownItem<T = any> {
|
||||||
|
value: T;
|
||||||
|
label: string;
|
||||||
|
icon?: string;
|
||||||
|
disabled?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const props = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
items: DropdownItem<T>[];
|
||||||
|
modelValue: T;
|
||||||
|
placeholder?: string;
|
||||||
|
searchable?: boolean;
|
||||||
|
disabled?: boolean;
|
||||||
|
size?: "sm" | "md" | "lg";
|
||||||
|
showIcon?: boolean;
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
placeholder: "Selecione...",
|
||||||
|
searchable: false,
|
||||||
|
disabled: false,
|
||||||
|
size: "md",
|
||||||
|
showIcon: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
"update:modelValue": [value: T];
|
||||||
|
change: [value: T];
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const isOpen = ref(false);
|
||||||
|
const searchQuery = ref("");
|
||||||
|
const dropdownRef = ref<HTMLElement | null>(null);
|
||||||
|
|
||||||
|
const selectedItem = computed(() => {
|
||||||
|
return props.items.find((item) => item.value === props.modelValue);
|
||||||
|
});
|
||||||
|
|
||||||
|
const filteredItems = computed(() => {
|
||||||
|
if (!props.searchable || !searchQuery.value) {
|
||||||
|
return props.items;
|
||||||
|
}
|
||||||
|
|
||||||
|
const query = searchQuery.value.toLowerCase();
|
||||||
|
return props.items.filter((item) =>
|
||||||
|
item.label.toLowerCase().includes(query)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
const toggleDropdown = () => {
|
||||||
|
if (!props.disabled) {
|
||||||
|
isOpen.value = !isOpen.value;
|
||||||
|
if (!isOpen.value) {
|
||||||
|
searchQuery.value = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const selectItem = (item: DropdownItem<T>) => {
|
||||||
|
if (!item.disabled) {
|
||||||
|
emit("update:modelValue", item.value);
|
||||||
|
emit("change", item.value);
|
||||||
|
isOpen.value = false;
|
||||||
|
searchQuery.value = "";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
onClickOutside(dropdownRef, () => {
|
||||||
|
isOpen.value = false;
|
||||||
|
searchQuery.value = "";
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div ref="dropdownRef" class="dropdown-container">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
:class="[
|
||||||
|
'dropdown-trigger',
|
||||||
|
`size-${size}`,
|
||||||
|
{ disabled: disabled, open: isOpen },
|
||||||
|
]"
|
||||||
|
@click="toggleDropdown"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
v-if="selectedItem?.icon && showIcon"
|
||||||
|
:src="selectedItem.icon"
|
||||||
|
:alt="selectedItem.label"
|
||||||
|
class="item-icon"
|
||||||
|
/>
|
||||||
|
<span class="selected-text">
|
||||||
|
{{ selectedItem?.label || placeholder }}
|
||||||
|
</span>
|
||||||
|
<ChevronDown
|
||||||
|
class="chevron"
|
||||||
|
:class="{ rotated: isOpen }"
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<transition name="dropdown-fade">
|
||||||
|
<div v-if="isOpen" class="dropdown-menu">
|
||||||
|
<input
|
||||||
|
v-if="searchable"
|
||||||
|
v-model="searchQuery"
|
||||||
|
type="text"
|
||||||
|
class="search-input"
|
||||||
|
placeholder="Buscar..."
|
||||||
|
@click.stop
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div class="items-container">
|
||||||
|
<div
|
||||||
|
v-for="item in filteredItems"
|
||||||
|
:key="String(item.value)"
|
||||||
|
:class="[
|
||||||
|
'dropdown-item',
|
||||||
|
{
|
||||||
|
selected: item.value === modelValue,
|
||||||
|
disabled: item.disabled,
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
@click="selectItem(item)"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
v-if="item.icon && showIcon"
|
||||||
|
:src="item.icon"
|
||||||
|
:alt="item.label"
|
||||||
|
class="item-icon"
|
||||||
|
/>
|
||||||
|
<span class="item-label">{{ item.label }}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="filteredItems.length === 0" class="no-results">
|
||||||
|
Nenhum resultado encontrado
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</transition>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.dropdown-container {
|
||||||
|
@apply relative inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-trigger {
|
||||||
|
@apply flex items-center gap-2 bg-gray-300 hover:bg-gray-200 rounded-3xl transition-colors cursor-pointer border-none outline-none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-trigger:focus {
|
||||||
|
@apply outline-2 outline-indigo-800;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-trigger.disabled {
|
||||||
|
@apply opacity-50 cursor-not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-trigger.disabled:hover {
|
||||||
|
@apply bg-gray-300;
|
||||||
|
}
|
||||||
|
|
||||||
|
.size-sm {
|
||||||
|
@apply px-2 py-1 text-sm;
|
||||||
|
}
|
||||||
|
|
||||||
|
.size-md {
|
||||||
|
@apply px-3 py-2 text-base;
|
||||||
|
}
|
||||||
|
|
||||||
|
.size-lg {
|
||||||
|
@apply px-4 py-3 text-lg;
|
||||||
|
}
|
||||||
|
|
||||||
|
.item-icon {
|
||||||
|
@apply sm:w-fit w-4 flex-shrink-0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.selected-text {
|
||||||
|
@apply text-gray-900 font-medium min-w-fit;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chevron {
|
||||||
|
@apply transition-transform duration-300 invert pr-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chevron.rotated {
|
||||||
|
@apply rotate-180;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-menu {
|
||||||
|
@apply absolute right-0 mt-2 bg-white rounded-xl border border-gray-300 shadow-md z-50 min-w-max w-full;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-input {
|
||||||
|
@apply w-full px-4 py-3 border-b border-gray-200 outline-none text-gray-900;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-input:focus {
|
||||||
|
@apply border-indigo-800;
|
||||||
|
}
|
||||||
|
|
||||||
|
.items-container {
|
||||||
|
@apply max-h-64 overflow-y-auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-item {
|
||||||
|
@apply flex items-center gap-2 px-4 py-4 cursor-pointer hover:bg-gray-300 transition-colors text-gray-900 font-semibold text-sm;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-item.selected {
|
||||||
|
@apply bg-gray-100;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-item.disabled {
|
||||||
|
@apply opacity-50 cursor-not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-item.disabled:hover {
|
||||||
|
@apply bg-transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.item-label {
|
||||||
|
@apply text-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
.no-results {
|
||||||
|
@apply px-4 py-6 text-center text-gray-500 text-sm;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Animação */
|
||||||
|
.dropdown-fade-enter-active,
|
||||||
|
.dropdown-fade-leave-active {
|
||||||
|
@apply transition-all duration-200;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-fade-enter-from,
|
||||||
|
.dropdown-fade-leave-to {
|
||||||
|
@apply opacity-0 -translate-y-2;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
55
src/components/ui/ErrorMessage.vue
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
export type ErrorType = "error" | "warning" | "info";
|
||||||
|
|
||||||
|
const props = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
message: string;
|
||||||
|
type?: ErrorType;
|
||||||
|
centered?: boolean;
|
||||||
|
icon?: boolean;
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
type: "error",
|
||||||
|
centered: true,
|
||||||
|
icon: false,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const colorClasses = {
|
||||||
|
error: "text-red-500",
|
||||||
|
warning: "text-amber-500",
|
||||||
|
info: "text-blue-500",
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div :class="['error-message-container', { centered: centered }]">
|
||||||
|
<div :class="['error-message', colorClasses[type]]">
|
||||||
|
<span v-if="icon" class="icon">⚠</span>
|
||||||
|
<span class="message">{{ message }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.error-message-container {
|
||||||
|
@apply flex w-full;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-message-container.centered {
|
||||||
|
@apply justify-center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-message {
|
||||||
|
@apply font-normal text-sm flex items-center gap-2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon {
|
||||||
|
@apply text-base;
|
||||||
|
}
|
||||||
|
|
||||||
|
.message {
|
||||||
|
@apply leading-tight;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
55
src/components/ui/FormCard.vue
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
export type FormCardPadding = "sm" | "md" | "lg";
|
||||||
|
|
||||||
|
const props = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
padding?: FormCardPadding;
|
||||||
|
fullWidth?: boolean;
|
||||||
|
noBorder?: boolean;
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
padding: "md",
|
||||||
|
fullWidth: true,
|
||||||
|
noBorder: false,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div
|
||||||
|
:class="[
|
||||||
|
'form-card',
|
||||||
|
`padding-${padding}`,
|
||||||
|
{ 'full-width': fullWidth, 'no-border': noBorder },
|
||||||
|
]"
|
||||||
|
>
|
||||||
|
<slot></slot>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.form-card {
|
||||||
|
@apply flex flex-col bg-white rounded-lg;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-card:not(.no-border) {
|
||||||
|
@apply border-y-10;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-card.full-width {
|
||||||
|
@apply w-full;
|
||||||
|
}
|
||||||
|
|
||||||
|
.padding-sm {
|
||||||
|
@apply px-4 py-3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.padding-md {
|
||||||
|
@apply sm:px-10 px-6 py-5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.padding-lg {
|
||||||
|
@apply px-12 py-8;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
147
src/components/ui/IconButton.vue
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
export type IconButtonVariant = "primary" | "secondary" | "outline" | "ghost";
|
||||||
|
export type IconButtonSize = "sm" | "md" | "lg";
|
||||||
|
export type IconPosition = "left" | "right";
|
||||||
|
|
||||||
|
const props = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
text: string;
|
||||||
|
icon?: string;
|
||||||
|
variant?: IconButtonVariant;
|
||||||
|
size?: IconButtonSize;
|
||||||
|
iconPosition?: IconPosition;
|
||||||
|
disabled?: boolean;
|
||||||
|
fullWidth?: boolean;
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
variant: "outline",
|
||||||
|
size: "md",
|
||||||
|
iconPosition: "left",
|
||||||
|
disabled: false,
|
||||||
|
fullWidth: false,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
click: [];
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const handleClick = () => {
|
||||||
|
if (!props.disabled) {
|
||||||
|
emit("click");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
:class="[
|
||||||
|
'icon-button',
|
||||||
|
`variant-${variant}`,
|
||||||
|
`size-${size}`,
|
||||||
|
{ 'is-disabled': disabled, 'full-width': fullWidth },
|
||||||
|
]"
|
||||||
|
:disabled="disabled"
|
||||||
|
@click="handleClick"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
v-if="icon && iconPosition === 'left'"
|
||||||
|
:src="icon"
|
||||||
|
:alt="`${text} icon`"
|
||||||
|
class="button-icon"
|
||||||
|
/>
|
||||||
|
<span class="button-text">{{ text }}</span>
|
||||||
|
<img
|
||||||
|
v-if="icon && iconPosition === 'right'"
|
||||||
|
:src="icon"
|
||||||
|
:alt="`${text} icon`"
|
||||||
|
class="button-icon"
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.icon-button {
|
||||||
|
@apply flex items-center justify-center gap-2 font-medium rounded-lg transition-all duration-200 cursor-pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-button:hover:not(.is-disabled) {
|
||||||
|
@apply transform scale-[1.02];
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-button.is-disabled {
|
||||||
|
@apply opacity-60 cursor-not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-button.full-width {
|
||||||
|
@apply w-full;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Variantes */
|
||||||
|
.variant-primary {
|
||||||
|
@apply bg-amber-400 text-gray-900 border-2 border-amber-400;
|
||||||
|
}
|
||||||
|
|
||||||
|
.variant-primary:hover:not(.is-disabled) {
|
||||||
|
@apply bg-amber-500 border-amber-500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.variant-secondary {
|
||||||
|
@apply bg-gray-200 text-gray-900 border-2 border-gray-300;
|
||||||
|
}
|
||||||
|
|
||||||
|
.variant-secondary:hover:not(.is-disabled) {
|
||||||
|
@apply bg-gray-300 border-gray-400;
|
||||||
|
}
|
||||||
|
|
||||||
|
.variant-outline {
|
||||||
|
@apply bg-transparent text-gray-900 border-2 border-amber-300;
|
||||||
|
}
|
||||||
|
|
||||||
|
.variant-outline:hover:not(.is-disabled) {
|
||||||
|
@apply bg-amber-300/10;
|
||||||
|
}
|
||||||
|
|
||||||
|
.variant-ghost {
|
||||||
|
@apply bg-transparent text-gray-900 border-2 border-transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.variant-ghost:hover:not(.is-disabled) {
|
||||||
|
@apply bg-gray-100;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Tamanhos */
|
||||||
|
.size-sm {
|
||||||
|
@apply px-2 py-1 text-xs;
|
||||||
|
}
|
||||||
|
|
||||||
|
.size-sm .button-icon {
|
||||||
|
@apply w-3 h-3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.size-md {
|
||||||
|
@apply px-3 py-2 text-sm;
|
||||||
|
}
|
||||||
|
|
||||||
|
.size-md .button-icon {
|
||||||
|
@apply w-4 h-4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.size-lg {
|
||||||
|
@apply px-4 py-3 text-base;
|
||||||
|
}
|
||||||
|
|
||||||
|
.size-lg .button-icon {
|
||||||
|
@apply w-5 h-5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button-text {
|
||||||
|
@apply font-semibold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button-icon {
|
||||||
|
@apply flex-shrink-0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
91
src/components/ui/InfoTooltip.vue
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, onMounted } from "vue";
|
||||||
|
import { useFloating, arrow, offset, flip, shift } from "@floating-ui/vue";
|
||||||
|
|
||||||
|
const props = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
text: string;
|
||||||
|
placement?: "top" | "bottom" | "left" | "right";
|
||||||
|
iconSrc?: string;
|
||||||
|
showOnHover?: boolean;
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
placement: "right",
|
||||||
|
iconSrc: "",
|
||||||
|
showOnHover: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const showTooltip = ref<boolean>(false);
|
||||||
|
const reference = ref<HTMLElement | null>(null);
|
||||||
|
const floating = ref<HTMLElement | null>(null);
|
||||||
|
const floatingArrow = ref(null);
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
useFloating(reference, floating, {
|
||||||
|
placement: props.placement,
|
||||||
|
middleware: [offset(10), flip(), shift(), arrow({ element: floatingArrow })],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleMouseOver = () => {
|
||||||
|
if (props.showOnHover) {
|
||||||
|
showTooltip.value = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleMouseOut = () => {
|
||||||
|
if (props.showOnHover) {
|
||||||
|
showTooltip.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const toggleTooltip = () => {
|
||||||
|
if (!props.showOnHover) {
|
||||||
|
showTooltip.value = !showTooltip.value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="info-tooltip-container">
|
||||||
|
<img
|
||||||
|
:src="iconSrc || '/src/assets/info.svg'"
|
||||||
|
alt="info icon"
|
||||||
|
class="info-icon"
|
||||||
|
ref="reference"
|
||||||
|
@mouseover="handleMouseOver"
|
||||||
|
@mouseout="handleMouseOut"
|
||||||
|
@click="toggleTooltip"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
v-if="showTooltip"
|
||||||
|
role="tooltip"
|
||||||
|
ref="floating"
|
||||||
|
class="tooltip-content"
|
||||||
|
>
|
||||||
|
{{ text }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.info-tooltip-container {
|
||||||
|
@apply relative inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-icon {
|
||||||
|
@apply cursor-pointer transition-opacity hover:opacity-70;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tooltip-content {
|
||||||
|
@apply bg-white text-gray-900 font-medium text-xs md:text-sm px-3 py-2 rounded border-2 border-emerald-500 z-50 max-w-xs shadow-lg;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 640px) {
|
||||||
|
.tooltip-content {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
60
src/components/ui/LoadingState.vue
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import SpinnerComponent from "./SpinnerComponent.vue";
|
||||||
|
|
||||||
|
const props = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
message?: string;
|
||||||
|
size?: "sm" | "md" | "lg";
|
||||||
|
centered?: boolean;
|
||||||
|
inline?: boolean;
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
message: "Carregando...",
|
||||||
|
size: "md",
|
||||||
|
centered: true,
|
||||||
|
inline: false,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const sizeMap = {
|
||||||
|
sm: { spinner: "4", text: "text-sm" },
|
||||||
|
md: { spinner: "6", text: "text-base" },
|
||||||
|
lg: { spinner: "8", text: "text-lg" },
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div
|
||||||
|
:class="[
|
||||||
|
'loading-state',
|
||||||
|
{ centered: centered, inline: inline },
|
||||||
|
]"
|
||||||
|
>
|
||||||
|
<span v-if="message" :class="['loading-message', sizeMap[size].text]">
|
||||||
|
{{ message }}
|
||||||
|
</span>
|
||||||
|
<SpinnerComponent
|
||||||
|
:width="sizeMap[size].spinner"
|
||||||
|
:height="sizeMap[size].spinner"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.loading-state {
|
||||||
|
@apply flex items-center gap-2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-state.centered {
|
||||||
|
@apply justify-center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-state.inline {
|
||||||
|
@apply inline-flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-message {
|
||||||
|
@apply text-gray-900 font-normal;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
72
src/components/ui/NetworkBadges.vue
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed } from "vue";
|
||||||
|
import { getNetworkImage } from "@/utils/imagesPath";
|
||||||
|
import type { NetworkConfig } from "@/model/NetworkEnum";
|
||||||
|
|
||||||
|
const props = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
networks: NetworkConfig[];
|
||||||
|
size?: "sm" | "md" | "lg";
|
||||||
|
showLabel?: boolean;
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
size: "md",
|
||||||
|
showLabel: false,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const sizeMap = {
|
||||||
|
sm: 16,
|
||||||
|
md: 24,
|
||||||
|
lg: 32,
|
||||||
|
};
|
||||||
|
|
||||||
|
const networkData = computed(() => {
|
||||||
|
return props.networks.map((network) => ({
|
||||||
|
network,
|
||||||
|
image: getNetworkImage(network.name),
|
||||||
|
name: network.name,
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="network-badges">
|
||||||
|
<div
|
||||||
|
v-for="data in networkData"
|
||||||
|
:key="data.network.id"
|
||||||
|
class="network-badge"
|
||||||
|
:title="data.name"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
:alt="`${data.name} logo`"
|
||||||
|
:src="data.image"
|
||||||
|
:width="sizeMap[size]"
|
||||||
|
:height="sizeMap[size]"
|
||||||
|
class="network-icon"
|
||||||
|
/>
|
||||||
|
<span v-if="showLabel" class="network-label">
|
||||||
|
{{ data.name }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.network-badges {
|
||||||
|
@apply flex gap-2 items-center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.network-badge {
|
||||||
|
@apply flex items-center gap-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.network-icon {
|
||||||
|
@apply flex-shrink-0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.network-label {
|
||||||
|
@apply text-sm font-medium text-gray-900;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
50
src/components/ui/NetworkSelector.vue
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed } from "vue";
|
||||||
|
import { Networks } from "@/config/networks";
|
||||||
|
import type { NetworkConfig } from "@/model/NetworkEnum";
|
||||||
|
import { getNetworkImage } from "@/utils/imagesPath";
|
||||||
|
import Dropdown, { type DropdownItem } from "./Dropdown.vue";
|
||||||
|
|
||||||
|
const props = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
modelValue: NetworkConfig;
|
||||||
|
disabled?: boolean;
|
||||||
|
size?: "sm" | "md" | "lg";
|
||||||
|
availableNetworks?: NetworkConfig[];
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
disabled: false,
|
||||||
|
size: "md",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
"update:modelValue": [value: NetworkConfig];
|
||||||
|
change: [value: NetworkConfig];
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const networkItems = computed((): DropdownItem<NetworkConfig>[] => {
|
||||||
|
return Object.values(Networks).map((network) => ({
|
||||||
|
value: network,
|
||||||
|
label: network.name,
|
||||||
|
icon: getNetworkImage(network.name),
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleChange = (value: NetworkConfig) => {
|
||||||
|
emit("update:modelValue", value);
|
||||||
|
emit("change", value);
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Dropdown
|
||||||
|
:model-value="modelValue"
|
||||||
|
:items="networkItems"
|
||||||
|
:disabled="disabled"
|
||||||
|
:size="size"
|
||||||
|
:show-icon="true"
|
||||||
|
@update:model-value="handleChange"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
||||||
66
src/components/ui/PageHeader.vue
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
export type HeaderSize = "sm" | "md" | "lg";
|
||||||
|
|
||||||
|
const props = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
title: string;
|
||||||
|
subtitle?: string;
|
||||||
|
size?: HeaderSize;
|
||||||
|
centered?: boolean;
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
size: "lg",
|
||||||
|
centered: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div
|
||||||
|
:class="['page-header', `size-${size}`, { centered: centered }]"
|
||||||
|
>
|
||||||
|
<h1 class="title text-white font-extrabold">
|
||||||
|
{{ title }}
|
||||||
|
</h1>
|
||||||
|
<p v-if="subtitle" class="subtitle text-white font-medium">
|
||||||
|
{{ subtitle }}
|
||||||
|
</p>
|
||||||
|
<slot></slot>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.page-header {
|
||||||
|
@apply flex flex-col gap-4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-header.centered {
|
||||||
|
@apply items-center justify-center text-center;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Tamanhos */
|
||||||
|
.size-sm .title {
|
||||||
|
@apply sm:text-2xl text-xl sm:max-w-[20rem] max-w-[16rem];
|
||||||
|
}
|
||||||
|
|
||||||
|
.size-sm .subtitle {
|
||||||
|
@apply sm:text-sm text-xs sm:max-w-[18rem] max-w-[14rem];
|
||||||
|
}
|
||||||
|
|
||||||
|
.size-md .title {
|
||||||
|
@apply sm:text-4xl text-2xl sm:max-w-[28rem] max-w-[22rem];
|
||||||
|
}
|
||||||
|
|
||||||
|
.size-md .subtitle {
|
||||||
|
@apply sm:text-base text-sm sm:max-w-[26rem] max-w-[20rem];
|
||||||
|
}
|
||||||
|
|
||||||
|
.size-lg .title {
|
||||||
|
@apply sm:text-5xl text-3xl sm:max-w-[29rem] max-w-[20rem];
|
||||||
|
}
|
||||||
|
|
||||||
|
.size-lg .subtitle {
|
||||||
|
@apply sm:text-base text-sm sm:max-w-[28rem] max-w-[30rem] sm:tracking-normal tracking-wide;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
50
src/components/ui/StatusBadge.vue
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed } from "vue";
|
||||||
|
|
||||||
|
export type StatusType = "open" | "expired" | "completed" | "pending";
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
status: StatusType;
|
||||||
|
customText?: string;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const statusConfig = computed(() => {
|
||||||
|
const configs: Record<StatusType, { text: string; color: string }> = {
|
||||||
|
open: {
|
||||||
|
text: "Em Aberto",
|
||||||
|
color: "bg-amber-300",
|
||||||
|
},
|
||||||
|
expired: {
|
||||||
|
text: "Expirado",
|
||||||
|
color: "bg-[#94A3B8]",
|
||||||
|
},
|
||||||
|
completed: {
|
||||||
|
text: "Finalizado",
|
||||||
|
color: "bg-emerald-300",
|
||||||
|
},
|
||||||
|
pending: {
|
||||||
|
text: "Pendente",
|
||||||
|
color: "bg-gray-300",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return configs[props.status];
|
||||||
|
});
|
||||||
|
|
||||||
|
const displayText = computed(() => {
|
||||||
|
return props.customText || statusConfig.value.text;
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div :class="[statusConfig.color, 'status-badge']">
|
||||||
|
{{ displayText }}
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.status-badge {
|
||||||
|
@apply text-xs sm:text-base font-medium text-gray-900 rounded-lg text-center px-2 py-1;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
@@ -1,20 +1,20 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed, watch, onMounted } from "vue";
|
import { ref, computed, watch, onMounted } from "vue";
|
||||||
import { useOnboard } from "@web3-onboard/vue";
|
import { useOnboard } from "@web3-onboard/vue";
|
||||||
import { Networks } from "../model/Networks";
|
import { Networks } from "@/config/networks";
|
||||||
import { useUser } from "@/composables/useUser";
|
import { useUser } from "@/composables/useUser";
|
||||||
|
|
||||||
const { connectedWallet } = useOnboard();
|
const { connectedWallet } = useOnboard();
|
||||||
const user = useUser();
|
const user = useUser();
|
||||||
const { networkId, networkName } = user;
|
const { network } = user;
|
||||||
|
|
||||||
const isWrongNetwork = ref(false);
|
const isWrongNetwork = ref(false);
|
||||||
const targetNetworkName = computed(() => Networks[networkName.value].chainName);
|
const targetNetworkName = computed(() => network.value.name);
|
||||||
|
|
||||||
const checkNetwork = () => {
|
const checkNetwork = () => {
|
||||||
if (connectedWallet.value) {
|
if (connectedWallet.value) {
|
||||||
const chainId = connectedWallet.value.chains[0].id;
|
const chainId = connectedWallet.value.chains[0].id;
|
||||||
isWrongNetwork.value = Number(chainId) !== networkId.value;
|
isWrongNetwork.value = Number(chainId) !== network.value.id;
|
||||||
} else {
|
} else {
|
||||||
isWrongNetwork.value = false; // No wallet connected yet
|
isWrongNetwork.value = false; // No wallet connected yet
|
||||||
}
|
}
|
||||||
@@ -23,11 +23,12 @@ const checkNetwork = () => {
|
|||||||
const switchNetwork = async () => {
|
const switchNetwork = async () => {
|
||||||
try {
|
try {
|
||||||
if (connectedWallet.value && connectedWallet.value.provider) {
|
if (connectedWallet.value && connectedWallet.value.provider) {
|
||||||
|
let chainId = network.value.id.toString(16);
|
||||||
await connectedWallet.value.provider.request({
|
await connectedWallet.value.provider.request({
|
||||||
method: "wallet_switchEthereumChain",
|
method: "wallet_switchEthereumChain",
|
||||||
params: [
|
params: [
|
||||||
{
|
{
|
||||||
chainId: Networks[networkName.value].chainId,
|
chainId: `0x${chainId}`,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@@ -39,7 +40,7 @@ const switchNetwork = async () => {
|
|||||||
|
|
||||||
onMounted(checkNetwork);
|
onMounted(checkNetwork);
|
||||||
watch(connectedWallet, checkNetwork);
|
watch(connectedWallet, checkNetwork);
|
||||||
watch(networkId, checkNetwork, { immediate: true });
|
watch(network, checkNetwork, { immediate: true });
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
48
src/components/ui/TokenSelector.vue
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed } from "vue";
|
||||||
|
import { TokenEnum } from "@/model/NetworkEnum";
|
||||||
|
import { getTokenImage } from "@/utils/imagesPath";
|
||||||
|
import Dropdown, { type DropdownItem } from "./Dropdown.vue";
|
||||||
|
|
||||||
|
const props = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
modelValue: TokenEnum;
|
||||||
|
disabled?: boolean;
|
||||||
|
size?: "sm" | "md" | "lg";
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
disabled: false,
|
||||||
|
size: "md",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
"update:modelValue": [value: TokenEnum];
|
||||||
|
change: [value: TokenEnum];
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const tokenItems = computed((): DropdownItem<TokenEnum>[] => {
|
||||||
|
return Object.values(TokenEnum).map((token) => ({
|
||||||
|
value: token,
|
||||||
|
label: token,
|
||||||
|
icon: getTokenImage(token),
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleChange = (value: TokenEnum) => {
|
||||||
|
emit("update:modelValue", value);
|
||||||
|
emit("change", value);
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Dropdown
|
||||||
|
:model-value="modelValue"
|
||||||
|
:items="tokenItems"
|
||||||
|
:disabled="disabled"
|
||||||
|
:size="size"
|
||||||
|
:show-icon="true"
|
||||||
|
@update:model-value="handleChange"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
||||||
152
src/components/ui/WalletConnectButton.vue
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, computed } from "vue";
|
||||||
|
import { onClickOutside } from "@vueuse/core";
|
||||||
|
import CustomButton from "./CustomButton.vue";
|
||||||
|
|
||||||
|
const props = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
walletAddress: string | null;
|
||||||
|
variant?: "primary" | "secondary" | "outline";
|
||||||
|
showMenu?: boolean;
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
variant: "primary",
|
||||||
|
showMenu: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
connect: [];
|
||||||
|
disconnect: [];
|
||||||
|
viewTransactions: [];
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const menuOpen = ref(false);
|
||||||
|
const menuRef = ref<HTMLElement | null>(null);
|
||||||
|
|
||||||
|
const isConnected = computed(() => {
|
||||||
|
return !!props.walletAddress;
|
||||||
|
});
|
||||||
|
|
||||||
|
const formattedAddress = computed(() => {
|
||||||
|
if (!props.walletAddress) return "";
|
||||||
|
|
||||||
|
const address = props.walletAddress;
|
||||||
|
const length = address.length;
|
||||||
|
const start = address.substring(0, 5);
|
||||||
|
const end = address.substring(length - 4, length);
|
||||||
|
|
||||||
|
return `${start}...${end}`;
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleConnect = () => {
|
||||||
|
emit("connect");
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDisconnect = () => {
|
||||||
|
menuOpen.value = false;
|
||||||
|
emit("disconnect");
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleViewTransactions = () => {
|
||||||
|
menuOpen.value = false;
|
||||||
|
emit("viewTransactions");
|
||||||
|
};
|
||||||
|
|
||||||
|
const toggleMenu = () => {
|
||||||
|
if (isConnected.value && props.showMenu) {
|
||||||
|
menuOpen.value = !menuOpen.value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
onClickOutside(menuRef, () => {
|
||||||
|
menuOpen.value = false;
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="wallet-connect-container">
|
||||||
|
<CustomButton
|
||||||
|
v-if="!isConnected"
|
||||||
|
text="Conectar carteira"
|
||||||
|
:variant="variant"
|
||||||
|
@button-clicked="handleConnect"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div v-else ref="menuRef" class="wallet-connected">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="wallet-button"
|
||||||
|
@click="toggleMenu"
|
||||||
|
>
|
||||||
|
<span class="wallet-address">{{ formattedAddress }}</span>
|
||||||
|
<div class="wallet-indicator"></div>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<transition name="menu-fade">
|
||||||
|
<div v-if="menuOpen && showMenu" class="wallet-menu">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="menu-item"
|
||||||
|
@click="handleViewTransactions"
|
||||||
|
>
|
||||||
|
<span>Ver transações</span>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="menu-item disconnect"
|
||||||
|
@click="handleDisconnect"
|
||||||
|
>
|
||||||
|
<span>Desconectar</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</transition>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.wallet-connect-container {
|
||||||
|
@apply relative inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wallet-connected {
|
||||||
|
@apply relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wallet-button {
|
||||||
|
@apply flex items-center gap-3 px-4 py-2 bg-white border-2 border-amber-400 rounded-lg hover:bg-amber-50 transition-colors cursor-pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wallet-address {
|
||||||
|
@apply text-gray-900 font-semibold text-sm;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wallet-indicator {
|
||||||
|
@apply w-2 h-2 bg-emerald-500 rounded-full;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wallet-menu {
|
||||||
|
@apply absolute top-full right-0 mt-2 bg-white rounded-lg border border-gray-300 shadow-lg z-50 min-w-[200px] overflow-hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu-item {
|
||||||
|
@apply w-full px-4 py-3 text-left text-gray-900 font-medium text-sm hover:bg-gray-100 transition-colors cursor-pointer border-none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu-item.disconnect {
|
||||||
|
@apply text-red-500 hover:bg-red-50;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Animação */
|
||||||
|
.menu-fade-enter-active,
|
||||||
|
.menu-fade-leave-active {
|
||||||
|
@apply transition-all duration-200;
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu-fade-enter-from,
|
||||||
|
.menu-fade-leave-to {
|
||||||
|
@apply opacity-0 -translate-y-2;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
@@ -1,15 +1,14 @@
|
|||||||
import { ref } from "vue";
|
import { ref } from "vue";
|
||||||
import { NetworkEnum, TokenEnum } from "../model/NetworkEnum";
|
|
||||||
import type { ValidDeposit } from "@/model/ValidDeposit";
|
import type { ValidDeposit } from "@/model/ValidDeposit";
|
||||||
import type { Participant } from "../utils/bbPay";
|
import type { Participant } from "../utils/bbPay";
|
||||||
import { NetworkById } from "@/model/Networks";
|
|
||||||
import type { Address } from "viem"
|
import type { Address } from "viem"
|
||||||
|
import { DEFAULT_NETWORK, Networks } from "@/config/networks";
|
||||||
|
import { TokenEnum, NetworkConfig } from "@/model/NetworkEnum"
|
||||||
|
|
||||||
const walletAddress = ref<Address | null>(null);
|
const walletAddress = ref<Address | null>(null);
|
||||||
const balance = ref("");
|
const balance = ref("");
|
||||||
const networkId = ref(11155111);
|
const network = ref(DEFAULT_NETWORK);
|
||||||
const networkName = ref(NetworkEnum.sepolia);
|
const selectedToken = ref<TokenEnum>(TokenEnum.BRZ);
|
||||||
const selectedToken = ref(TokenEnum.BRZ);
|
|
||||||
const loadingLock = ref(false);
|
const loadingLock = ref(false);
|
||||||
const sellerView = ref(false);
|
const sellerView = ref(false);
|
||||||
const depositsValidList = ref<ValidDeposit[]>([]);
|
const depositsValidList = ref<ValidDeposit[]>([]);
|
||||||
@@ -32,9 +31,29 @@ export function useUser() {
|
|||||||
selectedToken.value = token;
|
selectedToken.value = token;
|
||||||
};
|
};
|
||||||
|
|
||||||
const setNetworkId = (network: string | number) => {
|
const setNetwork = (chain: NetworkConfig) => {
|
||||||
networkName.value = NetworkById(network) || NetworkEnum.sepolia;
|
network.value = chain;
|
||||||
networkId.value = Number(network);
|
};
|
||||||
|
|
||||||
|
const setNetworkById = (id: string | number) => {
|
||||||
|
let chainId: number;
|
||||||
|
|
||||||
|
if (typeof id === 'string') {
|
||||||
|
// Parse hex string or number string to number
|
||||||
|
if (id.startsWith('0x')) {
|
||||||
|
chainId = parseInt(id, 16);
|
||||||
|
} else {
|
||||||
|
chainId = parseInt(id, 10);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
chainId = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find network by chain ID
|
||||||
|
const chain = Object.values(Networks).find(n => n.id === chainId);
|
||||||
|
if (chain) {
|
||||||
|
network.value = chain;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const setLoadingLock = (isLoading: boolean) => {
|
const setLoadingLock = (isLoading: boolean) => {
|
||||||
@@ -76,8 +95,7 @@ export function useUser() {
|
|||||||
// State
|
// State
|
||||||
walletAddress,
|
walletAddress,
|
||||||
balance,
|
balance,
|
||||||
networkId,
|
network,
|
||||||
networkName,
|
|
||||||
selectedToken,
|
selectedToken,
|
||||||
loadingLock,
|
loadingLock,
|
||||||
sellerView,
|
sellerView,
|
||||||
@@ -91,7 +109,8 @@ export function useUser() {
|
|||||||
setWalletAddress,
|
setWalletAddress,
|
||||||
setBalance,
|
setBalance,
|
||||||
setSelectedToken,
|
setSelectedToken,
|
||||||
setNetworkId,
|
setNetwork,
|
||||||
|
setNetworkById,
|
||||||
setLoadingLock,
|
setLoadingLock,
|
||||||
setSellerView,
|
setSellerView,
|
||||||
setDepositsValidList,
|
setDepositsValidList,
|
||||||
|
|||||||
24
src/config/networks.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { sepolia, rootstockTestnet } from "viem/chains";
|
||||||
|
import { NetworkConfig } from "@/model/NetworkEnum"
|
||||||
|
// TODO: import addresses from p2pix-smart-contracts deployments
|
||||||
|
|
||||||
|
export const Networks: {[key:string]: NetworkConfig} = {
|
||||||
|
sepolia: { ...sepolia,
|
||||||
|
rpcUrls: { default: { http: [import.meta.env.VITE_SEPOLIA_API_URL]}},
|
||||||
|
contracts: { ...sepolia.contracts,
|
||||||
|
p2pix: {address:"0xb7cD135F5eFD9760981e02E2a898790b688939fe"} },
|
||||||
|
tokens: {
|
||||||
|
BRZ: {address:"0x3eBE67A2C7bdB2081CBd34ba3281E90377462289"} },
|
||||||
|
subgraphUrls: [import.meta.env.VITE_SEPOLIA_SUBGRAPH_URL]
|
||||||
|
},
|
||||||
|
rootstockTestnet: { ...rootstockTestnet,
|
||||||
|
rpcUrls: { default: { http: [import.meta.env.VITE_RSK_API_URL]}},
|
||||||
|
contracts: { ...rootstockTestnet.contracts,
|
||||||
|
p2pix: {address:"0x57Dcba05980761169508886eEdc6f5E7EC0411Dc"} },
|
||||||
|
tokens: {
|
||||||
|
BRZ: {address:"0xfE841c74250e57640390f46d914C88d22C51e82e"} },
|
||||||
|
subgraphUrls: [import.meta.env.VITE_RSK_SUBGRAPH_URL]
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const DEFAULT_NETWORK = Networks.sepolia;
|
||||||
@@ -1,18 +1,10 @@
|
|||||||
export enum NetworkEnum {
|
import type { Chain, ChainContract } from "viem";
|
||||||
sepolia = 11155111,
|
|
||||||
rootstock = 31,
|
|
||||||
}
|
|
||||||
|
|
||||||
export const getNetworkSubgraphURL = (network: NetworkEnum) => {
|
|
||||||
const networkMap: Record<NetworkEnum, string> = {
|
|
||||||
[NetworkEnum.sepolia]: import.meta.env.VITE_SEPOLIA_SUBGRAPH_URL || "",
|
|
||||||
[NetworkEnum.rootstock]: import.meta.env.VITE_RSK_SUBGRAPH_URL || "",
|
|
||||||
};
|
|
||||||
|
|
||||||
return networkMap[network] || "";
|
|
||||||
};
|
|
||||||
|
|
||||||
export enum TokenEnum {
|
export enum TokenEnum {
|
||||||
BRZ = "BRZ",
|
BRZ = 'BRZ',
|
||||||
// BRX = 'BRX'
|
// BRX = 'BRX'
|
||||||
}
|
}
|
||||||
|
export type NetworkConfig = Chain & {
|
||||||
|
tokens: Record<TokenEnum, ChainContract>,
|
||||||
|
subgraphUrls: string[]
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
import { NetworkEnum } from "@/model/NetworkEnum";
|
|
||||||
|
|
||||||
export const NetworkById = (
|
|
||||||
chainId: string | number
|
|
||||||
): NetworkEnum | undefined => {
|
|
||||||
const normalizedChainId =
|
|
||||||
typeof chainId === "number" ? chainId : Number(chainId);
|
|
||||||
|
|
||||||
for (const [network, details] of Object.entries(Networks)) {
|
|
||||||
if (Number(details.chainId) === normalizedChainId) {
|
|
||||||
return network as unknown as NetworkEnum;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const Networks = {
|
|
||||||
[NetworkEnum.sepolia]: {
|
|
||||||
chainId: "0xAA36A7",
|
|
||||||
chainName: "Sepolia Testnet",
|
|
||||||
},
|
|
||||||
[NetworkEnum.rootstock]: {
|
|
||||||
chainId: "0x1F",
|
|
||||||
chainName: "Rootstock Testnet",
|
|
||||||
rpcUrls: ["https://public-node.testnet.rsk.co/"],
|
|
||||||
iconUrls: [
|
|
||||||
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACQAAAAoCAYAAACWwljjAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAPOSURBVHgBxVhNUhpBFH6vGdxp4S4LoSYnEE8gnEA4AbpMJUQ4gXgCRJK1egLxBOIJJCdwJElVllMu49Cd1z04zD/dY1H5qihmut/M93VPv59uhHdAXFaPAaEDgA2/BaeA4hq/zG+gIBAKQoyr9yshid4Jdn+2oQAYFIC4rA2zxUhgS3yrDqEAjGdIDD/YYG09aRl7L7vYd10wgPkMlcoNfdvtFhjCXJBAeyO2S5gLQuFo25bEIxjCCt8oN2Z46I+Mu4A4SbjwojQBi1+BDl5LP+JNYlhtQRmPsjjQN1ILldwY7JTXOuD9bWL/jxO8dFy7oL9TyMcIu/PeSghxlLduQUA9jwPXiAk98HLw5jFiaFfAEjRLImPR0qi7z+2VmArZ7zzqcDAS01ljCKqf7QSjxb7jKkIhTohu6rOCq64RjsNiFEo7x7ocSNMvlddhPWb0CQ6gAAw4HKZpKGFDcWhzSEG6kbQCm4dLbi9m+XlpBTHea2D31zTSNtxrAGMNdcP5FPuxfhlKdCHgASUJxcd7zUcobkAPXvkzWGyf7uVCt2M2DtkMljaHSxu92WWLAz8OjWsD+juD/4tzcpqBSh3yQrmwoNFFMZNuDB7bJRsp/hzMMQqeT+NQ96KtNEBK+SG+23XgHgUyy8FPjpPozy3M4sZwh1/nLRMOK26Mn50Z5IHjA6XkBugJSn1XHkeBbK8dJsxsl0jMEOUpm0o9+gkX+7+TI0E+0x6Hsk0ijyNYQ/4OAqWn2aF+5cLxEoRq6idqtyEPtFhp/XyMNI2p9ADFUc/iYL5h7YzEXEEyptj04mvVHxkGP4F8MS4sWDsqRr4DbyGZRiIcqCKtpRMYeTMcpVVAFewqMVPSjUkMVQTBp6BPVKeiTqN65E0qP1AvIArWC98qcQsms39oDeBEtoXFKFgLbQ76ZKiXiRH2E01UF9Go+kGDh32/LWHZAD2OQ7mGdLO4ndrqWaHZyNyD6XJUWEq6yIQqReOweCe49ivD2DNUIutjJgXpHwyUtyPbY/IMWehfBA0IZxQSQoW9rKXL+ltq0oKqYC+RB6yLKys4xEw/Idde5R02cTGOcgh1LSNnid+nihIqcN0tr48MhL89L2uoG+Dqv5Px/IwqAhkqnEi296M1OyLPqVCgdKhcuKNjlUnQL4X78cRk1E1JlMkBME1sFE0gRrRJZGs3iT44bRZP5z0wQJHzIZMMbpztN1t+FDhsMBe0YNfatimHDetgLGiZGkYapqPwYt6YIAWPDYI9fSrETfjkwwSFT2EVrV/USY+r+/GGNp2I7zoW/gdR9aOdZ/lPGgAAAABJRU5ErkJggg==",
|
|
||||||
],
|
|
||||||
nativeCurrency: {
|
|
||||||
name: "tRBTC",
|
|
||||||
symbol: "tRBTC",
|
|
||||||
decimals: 18,
|
|
||||||
},
|
|
||||||
blockExplorerUrls: ["https://explorer.testnet.rootstock.io/"],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { NetworkEnum } from "./NetworkEnum";
|
|
||||||
import type { Address } from "viem";
|
import type { Address } from "viem";
|
||||||
|
import type { NetworkConfig } from "@/model/NetworkEnum";
|
||||||
|
|
||||||
export type ValidDeposit = {
|
export type ValidDeposit = {
|
||||||
token: Address;
|
token: Address;
|
||||||
@@ -7,6 +7,6 @@ export type ValidDeposit = {
|
|||||||
remaining: number;
|
remaining: number;
|
||||||
seller: Address;
|
seller: Address;
|
||||||
participantID: string;
|
participantID: string;
|
||||||
network: NetworkEnum;
|
network: NetworkConfig;
|
||||||
open?: boolean;
|
open?: boolean;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -61,15 +61,15 @@ export const createSolicitation = async (offer: Offer) => {
|
|||||||
return response.json();
|
return response.json();
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getSolicitation = async (id: string) => {
|
export const getSolicitation = async (id: bigint): Promise<{pixTimestamp: `0x${string}`, signature: `0x${string}`}> => {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${import.meta.env.VITE_APP_API_URL}/release/${id}`
|
`${import.meta.env.VITE_APP_API_URL}/release/${id}`
|
||||||
);
|
);
|
||||||
|
|
||||||
const obj: any = await response.json();
|
const obj = await response.json();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pixTarget: obj.pixTarget,
|
pixTimestamp: obj.pixTimestamp,
|
||||||
signature: obj.signature,
|
signature: obj.signature,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,30 +1,11 @@
|
|||||||
import type { TokenEnum } from "@/model/NetworkEnum";
|
import type { TokenEnum } from "@/model/NetworkEnum";
|
||||||
|
import { Networks } from "@/config/networks";
|
||||||
export const imagesPath = import.meta.glob<string>("@/assets/*.{png,svg}", {
|
|
||||||
eager: true,
|
|
||||||
query: "?url",
|
|
||||||
import: "default",
|
|
||||||
});
|
|
||||||
|
|
||||||
export const getNetworkImage = (networkName: string): string => {
|
export const getNetworkImage = (networkName: string): string => {
|
||||||
try {
|
const normalizedName = networkName.toLowerCase().replace(/[^a-z0-9]/g, '-');
|
||||||
const path = Object.keys(imagesPath).find((key) =>
|
return new URL(`../assets/networks/${normalizedName}.svg`, import.meta.url).href;
|
||||||
key.endsWith(`${networkName.toLowerCase()}.svg`)
|
|
||||||
);
|
|
||||||
return path ? imagesPath[path] : "";
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error fetching network image");
|
|
||||||
const path = Object.keys(imagesPath).find((key) =>
|
|
||||||
key.endsWith(`invalidIcon.svg`)
|
|
||||||
);
|
|
||||||
return path ? imagesPath[path] : "";
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getTokenImage = (tokenName: TokenEnum): string => {
|
export const getTokenImage = (tokenName: TokenEnum): string => {
|
||||||
const path = Object.keys(imagesPath).find((key) =>
|
return new URL(`../assets/tokens/${tokenName.toLowerCase()}.svg`, import.meta.url).href;
|
||||||
key.endsWith(`${tokenName.toLowerCase()}.svg`)
|
|
||||||
);
|
|
||||||
return path ? imagesPath[path] : "";
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import SearchComponent from "@/components/SearchComponent.vue";
|
import SearchComponent from "@/components/BuyerSteps/BuyerSearchComponent.vue";
|
||||||
import LoadingComponent from "@/components/LoadingComponent/LoadingComponent.vue";
|
import LoadingComponent from "@/components/ui/LoadingComponent.vue";
|
||||||
import BuyConfirmedComponent from "@/components/BuyConfirmedComponent/BuyConfirmedComponent.vue";
|
import BuyConfirmedComponent from "@/components/BuyerSteps/BuyConfirmedComponent.vue";
|
||||||
import { ref, onMounted, watch } from "vue";
|
import { ref, onMounted, watch } from "vue";
|
||||||
import { useUser } from "@/composables/useUser";
|
import { useUser } from "@/composables/useUser";
|
||||||
import QrCodeComponent from "@/components/QrCodeComponent.vue";
|
import QrCodeComponent from "@/components/BuyerSteps/QrCodeComponent.vue";
|
||||||
import { addLock, releaseLock } from "@/blockchain/buyerMethods";
|
import { addLock, releaseLock } from "@/blockchain/buyerMethods";
|
||||||
import { updateWalletStatus, checkUnreleasedLock } from "@/blockchain/wallet";
|
import { updateWalletStatus, checkUnreleasedLock } from "@/blockchain/wallet";
|
||||||
import { getNetworksLiquidity } from "@/blockchain/events";
|
import { getNetworksLiquidity } from "@/blockchain/events";
|
||||||
import type { ValidDeposit } from "@/model/ValidDeposit";
|
import type { ValidDeposit } from "@/model/ValidDeposit";
|
||||||
import { getUnreleasedLockById } from "@/blockchain/events";
|
import { getUnreleasedLockById } from "@/blockchain/events";
|
||||||
import CustomAlert from "@/components/CustomAlert/CustomAlert.vue";
|
import CustomAlert from "@/components/ui/CustomAlert.vue";
|
||||||
import { getSolicitation } from "@/utils/bbPay";
|
import { getSolicitation } from "@/utils/bbPay";
|
||||||
import type { Address } from "viem";
|
import type { Address } from "viem";
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ const user = useUser();
|
|||||||
user.setSellerView(false);
|
user.setSellerView(false);
|
||||||
|
|
||||||
// States
|
// States
|
||||||
const { loadingLock, walletAddress, networkName } = user;
|
const { loadingLock, walletAddress, network } = user;
|
||||||
const flowStep = ref<Step>(Step.Search);
|
const flowStep = ref<Step>(Step.Search);
|
||||||
const participantID = ref<string>();
|
const participantID = ref<string>();
|
||||||
const sellerAddress = ref<Address>();
|
const sellerAddress = ref<Address>();
|
||||||
@@ -59,19 +59,15 @@ const confirmBuyClick = async (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const releaseTransaction = async ({
|
const releaseTransaction = async (params: {
|
||||||
pixTarget,
|
pixTimestamp: `0x${string}`&{lenght:34},
|
||||||
signature,
|
signature: `0x${string}`,
|
||||||
}: {
|
|
||||||
pixTarget: string;
|
|
||||||
signature: string;
|
|
||||||
}) => {
|
}) => {
|
||||||
flowStep.value = Step.List;
|
flowStep.value = Step.List;
|
||||||
showBuyAlert.value = true;
|
showBuyAlert.value = true;
|
||||||
loadingRelease.value = true;
|
loadingRelease.value = true;
|
||||||
|
|
||||||
const release = await releaseLock(BigInt(lockID.value), pixTarget, signature);
|
const release = await releaseLock(BigInt(lockID.value), params.pixTimestamp, params.signature);
|
||||||
await release.wait();
|
|
||||||
|
|
||||||
await updateWalletStatus();
|
await updateWalletStatus();
|
||||||
loadingRelease.value = false;
|
loadingRelease.value = false;
|
||||||
@@ -107,7 +103,7 @@ if (paramLockID) {
|
|||||||
await checkForUnreleasedLocks();
|
await checkForUnreleasedLocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
watch(networkName, async () => {
|
watch(network, async () => {
|
||||||
if (walletAddress.value) await checkForUnreleasedLocks();
|
if (walletAddress.value) await checkForUnreleasedLocks();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
import { ref, onMounted, watch } from "vue";
|
import { ref, onMounted, watch } from "vue";
|
||||||
import { useUser } from "@/composables/useUser";
|
import { useUser } from "@/composables/useUser";
|
||||||
import ListingComponent from "@/components/ListingComponent/ListingComponent.vue";
|
import ListingComponent from "@/components/ListingComponent/ListingComponent.vue";
|
||||||
import LoadingComponent from "@/components/LoadingComponent/LoadingComponent.vue";
|
import LoadingComponent from "@/components/ui/LoadingComponent.vue";
|
||||||
import CustomAlert from "@/components/CustomAlert/CustomAlert.vue";
|
import CustomAlert from "@/components/ui/CustomAlert.vue";
|
||||||
import {
|
import {
|
||||||
listValidDepositTransactionsByWalletAddress,
|
listValidDepositTransactionsByWalletAddress,
|
||||||
listAllTransactionByWalletAddress,
|
listAllTransactionByWalletAddress,
|
||||||
@@ -16,7 +16,7 @@ import type { WalletTransaction } from "@/model/WalletTransaction";
|
|||||||
import router from "@/router/index";
|
import router from "@/router/index";
|
||||||
|
|
||||||
const user = useUser();
|
const user = useUser();
|
||||||
const { walletAddress, networkName, selectedToken } = user;
|
const { walletAddress, network, selectedToken } = user;
|
||||||
const loadingWithdraw = ref<boolean>(false);
|
const loadingWithdraw = ref<boolean>(false);
|
||||||
const showAlert = ref<boolean>(false);
|
const showAlert = ref<boolean>(false);
|
||||||
|
|
||||||
@@ -29,7 +29,9 @@ const callWithdraw = async (amount: string) => {
|
|||||||
loadingWithdraw.value = true;
|
loadingWithdraw.value = true;
|
||||||
let withdraw;
|
let withdraw;
|
||||||
try {
|
try {
|
||||||
withdraw = await withdrawDeposit(amount, selectedToken.value);
|
withdraw = await withdrawDeposit(
|
||||||
|
amount,
|
||||||
|
network.value.tokens[selectedToken.value].address);
|
||||||
} catch {
|
} catch {
|
||||||
loadingWithdraw.value = false;
|
loadingWithdraw.value = false;
|
||||||
}
|
}
|
||||||
@@ -79,7 +81,7 @@ watch(walletAddress, async () => {
|
|||||||
await getWalletTransactions();
|
await getWalletTransactions();
|
||||||
});
|
});
|
||||||
|
|
||||||
watch(networkName, async () => {
|
watch(network, async () => {
|
||||||
await getWalletTransactions();
|
await getWalletTransactions();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ import { ref } from "vue";
|
|||||||
|
|
||||||
import SellerComponent from "@/components/SellerSteps/SellerComponent.vue";
|
import SellerComponent from "@/components/SellerSteps/SellerComponent.vue";
|
||||||
import SendNetwork from "@/components/SellerSteps/SendNetwork.vue";
|
import SendNetwork from "@/components/SellerSteps/SendNetwork.vue";
|
||||||
import LoadingComponent from "@/components/LoadingComponent/LoadingComponent.vue";
|
import LoadingComponent from "@/components/ui/LoadingComponent.vue";
|
||||||
import { useUser } from "@/composables/useUser";
|
import { useUser } from "@/composables/useUser";
|
||||||
import { approveTokens, addDeposit } from "@/blockchain/sellerMethods";
|
import { approveTokens, addDeposit } from "@/blockchain/sellerMethods";
|
||||||
import CustomAlert from "@/components/CustomAlert/CustomAlert.vue";
|
import CustomAlert from "@/components/ui/CustomAlert.vue";
|
||||||
import type { Participant } from "@/utils/bbPay";
|
import type { Participant } from "@/utils/bbPay";
|
||||||
|
|
||||||
enum Step {
|
enum Step {
|
||||||
@@ -69,7 +69,7 @@ const sendNetwork = async () => {
|
|||||||
/>
|
/>
|
||||||
<div v-if="flowStep == Step.Network">
|
<div v-if="flowStep == Step.Network">
|
||||||
<SendNetwork
|
<SendNetwork
|
||||||
:sellerId="user.sellerId.value"
|
:sellerId="Number(user.sellerId.value)"
|
||||||
:offer="Number(user.seller.value.offer)"
|
:offer="Number(user.seller.value.offer)"
|
||||||
:selected-token="user.selectedToken.value"
|
:selected-token="user.selectedToken.value"
|
||||||
v-if="!loading"
|
v-if="!loading"
|
||||||
|
|||||||