fixed network selection (hex string) and icons
This commit is contained in:
parent
a906fa136d
commit
358ae7410f
@ -14,9 +14,10 @@ const targetNetwork = ref(DEFAULT_NETWORK);
|
|||||||
|
|
||||||
const web3Onboard = init({
|
const web3Onboard = init({
|
||||||
wallets: [injected],
|
wallets: [injected],
|
||||||
chains: Object.entries(Networks).map(([, network]) => ({
|
chains: Object.values(Networks).map((network) => ({
|
||||||
id: network.id,
|
id: network.id,
|
||||||
label: network.nativeCurrency.symbol,
|
token: network.nativeCurrency.symbol,
|
||||||
|
label: network.name,
|
||||||
rpcUrl: network.rpcUrls.default.http[0],
|
rpcUrl: network.rpcUrls.default.http[0],
|
||||||
})),
|
})),
|
||||||
connect: {
|
connect: {
|
||||||
|
|||||||
@ -80,9 +80,10 @@ const closeMenu = (): void => {
|
|||||||
|
|
||||||
const networkChange = async (network: NetworkConfig): 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: String(network.id),
|
chainId: `0x${chainId}`,
|
||||||
wallet: connectedWallet.value?.label || "",
|
wallet: connectedWallet.value?.label || "",
|
||||||
});
|
});
|
||||||
user.setNetwork(network);
|
user.setNetwork(network);
|
||||||
|
|||||||
@ -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: network.value.id,
|
chainId: `0x${chainId}`,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|||||||
@ -12,7 +12,7 @@ export const Networks: {[key:string]: NetworkConfig} = {
|
|||||||
subgraphUrls: [import.meta.env.VITE_SEPOLIA_SUBGRAPH_URL]
|
subgraphUrls: [import.meta.env.VITE_SEPOLIA_SUBGRAPH_URL]
|
||||||
},
|
},
|
||||||
rootstockTestnet: { ...rootstockTestnet,
|
rootstockTestnet: { ...rootstockTestnet,
|
||||||
rpcUrls: { default: { http: [import.meta.env.VITE_ROOTSTOCK_API_URL]}},
|
rpcUrls: { default: { http: [import.meta.env.VITE_RSK_API_URL]}},
|
||||||
contracts: { ...rootstockTestnet.contracts,
|
contracts: { ...rootstockTestnet.contracts,
|
||||||
p2pix: {address:"0x57Dcba05980761169508886eEdc6f5E7EC0411Dc"} },
|
p2pix: {address:"0x57Dcba05980761169508886eEdc6f5E7EC0411Dc"} },
|
||||||
tokens: {
|
tokens: {
|
||||||
|
|||||||
@ -7,17 +7,16 @@ export const imagesPath = import.meta.glob<string>("@/assets/*.{png,svg}", {
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const getNetworkImage = (networkName: string): string => {
|
export const getNetworkImage = (networkName: string): string => {
|
||||||
|
const imageName = networkName
|
||||||
|
.toLowerCase()
|
||||||
|
.replace(/[^a-z0-9]/g, '-');
|
||||||
try {
|
try {
|
||||||
const path = Object.keys(imagesPath).find((key) =>
|
const path = Object.keys(imagesPath).find((key) =>
|
||||||
key.endsWith(`${networkName.toLowerCase()}.svg`)
|
key.endsWith(`${imageName}.svg`)
|
||||||
);
|
);
|
||||||
return path ? imagesPath[path] : "";
|
return path ? imagesPath[path] : "";
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching network image");
|
console.error("Error fetching network image");
|
||||||
const path = Object.keys(imagesPath).find((key) =>
|
|
||||||
key.endsWith(`invalidIcon.svg`)
|
|
||||||
);
|
|
||||||
return path ? imagesPath[path] : "";
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user