Skip to content

Commit

Permalink
Merge pull request #1244 from trilitech/fix-hanging-beacon-permission…
Browse files Browse the repository at this point in the history
…-request-modal

Close beacon permission request modal on sign
  • Loading branch information
serjonya-trili authored May 14, 2024
2 parents 9ce0830 + 68488ba commit 1051354
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions src/utils/beacon/PermissionRequestModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,25 @@ import {
Text,
} from "@chakra-ui/react";
import { capitalize } from "lodash";
import React from "react";
import React, { useContext } from "react";
import { FormProvider, useForm } from "react-hook-form";

import { WalletClient } from "./WalletClient";
import { JsValueWrap } from "../../components/AccountDrawer/JsValueWrap";
import { OwnedImplicitAccountsAutocomplete } from "../../components/AddressAutocomplete";
import { DynamicModalContext } from "../../components/DynamicModal";
import colors from "../../style/colors";
import { useAddConnection } from "../hooks/beaconHooks";
import { useGetImplicitAccount } from "../hooks/getAccountDataHooks";
import { useAsyncActionHandler } from "../hooks/useAsyncActionHandler";

export const PermissionRequestModal: React.FC<{
request: PermissionRequestOutput;
}> = ({ request }) => {
const addConnectionToBeaconSlice = useAddConnection();
const getAccount = useGetImplicitAccount();
const { onClose } = useContext(DynamicModalContext);
const { handleAsyncAction } = useAsyncActionHandler();
const form = useForm<{ address: string }>({
mode: "onBlur",
});
Expand All @@ -47,22 +51,23 @@ export const PermissionRequestModal: React.FC<{
formState: { errors, isValid },
} = form;

const grant = async () => {
const account = getAccount(getValues().address);
const response: BeaconResponseInputMessage = {
type: BeaconMessageType.PermissionResponse,
network: request.network,
scopes: request.scopes,
id: request.id,
publicKey: account.pk,
// TODO: update when we start supporting abstracted accounts
walletType: "implicit",
};
const grant = () =>
handleAsyncAction(async () => {
const account = getAccount(getValues().address);
const response: BeaconResponseInputMessage = {
type: BeaconMessageType.PermissionResponse,
network: request.network,
scopes: request.scopes,
id: request.id,
publicKey: account.pk,
// TODO: update when we start supporting abstracted accounts
walletType: "implicit",
};

await WalletClient.respond(response);
await WalletClient.respond(response);

addConnectionToBeaconSlice(request.senderId, account.address.pkh, request.network.type);
};
addConnectionToBeaconSlice(request.senderId, account.address.pkh, request.network.type);
}).finally(onClose);

return (
<ModalContent>
Expand Down Expand Up @@ -124,7 +129,7 @@ export const PermissionRequestModal: React.FC<{
</FormProvider>
</ModalBody>
<ModalFooter>
<Button width="100%" isDisabled={!isValid} onClick={_ => grant()} size="lg">
<Button width="100%" isDisabled={!isValid} onClick={grant} size="lg">
Sign
</Button>
</ModalFooter>
Expand Down

1 comment on commit 1051354

@github-actions
Copy link

Choose a reason for hiding this comment

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

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements 89.57% 3573/3989
🟢 Branches 81.84% 1248/1525
🟢 Functions 87.91% 1098/1249
🟢 Lines 89.5% 3377/3773

Test suite run success

1390 tests passing in 180 suites.

Report generated by 🧪jest coverage report action from 1051354

Please sign in to comment.