Skip to content

Commit

Permalink
chore: move request account logic to new file
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed Jun 30, 2022
1 parent f48bf9b commit b6f788c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/background/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
inferLegacyMessage,
} from './legacy-external-message-handler';
import { popupCenter } from './popup-center';
import { requestAccounts } from './methods/request-accounts';

initSentry();
initContextMenuActions();
Expand Down Expand Up @@ -59,13 +60,7 @@ chrome.runtime.onConnect.addListener(port =>

switch (message.method) {
case RpcMethods[RpcMethods.stx_requestAccounts]: {
const params = new URLSearchParams();
params.set('tabId', port.sender.tab.id.toString());
params.set('id', message.id);
params.set('origin', port.sender.origin.toString());
popupCenter({
url: `/popup-center.html#${RouteUrls.AccountRequest}?${params.toString()}`,
});
requestAccounts(port.sender.tab.id, port.sender.origin, message);
break;
}
}
Expand Down
15 changes: 15 additions & 0 deletions src/background/methods/request-accounts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { popupCenter } from '@background/popup-center';
import { SupportedRpcMessages } from '@shared/message-types';
import { RouteUrls } from '@shared/route-urls';

export function requestAccounts(tabId: number, origin: string, message: SupportedRpcMessages) {
const params = new URLSearchParams();

params.set('tabId', tabId.toString());
params.set('id', message.id);
params.set('origin', origin.toString());

popupCenter({
url: `/popup-center.html#${RouteUrls.AccountRequest}?${params.toString()}`,
});
}
12 changes: 12 additions & 0 deletions test-app/src/common/use-request-accounts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { useMemo, useState } from 'react';

export function useRequestAccountsInfo() {
const [accountKeys, setAccountKeys] = useState(null);
return useMemo(
() => ({
accountKeys,
setAccountKeys,
}),
[accountKeys]
);
}

0 comments on commit b6f788c

Please sign in to comment.