Skip to content

Commit

Permalink
fix: dont crash on missing apiAddrs
Browse files Browse the repository at this point in the history
  • Loading branch information
samsiegart committed Jan 19, 2024
1 parent e0b82f7 commit b2448db
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 17 deletions.
15 changes: 5 additions & 10 deletions wallet/src/components/ConnectionSettingsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ const useNodeSuggestions = (networkConfigHref: string) => {
const networkConfig = await res.json();

if (didConfigChange) return;
setApiSuggestions(networkConfig.apiAddrs);
setRpcSuggestions(networkConfig.rpcAddrs);
setApiSuggestions(networkConfig.apiAddrs ?? []);
setRpcSuggestions(networkConfig.rpcAddrs ?? []);
};

updateSuggestions().catch(() =>
Expand Down Expand Up @@ -165,15 +165,10 @@ const ConnectionSettingsDialog = ({
case 'main':
case 'testnet':
case 'devnet':
case 'local':
setConfig({
...config,
href: `https://${value}.agoric.net/network-config`,
});
break;
case 'localhost':
setConfig({
...config,
href: `${window.location.origin}/wallet/network-config`,
href: networkConfigUrl.fromSource(value),
});
break;
case 'custom':
Expand All @@ -185,7 +180,7 @@ const ConnectionSettingsDialog = ({
<MenuItem value="main">Mainnet</MenuItem>
<MenuItem value="testnet">Testnet</MenuItem>
<MenuItem value="devnet">Devnet</MenuItem>
<MenuItem value="localhost">Localhost</MenuItem>
<MenuItem value="local">Local Chain</MenuItem>
<MenuItem value="custom">
<i>Custom URL</i>
</MenuItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ describe('Connection setting dialog', () => {
);

const networkSelect = component.find(Select).first();
act(() =>
networkSelect.props().onChange({ target: { value: 'localhost' } }),
);
act(() => networkSelect.props().onChange({ target: { value: 'local' } }));
component.update();

const textField = component.find(TextField).first();
Expand Down
2 changes: 1 addition & 1 deletion wallet/src/util/SuggestChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const makeChainInfo = (
if (config?.rpc) {
rpc = config.rpc;
} else {
const rpcAddr = rpcAddrs[rpcIndex];
const rpcAddr = rpcAddrs[rpcIndex] ?? '';
rpc = rpcAddr.match(/:\/\//) ? rpcAddr : `http://${rpcAddr}`;
}

Expand Down
5 changes: 2 additions & 3 deletions wallet/src/util/connections.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
export const KnownNetworkConfigUrls = {
main: 'https://main.agoric.net/network-config',
devnet: 'https://devnet.agoric.net/network-config',
testnet: 'https://testnet.agoric.net/network-config',
// for localhost skip https and assume it's subpathed to /wallet
localhost: 'http://localhost:3000/wallet/network-config',
testnet: 'https://emerynet.agoric.net/network-config',
local: `${window.location.origin}/wallet/network-config`,
};

export const DEFAULT_CONNECTION_CONFIGS = Object.values(
Expand Down

0 comments on commit b2448db

Please sign in to comment.