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