-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: WalletConnect integration, part 2, pairing list
- Loading branch information
1 parent
022c811
commit 3227347
Showing
23 changed files
with
268 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
apps/web/src/components/WalletConnect/WalletConnectPeers.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import { Center, Divider, Flex, IconButton, Image, Text, VStack } from "@chakra-ui/react"; | ||
import { useDisconnectWalletConnectPeer, useGetWcPeerListToggle, walletKit } from "@umami/state"; | ||
import { parsePkh } from "@umami/tezos"; | ||
import { type SessionTypes } from "@walletconnect/types"; | ||
import { getSdkError } from "@walletconnect/utils"; | ||
import capitalize from "lodash/capitalize"; | ||
|
||
import { CodeSandboxIcon, StubIcon as TrashIcon } from "../../assets/icons"; | ||
import { useColor } from "../../styles/useColor"; | ||
import { AddressPill } from "../AddressPill"; | ||
import { EmptyMessage } from "../EmptyMessage"; | ||
|
||
/** | ||
* Component displaying a list of connected dApps. | ||
* | ||
* Loads dApps data from WalletConnct API and displays it in a list. | ||
*/ | ||
export const WcPeers = () => { | ||
const sessions: Record<string, SessionTypes.Struct> = walletKit.getActiveSessions(); | ||
useGetWcPeerListToggle(); | ||
|
||
if (Object.keys(sessions).length === 0) { | ||
return ( | ||
<EmptyMessage | ||
alignItems="flex-start" | ||
marginTop="40px" | ||
data-testid="wc-peers-empty" | ||
subtitle="No WalltConnect Apps to show" | ||
title="Your WalletConnect Apps will appear here..." | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<VStack | ||
alignItems="flex-start" | ||
gap="24px" | ||
marginTop="24px" | ||
data-testid="wc-peers" | ||
divider={<Divider />} | ||
spacing="0" | ||
> | ||
{ | ||
// loop peers and print PeerRow | ||
Object.entries(sessions).map(([topic, sessionInfo]) => ( | ||
<PeerRow key={topic} sessionInfo={sessionInfo} /> | ||
)) | ||
} | ||
</VStack> | ||
); | ||
}; | ||
|
||
/** | ||
* Component for displaying info about single connected dApp. | ||
* | ||
* @param sessionInfo - sessionInfo provided by wc Api + computed dAppId. | ||
* @param onRemove - action for deleting dApp connection. | ||
*/ | ||
const PeerRow = ({ sessionInfo }: { sessionInfo: SessionTypes.Struct }) => { | ||
const color = useColor(); | ||
const disconnectWalletConnectPeer = useDisconnectWalletConnectPeer(); | ||
|
||
return ( | ||
<Center | ||
alignItems="center" | ||
justifyContent="space-between" | ||
width="full" | ||
height="60px" | ||
data-testid="peer-row" | ||
> | ||
<Flex height="100%"> | ||
<Center width="60px" marginRight="12px"> | ||
<Image | ||
objectFit="cover" | ||
fallback={<CodeSandboxIcon width="36px" height="36px" />} | ||
src={sessionInfo.peer.metadata.icons[0]} | ||
/> | ||
</Center> | ||
<Center alignItems="flex-start" flexDirection="column" gap="6px"> | ||
<Text color={color("900")} size="lg"> | ||
{sessionInfo.peer.metadata.name} | ||
</Text> | ||
<StoredSessionInfo sessionInfo={sessionInfo} /> | ||
</Center> | ||
</Flex> | ||
<IconButton | ||
color={color("500")} | ||
aria-label="Remove Peer" | ||
icon={<TrashIcon />} | ||
onClick={() => | ||
disconnectWalletConnectPeer({ | ||
topic: sessionInfo.topic, | ||
reason: getSdkError("USER_DISCONNECTED"), | ||
}) | ||
} | ||
variant="iconButtonSolid" | ||
/> | ||
</Center> | ||
); | ||
}; | ||
|
||
/** | ||
* Component for displaying additional info about connection with a dApp. | ||
* | ||
* Displays {@link AddressPill} with a connected account and network type. | ||
* | ||
* @param sessionInfo - sessionInfo provided by WalletConnect Api. | ||
* Account is stored in format: tezos:ghostnet:tz1... | ||
* Network is stored in format: tezos:mainnet | ||
*/ | ||
const StoredSessionInfo = ({ sessionInfo }: { sessionInfo: SessionTypes.Struct }) => ( | ||
<Flex> | ||
<AddressPill | ||
marginRight="10px" | ||
address={parsePkh(sessionInfo.namespaces.tezos.accounts[0].split(":")[2])} | ||
/> | ||
<Divider marginRight="10px" orientation="vertical" /> | ||
<Text marginTop="2px" marginRight="4px" fontWeight={600} size="sm"> | ||
Network: | ||
</Text> | ||
<Text marginTop="2px" data-testid="dapp-connection-network" size="sm"> | ||
{capitalize(sessionInfo.namespaces.tezos.chains?.[0].split(":")[1] ?? "")} | ||
</Text> | ||
</Flex> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./WalletConnectProvider"; | ||
export * from "./WalletConnectPeers"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.