Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: integrate starknetId #218

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"@radix-ui/react-dialog": "^1.0.4",
"@radix-ui/react-tabs": "^1.0.4",
"@radix-ui/react-toolbar": "^1.0.4",
"@starknet-react/chains": "^0.1.6",
"@starknet-react/core": "^2.2.4",
"@starknet-react/chains": "^0.1.7",
"@starknet-react/core": "^2.8.1",
"@t3-oss/env-nextjs": "^0.3.1",
"@tanstack/react-query": "^4.29.7",
"@trpc/client": "^10.26.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { useAccount as useStarknetAccount } from "@starknet-react/core";
import {
useStarkProfile,
useAccount as useStarknetAccount,
} from "@starknet-react/core";
import { Typography } from "design-system";
import { useMemo } from "react";
import { useAccount as useEthereumAccount } from "wagmi";
Expand All @@ -14,6 +17,10 @@ export default function TransferNftsWalletSummary() {
const { address: ethereumAddress } = useEthereumAccount();
const { address: starknetAddress } = useStarknetAccount();

const { data: starkProfile } = useStarkProfile({
address: starknetAddress,
});

// TODO @YohanTz: Hook wrapper around wagmi and starknet-react
const shortEthereumAddress = useMemo(
() =>
Expand All @@ -33,7 +40,7 @@ export default function TransferNftsWalletSummary() {

const shortAddressByChain: Record<Chain, string | undefined> = {
Ethereum: shortEthereumAddress,
Starknet: shortStarknetAddress,
Starknet: starkProfile?.name ?? shortStarknetAddress,
};

return (
Expand Down
19 changes: 13 additions & 6 deletions apps/web/src/app/_components/ConnectStarkNetButton.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { useAccount, useStarkName } from "@starknet-react/core";
import { useAccount, useStarkProfile } from "@starknet-react/core";
import { Typography } from "design-system";
import Image from "next/image";
import { useMemo } from "react";

import { useIsSSR } from "~/app/_hooks/useIsSSR";
import { getStarknetPFPIfExists } from "~/utils/profile";

import {
CHAIN_LOGOS_BY_NAME,
Expand All @@ -17,7 +18,9 @@ export default function ConnectStarknetButton() {
const { address, connector, isConnected } = useAccount();
const { toggleConnectStarknetWalletModal } = useConnectModals();

const { data: starkName } = useStarkName({ address });
const { data: starkProfile } = useStarkProfile({
address,
});

const shortAddress = useMemo(
() => (address ? `${address.slice(0, 6)}...${address.slice(-4)}` : ""),
Expand All @@ -35,7 +38,9 @@ export default function ConnectStarknetButton() {
onClick={toggleConnectStarknetWalletModal}
>
<Typography variant="button_text_xs">
{isConnected ? starkName ?? shortAddress : "Connect Starknet Wallet"}
{isConnected
? starkProfile?.name ?? shortAddress
: "Connect Starknet Wallet"}
</Typography>
<div className="flex">
<Image
Expand All @@ -45,11 +50,13 @@ export default function ConnectStarknetButton() {
width={28}
/>
{connector !== undefined && (
<Image
//eslint-disable-next-line @next/next/no-img-element
<img
src={
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
WALLET_LOGOS_BY_ID[connector.id] ??
DEFAULT_STARKNET_CONNECTOR_LOGO
getStarknetPFPIfExists(starkProfile?.profilePicture) ??
WALLET_LOGOS_BY_ID[connector.id]?.src ??
DEFAULT_STARKNET_CONNECTOR_LOGO.src
}
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions, @typescript-eslint/unbound-method
alt={`${connector.name} logo`}
Expand Down
19 changes: 16 additions & 3 deletions apps/web/src/app/_components/StarknetConnectorList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
useBalance,
useConnect,
useDisconnect,
useStarkProfile,
} from "@starknet-react/core";
import clsx from "clsx";
import { Typography } from "design-system";
Expand All @@ -13,6 +14,8 @@ import Image from "next/image";
import { useEffect, useMemo, useState } from "react";
import { useCopyToClipboard } from "usehooks-ts";

import { getStarknetPFPIfExists } from "~/utils/profile";

import {
CHAIN_WALLET_ILLUSTRATION_BY_NAME,
DOWNLOAD_LINK_BY_CONNECTOR_ID,
Expand Down Expand Up @@ -41,6 +44,10 @@ export default function StarknetConnectorList({
string | undefined
>(undefined);

const { data: starkProfile } = useStarkProfile({
address,
});

useEffect(() => {
if (showCopiedMessage) {
const timer = setTimeout(() => {
Expand Down Expand Up @@ -103,16 +110,22 @@ export default function StarknetConnectorList({
)}
>
{activeConnector?.id !== undefined && (
<Image
//eslint-disable-next-line @next/next/no-img-element
<img
src={
getStarknetPFPIfExists(starkProfile?.profilePicture) ??
WALLET_LOGOS_BY_ID[activeConnector?.id]?.src ??
""
}
alt="connector"
className="rounded-full"
height={28}
src={WALLET_LOGOS_BY_ID[activeConnector?.id] ?? ""}
width={28}
/>
)}
<div className="relative mx-auto">
<Typography className="mx-auto" variant="button_text_s">
{shortAddress}
{starkProfile?.name ?? shortAddress}
</Typography>
<AnimatePresence>
{showCopiedMessage && (
Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/utils/profile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const getStarknetPFPIfExists = ( profilePicture: string | undefined ) => {
return profilePicture !== "https://starknet.id/api/identicons/0" ? profilePicture : undefined
}
69 changes: 37 additions & 32 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading