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: getAddresses popup appearing randomly on core.app #67

Merged
merged 1 commit into from
Oct 15, 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
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,10 @@ describe('background/services/accounts/handlers/avalanche_getAddressesInRange.ts
];
const request = getPayload({ params: [0, 0, 2, 2] });
await handleRequest(buildRpcCall(request));
expect(canSkipApproval).toHaveBeenCalledWith(
'core.app',
3,
EXPOSED_DOMAINS
);
expect(canSkipApproval).toHaveBeenCalledWith('core.app', 3, {
allowInactiveTabs: true,
domainWhitelist: EXPOSED_DOMAINS,
});
});

it('sets the limit to 0 if not provided', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,10 @@ export class AvalancheGetAddressesInRangeHandler extends DAppRequestHandler<
});

if (
await canSkipApproval(
request.site.domain,
request.site.tabId,
EXPOSED_DOMAINS
)
await canSkipApproval(request.site.domain, request.site.tabId, {
domainWhitelist: EXPOSED_DOMAINS,
allowInactiveTabs: true,
})
Copy link
Contributor

@vvava vvava Oct 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we put all of the parameters in to an object then?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can simplify in a follow up PR (so I don't need to collect approvals after updating again 😄)

) {
return {
...request,
Expand Down
17 changes: 13 additions & 4 deletions src/utils/canSkipApproval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,23 @@ import { isSyncDomain } from '@src/background/services/network/utils/getSyncDoma
import { isActiveTab } from './isActiveTab';
import { runtime } from 'webextension-polyfill';

type SkipApprovalOptions = {
allowInactiveTabs?: boolean;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with dev having to explicitly say allowInactiveTabs rather than making the tabId optional. It feels less error-prone this way.

domainWhitelist?: string[];
};

export const canSkipApproval = async (
domain: string,
tabId: number,
exposedDomainList?: string[]
{ allowInactiveTabs, domainWhitelist }: SkipApprovalOptions = {}
) => {
if (!isSyncDomain(domain, domainWhitelist)) {
return false;
}

return (
isSyncDomain(domain, exposedDomainList) &&
// chrome.tabs.get(...) does not see extension popup
(domain === runtime.id || (await isActiveTab(tabId)))
allowInactiveTabs ||
domain === runtime.id || // chrome.tabs.get(...) does not see extension popup
(await isActiveTab(tabId))
);
};
Loading