Skip to content

Commit

Permalink
feat: HttpAgent now uses a default address
Browse files Browse the repository at this point in the history
  • Loading branch information
krpeacock committed Aug 11, 2023
1 parent 3bb4f8c commit 9b35214
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/generated/changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ <h1>Agent-JS Changelog</h1>
<section>
<h2>Version x.x.x</h2>
<ul>
<li>
Feat: HttpAgent now uses a default address of https://icp-api.io. Users will be warned for
not setting a host, but the code will default to mainnet.
</li>
<li>
Feat: use webcrypto or node crypto instead of Math.random for nonce generation if
available
Expand Down
5 changes: 4 additions & 1 deletion packages/agent/src/agent/http/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@ export class HttpAgent implements Agent {
} else {
const location = typeof window !== 'undefined' ? window.location : undefined;
if (!location) {
throw new Error('Must specify a host to connect to.');
this._host = new URL('https://icp-api.io');
console.warn(
'Could not infer host from window.location, defaulting to mainnet gateway of https://icp-api.io. Please provide a host to the HttpAgent constructor to avoid this warning.',
);
}
this._host = new URL(location + '');
}
Expand Down

0 comments on commit 9b35214

Please sign in to comment.