Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix custom networks management #351

Merged
merged 1 commit into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/constants/src/network/network.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const FAUCET_XAHAU_TESTNET = 'https://xahau-test.net/accounts';
export interface NetworkNode {
chain: Chain;
name: Network;
customNetworkName?: string;
server: string;
nodes?: string[];
description: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ export const TransactionDetails: FC<TransactionDetailsProps> = ({
const mainToken = useMainToken();

const currentNetwork = useMemo(() => {
return getNetwork(chainName, networkName as Network);
try {
return getNetwork(chainName, networkName as Network);
} catch (error) {
return {
...getNetwork(chainName, 'Custom' as Network),
customNetworkName: networkName as string
};
}
}, [chainName, networkName]);

const expectedNetwork = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const NetworkProvider: FC = ({ children }) => {

const connectToNetwork = async () => {
const network = loadNetwork();
setNetworkName(network.name);
setNetworkName(network.customNetworkName ?? network.name);
if (chainName !== network.chain) {
setChainName(network.chain);
}
Expand Down Expand Up @@ -132,7 +132,7 @@ const NetworkProvider: FC = ({ children }) => {
try {
const loadedNetwork = loadNetwork();
const ws = await connectToLedger(loadedNetwork.server);
setNetworkName(loadedNetwork.name);
setNetworkName(loadedNetwork.customNetworkName ?? loadedNetwork.name);
setClient(ws);
setIsConnectionFailed(false);
} catch (err) {
Expand Down Expand Up @@ -214,7 +214,7 @@ const NetworkProvider: FC = ({ children }) => {
try {
await removeNetwork();
const network = await loadNetwork();
setNetworkName(network.name);
setNetworkName(network.customNetworkName ?? network.name);
} catch (err) {
Sentry.captureException(err);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/extension/src/utils/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ export const loadNetwork = () => {
if ('chain' in parsedData && 'name' in parsedData && 'server' in parsedData) {
return {
chain: parsedData.chain,
name: parsedData.name,
name: 'Custom' as Network,
customNetworkName: parsedData.name,
server: parsedData.server,
description: 'Custom network'
};
Expand Down
Loading