Skip to content

Commit

Permalink
Fix custom networks management (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibautBremand authored Jan 20, 2024
1 parent 8f3a766 commit 47cbf6e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
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

0 comments on commit 47cbf6e

Please sign in to comment.