Skip to content

Commit

Permalink
Revert "chore: remove reward import"
Browse files Browse the repository at this point in the history
This reverts commit b2cf1d8.
  • Loading branch information
dominik-stumpf committed Jul 3, 2024
1 parent d15b1f6 commit 996f822
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { cn } from "@/lib/utils"
import useUser from "components/[guild]/hooks/useUser"
import useDelegateVaults from "components/common/Layout/components/Account/components/delegate/useDelegateVaults"
import { ReactNode, useMemo } from "react"
// import rewards from "rewards"
import rewards from "rewards"
import { PlatformName } from "types"
import { SocialAccount } from "./SocialAccount"

Expand All @@ -11,15 +11,14 @@ const AccountConnections = () => {
const vaults = useDelegateVaults()

const orderedSocials = useMemo(() => {
const connectedPlatforms: PlatformName[] = []
// platformUsers
// ?.filter((platformUser) => rewards[platformUser.platformName]?.isPlatform)
// ?.map((platformUser) => platformUser.platformName as string) ?? []
const notConnectedPlatforms: PlatformName[] = []
// Object.keys(rewards).filter(
// (platform) =>
// rewards[platform].isPlatform && !connectedPlatforms?.includes(platform)
// )
const connectedPlatforms =
platformUsers
?.filter((platformUser) => rewards[platformUser.platformName]?.isPlatform)
?.map((platformUser) => platformUser.platformName as string) ?? []
const notConnectedPlatforms = Object.keys(rewards).filter(
(platform) =>
rewards[platform].isPlatform && !connectedPlatforms?.includes(platform)
)
return [...connectedPlatforms, ...notConnectedPlatforms] as PlatformName[]
}, [platformUsers])

Expand All @@ -33,12 +32,12 @@ const AccountConnections = () => {
{platform === "EMAIL" ? (
<></>
) : // <EmailAddress key={"EMAIL"} />
platform === "FARCASTER" ? (
<></>
) : (
// <FarcasterProfile key={"FARCASTER"} />
<SocialAccount key={platform} type={platform} />
)}
platform === "FARCASTER" ? (
<></>
) : (
// <FarcasterProfile key={"FARCASTER"} />
<SocialAccount key={platform} type={platform} />
)}
{i < orderedSocials.length - 1 && (
<hr className="border-border-secondary" />
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import useDisconnect from "components/common/Layout/components/Account/component
import useMembership from "components/explorer/hooks/useMembership"
import { motion } from "framer-motion"
import { ReactNode } from "react"
// import rewards from "rewards"
import rewards from "rewards"
import { PlatformName } from "types"
import { DisconnectAccountButton } from "./DisconnectAccountButton"

Expand Down Expand Up @@ -62,48 +62,47 @@ const SocialAccountUI = ({
username?: string
isConnected?: boolean
children: ReactNode
}) =>
null
// const { icon: IconComponent, name: platformName } = rewards[type]
// const bgClassName = PLATFORM_COLORS[type] ?? ""
//
// return (
// <motion.div layout className="flex w-full items-center gap-3">
// <div
// className={cn(
// "relative flex size-7 items-center justify-center rounded-full bg-card text-white",
// bgClassName
// )}
// >
// {!!avatarUrl ? (
// <>
// <img
// src={avatarUrl}
// alt={username}
// className="h-full w-full rounded-full object-cover"
// />
// <div
// className={cn(
// "absolute -bottom-0.5 -right-1 flex size-4 items-center justify-center rounded-full border border-card-secondary",
// bgClassName
// )}
// >
// <IconComponent weight="bold" className="size-2.5" />
// </div>
// </>
// ) : (
// <IconComponent weight="bold" className="size-4" />
// )}
// </div>
//
// <span className="line-clamp-1 text-sm font-bold">
// {username ?? `${platformName} ${isConnected ? "connected" : ""}`}
// </span>
//
// {children}
// </motion.div>
// )
}) => {
const { icon: IconComponent, name: platformName } = rewards[type]
const bgClassName = PLATFORM_COLORS[type] ?? ""

return (
<motion.div layout className="flex w-full items-center gap-3">
<div
className={cn(
"relative flex size-7 items-center justify-center rounded-full bg-card text-white",
bgClassName
)}
>
{!!avatarUrl ? (
<>
<img
src={avatarUrl}
alt={username}
className="h-full w-full rounded-full object-cover"
/>
<div
className={cn(
"absolute -bottom-0.5 -right-1 flex size-4 items-center justify-center rounded-full border border-card-secondary",
bgClassName
)}
>
<IconComponent weight="bold" className="size-2.5" />
</div>
</>
) : (
<IconComponent weight="bold" className="size-4" />
)}
</div>

<span className="line-clamp-1 text-sm font-bold">
{username ?? `${platformName} ${isConnected ? "connected" : ""}`}
</span>

{children}
</motion.div>
)
}

// TODO: we should move these to `rewards.ts` eventually
const PLATFORM_COLORS = {
Expand Down Expand Up @@ -174,7 +173,7 @@ const DisconnectPlatformButton = ({ type }: { type: PlatformName }) => {
isLoading,
loadingText,
onConfirm,
name: '' // rewards[type].name,
name: rewards[type].name,
}}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { Alert } from "components/common/Modal"
import useToast from "hooks/useToast"
import { atom, useAtom } from "jotai"
import { useRef } from "react"
// import rewards from "rewards"
import rewards from "rewards"
import { PlatformName } from "types"
import capitalize from "utils/capitalize"
import shortenHex from "utils/shortenHex"
Expand All @@ -37,7 +37,7 @@ const PlatformMergeErrorAlert = () => {
const { addressOrDomain, platformName } = state || {}
const onClose = () => setState(false)

const socialAccountName = "social" // rewards[platformName]?.name ?? "social"
const socialAccountName = rewards[platformName]?.name ?? "social"
const { onConnect, isLoading } = useConnectPlatform(
platformName ?? "DISCORD",
() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useConnect } from "components/[guild]/JoinModal/hooks/useConnectPlatfor
import { Message } from "components/[guild]/JoinModal/hooks/useOauthPopupWindow"
import useUser from "components/[guild]/hooks/useUser"
import { useEffect } from "react"
// import rewards from "rewards"
import rewards from "rewards"

const useConnectFromLocalStorage = () => {
const { keyPair } = useUserPublic()
Expand All @@ -27,36 +27,36 @@ const useConnectFromLocalStorage = () => {
)
const { platformUsers } = useUser()

// useEffect(() => {
// if (!keyPair || !platformUsers) return
//
// Object.keys(rewards).forEach((platformName) => {
// const storageKey = `${platformName}_shouldConnect`
// const strData = window.localStorage.getItem(storageKey)
// window.localStorage.removeItem(storageKey)
//
// const isAlreadyConnected = platformUsers.some(
// (platformUser) => platformUser.platformName === platformName
// )
// if (isAlreadyConnected) return
//
// if (strData) {
// const data: Message = JSON.parse(strData)
//
// if (data.type === "OAUTH_SUCCESS") {
// onSubmit({ platformName, authData: data.data })
// } else {
// toast({
// variant: "error",
// title: data.data.error ?? "Error",
// description:
// data.data.errorDescription || `Failed to connect ${platformName}`,
// })
// captureEvent("OAuth error from localStorage data", { data: data.data })
// }
// }
// })
// }, [keyPair, platformUsers, onSubmit, toast, captureEvent])
useEffect(() => {
if (!keyPair || !platformUsers) return

Object.keys(rewards).forEach((platformName) => {
const storageKey = `${platformName}_shouldConnect`
const strData = window.localStorage.getItem(storageKey)
window.localStorage.removeItem(storageKey)

const isAlreadyConnected = platformUsers.some(
(platformUser) => platformUser.platformName === platformName
)
if (isAlreadyConnected) return

if (strData) {
const data: Message = JSON.parse(strData)

if (data.type === "OAUTH_SUCCESS") {
onSubmit({ platformName, authData: data.data })
} else {
toast({
variant: "error",
title: data.data.error ?? "Error",
description:
data.data.errorDescription || `Failed to connect ${platformName}`,
})
captureEvent("OAuth error from localStorage data", { data: data.data })
}
}
})
}, [keyPair, platformUsers, onSubmit, toast, captureEvent])
}

export default useConnectFromLocalStorage

0 comments on commit 996f822

Please sign in to comment.