fix: network selection
This commit is contained in:
parent
4b4ade2bfa
commit
9eee78fa91
@ -238,7 +238,7 @@ const handleSubmit = async (e: Event): Promise<void> => {
|
||||
height="24"
|
||||
v-if="
|
||||
selectedDeposits &&
|
||||
selectedDeposits.find((d) => d.network == Networks.rootstockTestnet)
|
||||
selectedDeposits.find((d) => d.network == Networks.rootstock)
|
||||
"
|
||||
/>
|
||||
<img
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
import { ref, computed } from 'vue';
|
||||
import { NetworkEnum } from '@/model/NetworkEnum';
|
||||
import { NetworkConfig } from '@/model/NetworkEnum';
|
||||
import { ref, computed, type Ref } from 'vue';
|
||||
import { isTestnetEnvironment } from '@/config/networks';
|
||||
import { sepolia, rootstock, rootstockTestnet } from "viem/chains";
|
||||
|
||||
export interface Transaction {
|
||||
id: string;
|
||||
@ -22,7 +24,7 @@ export interface AnalyticsData {
|
||||
totalReleases: string;
|
||||
}
|
||||
|
||||
export function useGraphQL(networkName: NetworkEnum) {
|
||||
export function useGraphQL(network: Ref<NetworkConfig>) {
|
||||
const searchAddress = ref('');
|
||||
const selectedType = ref('all');
|
||||
const loading = ref(false);
|
||||
@ -38,19 +40,21 @@ export function useGraphQL(networkName: NetworkEnum) {
|
||||
totalReleases: '0'
|
||||
});
|
||||
|
||||
const getGraphQLUrl = (networkName: string) => {
|
||||
switch (networkName) {
|
||||
case 'sepolia':
|
||||
return import.meta.env.VITE_SEPOLIA_SUBGRAPH_URL || 'https://api.studio.thegraph.com/query/113713/p-2-pix/sepolia';
|
||||
case 'rootstockTestnet':
|
||||
return import.meta.env.VITE_RSK_SUBGRAPH_URL || 'https://api.studio.thegraph.com/query/113713/p-2-pix/1';
|
||||
const getGraphQLUrl = () => {
|
||||
const rskNetworkName = isTestnetEnvironment() ? rootstockTestnet.name : rootstock.name;
|
||||
|
||||
switch (network.value.name) {
|
||||
case sepolia.name:
|
||||
return import.meta.env.VITE_SEPOLIA_SUBGRAPH_URL!;
|
||||
case rskNetworkName:
|
||||
return import.meta.env.VITE_RSK_SUBGRAPH_URL!;
|
||||
default:
|
||||
return 'https://api.studio.thegraph.com/query/113713/p-2-pix/sepolia';
|
||||
throw new Error(`Unsupported network: ${network.value.name}`);
|
||||
}
|
||||
};
|
||||
|
||||
const executeQuery = async (query: string, variables: any = {}) => {
|
||||
const url = getGraphQLUrl(networkName.toString());
|
||||
const url = getGraphQLUrl();
|
||||
|
||||
try {
|
||||
const response = await fetch(url, {
|
||||
|
||||
@ -1,22 +1,28 @@
|
||||
import { sepolia, rootstockTestnet } from "viem/chains";
|
||||
import { sepolia, rootstock, rootstockTestnet } from "viem/chains";
|
||||
import { NetworkConfig } from "@/model/NetworkEnum"
|
||||
// TODO: import addresses from p2pix-smart-contracts deployments
|
||||
|
||||
export const isTestnetEnvironment = () => {
|
||||
return import.meta.env.VITE_ENVIRONMENT === 'testnet' ||
|
||||
import.meta.env.NODE_ENV === 'development' ||
|
||||
import.meta.env.MODE === 'development';
|
||||
};
|
||||
|
||||
export const Networks: {[key:string]: NetworkConfig} = {
|
||||
sepolia: { ...sepolia,
|
||||
rpcUrls: { default: { http: [import.meta.env.VITE_SEPOLIA_API_URL]}},
|
||||
contracts: { ...sepolia.contracts,
|
||||
p2pix: {address:"0xb7cD135F5eFD9760981e02E2a898790b688939fe"} },
|
||||
p2pix: { address: import.meta.env.VITE_SEPOLIA_P2PIX_ADDRESS } },
|
||||
tokens: {
|
||||
BRZ: {address:"0x3eBE67A2C7bdB2081CBd34ba3281E90377462289"} },
|
||||
BRZ: { address: import.meta.env.VITE_SEPOLIA_TOKEN_ADDRESS } },
|
||||
subgraphUrls: [import.meta.env.VITE_SEPOLIA_SUBGRAPH_URL]
|
||||
},
|
||||
rootstockTestnet: { ...rootstockTestnet,
|
||||
rootstock: { ...(isTestnetEnvironment() ? rootstockTestnet : rootstock),
|
||||
rpcUrls: { default: { http: [import.meta.env.VITE_RSK_API_URL]}},
|
||||
contracts: { ...rootstockTestnet.contracts,
|
||||
p2pix: {address:"0x57Dcba05980761169508886eEdc6f5E7EC0411Dc"} },
|
||||
contracts: { ...(isTestnetEnvironment() ? rootstockTestnet.contracts : rootstock.contracts),
|
||||
p2pix: { address: import.meta.env.VITE_RSK_P2PIX_ADDRESS } },
|
||||
tokens: {
|
||||
BRZ: {address:"0xfE841c74250e57640390f46d914C88d22C51e82e"} },
|
||||
BRZ: { address: import.meta.env.VITE_RSK_TOKEN_ADDRESS } },
|
||||
subgraphUrls: [import.meta.env.VITE_RSK_SUBGRAPH_URL]
|
||||
},
|
||||
};
|
||||
|
||||
@ -6,10 +6,9 @@ import FormCard from '@/components/ui/FormCard.vue';
|
||||
import LoadingComponent from '@/components/ui/LoadingComponent.vue';
|
||||
import AnalyticsCard from '@/components/Explorer/AnalyticsCard.vue';
|
||||
import TransactionTable from '@/components/Explorer/TransactionTable.vue';
|
||||
import { getBlockExplorerUrl } from '@/config/networks';
|
||||
|
||||
const user = useUser();
|
||||
const { networkName } = user;
|
||||
const { network } = user;
|
||||
|
||||
const {
|
||||
searchAddress,
|
||||
@ -23,7 +22,7 @@ const {
|
||||
fetchUserActivity,
|
||||
fetchAnalytics,
|
||||
clearData
|
||||
} = useGraphQL(networkName.value);
|
||||
} = useGraphQL(network);
|
||||
|
||||
const transactionTypes = [
|
||||
{ key: 'all', label: 'Todas' },
|
||||
@ -45,7 +44,7 @@ watch(searchAddress, async (newAddress) => {
|
||||
}
|
||||
});
|
||||
|
||||
watch(networkName, async () => {
|
||||
watch(network, async () => {
|
||||
clearData();
|
||||
await Promise.all([
|
||||
fetchAllActivity(),
|
||||
@ -150,7 +149,7 @@ onMounted(async () => {
|
||||
|
||||
<TransactionTable
|
||||
:transactions="transactions"
|
||||
:network-explorer-url="getBlockExplorerUrl(networkName)"
|
||||
:network-explorer-url="network.blockExplorers?.default.url || ''"
|
||||
/>
|
||||
</FormCard>
|
||||
</div>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user