Skip to content

Commit

Permalink
feat: update sid.js (#834)
Browse files Browse the repository at this point in the history
  • Loading branch information
Marchand-Nicolas authored Oct 7, 2024
1 parent 833faea commit 18b1a87
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 306 deletions.
6 changes: 3 additions & 3 deletions components/UI/notifications/notificationDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const NotificationDetail: FunctionComponent<NotificationDetailProps> = ({
if (notification.type === NotificationType.TRANSACTION) {
if (isLoading) {
return <CircularProgress color="secondary" size={24} />;
} else if (isError || data?.status === "REJECTED") {
} else if (isError || data?.isRejected()) {
return <CloseCircleIcon width="24" color="" />;
} else {
return <DoneIcon width="24" color={theme.palette.primary.main} />;
Expand All @@ -61,7 +61,7 @@ const NotificationDetail: FunctionComponent<NotificationDetailProps> = ({
? "pending"
: isError
? "error"
: data?.status === "REJECTED"
: data?.isRejected()
? "error"
: "success";
}, [notification, isLoading, error, isError, data]);
Expand All @@ -79,7 +79,7 @@ const NotificationDetail: FunctionComponent<NotificationDetailProps> = ({
if (status !== notification.data.status) {
updateNotificationStatus(notification.data.hash, status);
}
}, [ isLoading, error, isError, data, status]);
}, [isLoading, error, isError, data, status]);

return (
<div className={styles.notif_detail}>
Expand Down
50 changes: 38 additions & 12 deletions components/navbar/walletButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { TEXT_TYPE } from "@constants/typography";
import { Connector } from "starknetkit";
import CopyAddress from "@components/UI/CopyAddress"; // Import the new CopyAddress component


type WalletButtonProps = {
setShowWallet: (showWallet: boolean) => void;
showWallet: boolean;
Expand All @@ -44,7 +43,8 @@ const WalletButton: FunctionComponent<WalletButtonProps> = ({
const [hovering, setHovering] = useState<boolean>(false);
const [unfocus, setUnfocus] = useState<boolean>(false);
const network = currentNetwork === "TESTNET" ? "testnet" : "mainnet";
const isWebWallet = (connector as Connector)?.wallet?.id === "argentWebWallet";
const isWebWallet =
(connector as Connector)?.wallet?.id === "argentWebWallet";

const buttonName = useMemo(
() =>
Expand Down Expand Up @@ -124,7 +124,12 @@ const WalletButton: FunctionComponent<WalletButtonProps> = ({
<>
<div className="flex items-center justify-between">
<div className={styles.buttonTextSection}>
<Typography type={TEXT_TYPE.BODY_DEFAULT} className={styles.buttonText}>{buttonName}</Typography>
<Typography
type={TEXT_TYPE.BODY_DEFAULT}
className={styles.buttonText}
>
{buttonName}
</Typography>
{txLoading ? (
<CircularProgress color="secondary" size={24} />
) : null}
Expand All @@ -146,29 +151,50 @@ const WalletButton: FunctionComponent<WalletButtonProps> = ({
<Link href="/leaderboard">
<button>
<TrophyIcon width="24" />
<Typography type={TEXT_TYPE.BUTTON_SMALL} color="secondary500">Leaderboard</Typography>
<Typography
type={TEXT_TYPE.BUTTON_SMALL}
color="secondary500"
>
Leaderboard
</Typography>
</button>
</Link>
<div className="flex items-center">
<CopyAddress
address={address ?? ""}
iconSize="24"
className={styles.copyButton}
wallet={true}/>
</div>
address={address ?? ""}
iconSize="24"
className={styles.copyButton}
wallet={true}
/>
</div>
{isWebWallet && (
<button onClick={handleOpenWebWallet}>
<ArgentIcon width="24" />
<Typography type={TEXT_TYPE.BUTTON_SMALL} color="secondary500">Web wallet Dashboard</Typography>
<Typography
type={TEXT_TYPE.BUTTON_SMALL}
color="secondary500"
>
Web wallet Dashboard
</Typography>
</button>
)}
<button onClick={handleWalletChange}>
<WalletIcon width="24" />
<Typography type={TEXT_TYPE.BUTTON_SMALL} color="secondary500">Change Wallet</Typography>
<Typography
type={TEXT_TYPE.BUTTON_SMALL}
color="secondary500"
>
Change Wallet
</Typography>
</button>
<button onClick={handleDisconnect}>
<LogoutIcon width="24" />
<Typography type={TEXT_TYPE.BUTTON_SMALL} color="secondary500">Disconnect</Typography>
<Typography
type={TEXT_TYPE.BUTTON_SMALL}
color="secondary500"
>
Disconnect
</Typography>
</button>
</div>
) : null}
Expand Down
8 changes: 3 additions & 5 deletions context/StarknetIdJsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { getCurrentNetwork } from "@utils/network";
import React from "react";
import { ReactNode, createContext, useMemo } from "react";
import { Provider, constants } from "starknet";
import { RpcProvider, constants } from "starknet";
import { StarknetIdNavigator } from "starknetid.js";

interface StarknetIdJsConfig {
Expand All @@ -21,10 +21,8 @@ export const StarknetIdJsProvider = ({ children }: { children: ReactNode }) => {
}, []);

const provider = useMemo(() => {
return new Provider({
rpc: {
nodeUrl: process.env.NEXT_PUBLIC_RPC_URL,
},
return new RpcProvider({
nodeUrl: process.env.NEXT_PUBLIC_RPC_URL,
});
}, []);

Expand Down
11 changes: 3 additions & 8 deletions hooks/useNotificationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,16 @@ export function useNotificationManager() {
}
return notification;
});

setNotifications(updatedNotifications);
};

const checkTransactionStatus = async (txHash: string) => {
const data = await provider.getTransactionReceipt(txHash);
if (data?.status === "REJECTED" || data?.status === "REVERTED") {
if (data?.isRejected() || data?.isReverted()) {
updateNotificationStatus(txHash, "error");
setUnread(true);
} else if (
data?.status === "ACCEPTED_ON_L2" ||
data?.status === "ACCEPTED_ON_L1" ||
data?.finality_status === "ACCEPTED_ON_L2" ||
data?.finality_status === "ACCEPTED_ON_L1"
) {
} else if (data?.isSuccess()) {
updateNotificationStatus(txHash, "success");
setUnread(true);
}
Expand Down
Loading

0 comments on commit 18b1a87

Please sign in to comment.