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

Update tx popup route guard #811

Merged
merged 1 commit into from
Mar 21, 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
8 changes: 5 additions & 3 deletions apps/extension/src/entry/popup-root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ chrome.runtime.onMessage.addListener(
(req: unknown, _: chrome.runtime.MessageSender, responder: (x: unknown) => void) => {
if (isPopupRequest(req)) {
try {
if (isTxApprovalRequest(req))
if (isTxApprovalRequest(req)) {
void txApprovalSelector(useStore.getState()).acceptRequest(req, responder);
else if (isOriginApprovalRequest(req))
} else if (isOriginApprovalRequest(req)) {
originApprovalSelector(useStore.getState()).acceptRequest(req, responder);
else throw new Error('Unknown popup request');
} else {
throw new Error('Unknown popup request');
}
} catch (e) {
responder({
type: req.type,
Expand Down
5 changes: 1 addition & 4 deletions apps/extension/src/message/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,4 @@ export const isOriginApprovalRequest = (req: unknown): req is InternalRequest<Or
isPopupRequest(req) && req.type === PopupType.OriginApproval && 'origin' in req.request;

export const isTxApprovalRequest = (req: unknown): req is InternalRequest<TxApproval> =>
isPopupRequest(req) &&
req.type === PopupType.TxApproval &&
'authorizeRequest' in req.request &&
'transactionView' in req.request;
isPopupRequest(req) && req.type === PopupType.TxApproval && 'authorizeRequest' in req.request;
5 changes: 4 additions & 1 deletion apps/extension/src/state/tx-approval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,13 @@ export const createTxApprovalSlice = (): SliceCreator<TxApprovalSlice> => (set,
return denomMetadata ?? new Metadata();
};

const wallets = await localExtStorage.get('wallets');
const activeWalletFvk = wallets[0]?.fullViewingKey ?? '';

const transactionView = await viewTransactionPlan(
authorizeRequest.plan ?? new TransactionPlan(),
getMetadata,
(await localExtStorage.get('wallets'))[0]?.fullViewingKey ?? '',
activeWalletFvk,
);

// pregenerate views from various perspectives.
Expand Down
Loading