Skip to content

Commit

Permalink
tezos_getAccounts
Browse files Browse the repository at this point in the history
  • Loading branch information
dianasavvatina committed Dec 19, 2024
1 parent 5153a57 commit 689bd4c
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions apps/web/src/components/WalletConnect/useHandleWcRequest.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { SigningType } from "@airgap/beacon-wallet";
import { useToast } from "@chakra-ui/react";
import { useDynamicModalContext } from "@umami/components";
import { type ImplicitAccount, estimate, toAccountOperations } from "@umami/core";
import {
useAsyncActionHandler,
useFindNetwork,
useGetImplicitAccount,
useGetOwnedAccountSafe,
walletKit,
} from "@umami/state";
import { WalletConnectError } from "@umami/utils";
import { formatJsonRpcResult } from "@walletconnect/jsonrpc-utils";
import { type SessionTypes, type SignClientTypes, type Verify } from "@walletconnect/types";

import { SignPayloadRequestModal } from "../common/SignPayloadRequestModal";
Expand All @@ -18,7 +21,6 @@ import {
type SignHeaderProps,
type SignPayloadProps,
} from "../SendFlow/utils";

/**
* @returns a function that handles a beacon message and opens a modal with the appropriate content
*
Expand All @@ -31,6 +33,7 @@ export const useHandleWcRequest = () => {
const getAccount = useGetOwnedAccountSafe();
const getImplicitAccount = useGetImplicitAccount();
const findNetwork = useFindNetwork();
const toast = useToast();

return async (
event: {
Expand All @@ -54,11 +57,38 @@ export const useHandleWcRequest = () => {

switch (request.method) {
case "tezos_getAccounts": {
throw new WalletConnectError(
"Getting accounts is not supported yet",
"WC_METHOD_UNSUPPORTED",
session
);
const wcPeers = walletKit.getActiveSessions();
if (!(topic in wcPeers)) {
throw new WalletConnectError(
`Unknown session ${topic}`,
"UNAUTHORIZED_EVENT",
null
);
}
const session = wcPeers[topic];
const accountPkh = session.namespaces.tezos.accounts[0].split(":")[2];
const signer = getAccount(accountPkh);
if (!signer) {
throw new WalletConnectError(
`Unknown account, no signer: ${accountPkh}`,
"UNAUTHORIZED_EVENT",
session
);
}
const response = formatJsonRpcResult(id, [
{
algo: "ed25519",
address: accountPkh,
pubkey: accountPkh,
},
]);
await walletKit.respondSessionRequest({ topic, response });

toast({
description: "Successfully signed the payload",
status: "success",
});
return;
}

case "tezos_sign": {
Expand Down

0 comments on commit 689bd4c

Please sign in to comment.