Skip to content

Commit

Permalink
Merge pull request #2288 from trilitech/wc_getacc
Browse files Browse the repository at this point in the history
feat: WalletConnect integration, part 9, get accounts
  • Loading branch information
dianasavvatina authored Jan 13, 2025
2 parents 87edd3a + ca8e935 commit c1a784b
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions apps/web/src/components/WalletConnect/useHandleWcRequest.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
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 {
Expand All @@ -9,7 +10,7 @@ import {
walletKit,
} from "@umami/state";
import { WalletConnectError } from "@umami/utils";
import { formatJsonRpcError } from "@walletconnect/jsonrpc-utils";
import { formatJsonRpcError, formatJsonRpcResult } from "@walletconnect/jsonrpc-utils";
import { type SessionTypes, type SignClientTypes, type Verify } from "@walletconnect/types";
import { type SdkErrorKey, getSdkError } from "@walletconnect/utils";

Expand All @@ -21,7 +22,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 @@ -34,6 +34,7 @@ export const useHandleWcRequest = () => {
const getAccount = useGetOwnedAccountSafe();
const getImplicitAccount = useGetImplicitAccount();
const findNetwork = useFindNetwork();
const toast = useToast();

return async (
event: {
Expand All @@ -57,11 +58,28 @@ 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 = getImplicitAccount(accountPkh);
const publicKey = signer.pk;
const response = formatJsonRpcResult(id, [
{
algo: "ed25519", // the only supported curve
address: accountPkh,
pubkey: publicKey,
},
]);
await walletKit.respondSessionRequest({ topic, response });

toast({
description: "Successfully provided the requested account data",
status: "success",
});
return;
}

case "tezos_sign": {
Expand Down

1 comment on commit c1a784b

@github-actions
Copy link

Choose a reason for hiding this comment

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

Title Lines Statements Branches Functions
apps/desktop Coverage: 83%
83.81% (1787/2132) 79.58% (850/1068) 78.27% (454/580)
apps/web Coverage: 83%
83.81% (1787/2132) 79.58% (850/1068) 78.27% (454/580)
packages/components Coverage: 97%
97.51% (196/201) 95.91% (94/98) 88.13% (52/59)
packages/core Coverage: 81%
82.47% (207/251) 72.72% (88/121) 81.35% (48/59)
packages/crypto Coverage: 100%
100% (43/43) 90.9% (10/11) 100% (7/7)
packages/data-polling Coverage: 97%
95.27% (141/148) 87.5% (21/24) 92.85% (39/42)
packages/multisig Coverage: 98%
98.47% (129/131) 85.71% (18/21) 100% (36/36)
packages/social-auth Coverage: 100%
100% (21/21) 100% (11/11) 100% (3/3)
packages/state Coverage: 85%
84.48% (828/980) 81.35% (192/236) 77.83% (302/388)
packages/tezos Coverage: 89%
88.72% (118/133) 94.59% (35/37) 86.84% (33/38)
packages/tzkt Coverage: 89%
87.32% (62/71) 87.5% (14/16) 80.48% (33/41)

Please sign in to comment.