-
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.
- Loading branch information
1 parent
6ff0ebf
commit f5056e3
Showing
22 changed files
with
447 additions
and
51 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
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,199 @@ | ||
import { Center, Divider, Flex, Heading, IconButton, Image, Text, VStack } from "@chakra-ui/react"; | ||
import { useGetWcConnectionInfo, useRemoveWcPeer, 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/AddressPill"; | ||
import { EmptyMessage } from "../EmptyMessage"; | ||
|
||
/** | ||
* Component displaying a list of connected dApps. | ||
* | ||
* Loads dApps data from {@link useWcPeers} hook & zips it with generated dAppIds. | ||
*/ | ||
export const WcPeers = () => { | ||
const wcPeers: Record<string, SessionTypes.Struct> = walletKit.getActiveSessions(); | ||
|
||
console.log("wcPeers", wcPeers); | ||
|
||
if (Object.keys(wcPeers).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(wcPeers).map(([topic, peerInfo]) => ( | ||
<PeerRow key={topic} peerInfo={peerInfo} /> | ||
)) | ||
} | ||
</VStack> | ||
); | ||
}; | ||
|
||
/* | ||
interface Struct { | ||
topic: string; | ||
topic: string; | ||
relay: RelayerTypes.ProtocolOptions; | ||
expiry: Expiry; | ||
acknowledged: boolean; | ||
controller: string; | ||
namespaces: Namespaces; | ||
requiredNamespaces: ProposalTypes.RequiredNamespaces; | ||
optionalNamespaces: ProposalTypes.OptionalNamespaces; | ||
sessionProperties?: ProposalTypes.SessionProperties; | ||
sessionConfig?: SessionConfig; | ||
self: { | ||
publicKey: string; | ||
metadata: SignClientTypes.Metadata; | ||
}; | ||
peer: { | ||
publicKey: string; | ||
metadata: SignClientTypes.Metadata; | ||
}; | ||
authentication?: AuthTypes.Cacao[]; | ||
transportType?: RelayerTypes.TransportType; | ||
} | ||
*/ | ||
|
||
/** | ||
* Component for displaying info about single connected dApp. | ||
* | ||
* @param peerInfo - peerInfo provided by wc Api + computed dAppId. | ||
* @param onRemove - action for deleting dApp connection. | ||
*/ | ||
const PeerRow = ({ peerInfo }: { peerInfo: SessionTypes.Struct }) => { | ||
const color = useColor(); | ||
const removePeer = useRemoveWcPeer(); | ||
|
||
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={peerInfo.peer.metadata.icons[0]} | ||
/> | ||
</Center> | ||
<Center alignItems="flex-start" flexDirection="column" gap="6px"> | ||
<Heading color={color("900")} size="lg"> | ||
{peerInfo.peer.metadata.name} | ||
</Heading> | ||
<StoredPeerInfo peerInfo={peerInfo} /> | ||
</Center> | ||
</Flex> | ||
<IconButton | ||
color={color("500")} | ||
aria-label="Remove Peer" | ||
icon={<TrashIcon />} | ||
onClick={() => | ||
removePeer({ topic: peerInfo.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, | ||
* if information about the connection is stored in {@link wcSlice}. | ||
* | ||
* @param peerInfo - peerInfo provided by wc Api + computed dAppId. | ||
*/ | ||
const StoredPeerInfo = ({ peerInfo }: { peerInfo: SessionTypes.Struct }) => { | ||
const connectionInfo = useGetWcConnectionInfo(peerInfo.topic); | ||
|
||
if (!connectionInfo) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Flex> | ||
<AddressPill marginRight="10px" address={parsePkh(connectionInfo.accountPkh)} /> | ||
<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(connectionInfo.networkType)} | ||
</Text> | ||
</Flex> | ||
); | ||
}; | ||
|
||
// import { Text } from "@chakra-ui/react"; | ||
// import { walletKit } from "@umami/state"; | ||
// import { type PairingTypes } from "@walletconnect/types"; | ||
// import { getSdkError } from "@walletconnect/utils"; | ||
// import { Fragment, useEffect } from "react"; | ||
|
||
// import PairingCard from "./PairingCard"; | ||
|
||
// export default function PairingsPage() { | ||
// // const [walletPairings ] = useState(web3wallet.core.pairing.getPairings()) | ||
|
||
// async function onDelete(topic: string) { | ||
// await walletKit.disconnectSession({ topic, reason: getSdkError("USER_DISCONNECTED") }); | ||
// const newPairings = pairings.filter(pairing => pairing.topic !== topic); | ||
// SettingsStore.setPairings(newPairings as PairingTypes.Struct[]); | ||
// } | ||
|
||
// useEffect(() => { | ||
// SettingsStore.setPairings(web3wallet.core.pairing.getPairings()); | ||
// }, []); | ||
|
||
// // console.log("pairings", walletPairings) | ||
// return ( | ||
// <Fragment> | ||
// {pairings.length ? ( | ||
// pairings.map(pairing => { | ||
// const { peerMetadata } = pairing; | ||
|
||
// return ( | ||
// <PairingCard | ||
// key={pairing.topic} | ||
// data-testid={"pairing-" + pairing.topic} | ||
// name={peerMetadata?.name} | ||
// onDelete={() => onDelete(pairing.topic)} | ||
// topic={pairing.topic} | ||
// url={peerMetadata?.url} | ||
// /> | ||
// ); | ||
// }) | ||
// ) : ( | ||
// <Text css={{ opacity: "0.5", textAlign: "center", marginTop: "$20" }}>No pairings</Text> | ||
// )} | ||
// </Fragment> | ||
// ); | ||
// } |
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 "./WcProvider"; | ||
export * from "./WcPeers"; |
Oops, something went wrong.