Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ross Bulat committed Mar 9, 2024
1 parent 3f72e80 commit 4790960
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
12 changes: 9 additions & 3 deletions src/controllers/ApiController/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ export class ApiController {

// Instantiate a new `Api` instance with the supplied chain id and endpoint.
static async instantiate(tabId: number, chainId: ChainId, endpoint: string) {
if (!this.instances[tabId]) {
this.instances[tabId] = new Api(tabId, chainId, endpoint);
await this.instances[tabId].initialize();
// NOTE: This method should only be called to connect to a new instance. We therefore assume we
// want to disconnect from existing instances for this tab. The following condition will only be
// met if there is an exsiting stale instnace in class state, of if this method is used
// incorrectly.
if (this.instances[tabId]) {
await this.destroy(tabId);
}

this.instances[tabId] = new Api(tabId, chainId, endpoint);
await this.instances[tabId].initialize();
}

// Gracefully disconnect and then destroy an api instance.
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useRedirectOnInactive/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export const useRedirectOnInactive = (tabId: number) => {
const { setActiveSection } = useSection();

const apiStatus = getApiStatus(tabId);
const apiInactive = [undefined, 'disconnected'].includes(apiStatus);
const INACTIVE_API_STATUSES = ['connected', 'disconnected', 'error'];
const apiInactive = INACTIVE_API_STATUSES.includes(apiStatus);

// Redirect to section 0 if api is no longer connected. Do not persist - user might want to land
// on this section again on subsequent visits.
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Default/Connect/LocaNodeInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const LocalNodeInput = () => {

// Handle input change.
const onChange = (value: string) => {
// If trimmed value and the current value is empty, don't update.
// If trimmed value or the current value is empty, don't update.
if (!(!value.trim().length && customNodeUrl === '')) {
setCustomNodeUrl(activeTabId, value);
}
Expand Down

0 comments on commit 4790960

Please sign in to comment.