Skip to content

Commit

Permalink
Merge branch 'develop' into mochi-web-preview
Browse files Browse the repository at this point in the history
  • Loading branch information
tuanddd committed Feb 23, 2024
2 parents c38edfb + 7d74eb2 commit 9e0d58b
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 34 deletions.
4 changes: 2 additions & 2 deletions apps/mochi-web/components/Profile/ProfileWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export const ProfileWidget = () => {
}, [])

return (
<Card className="pb-3 space-y-4 shadow-input bg-background-body">
<Card className="pb-3 space-y-4 shadow-input !bg-background-body">
<div className="flex items-center space-x-2">
<Avatar src={me?.avatar || ''} size="xl" />
<div className="overflow-hidden flex-1 space-y-1">
Expand Down Expand Up @@ -391,7 +391,7 @@ export const ProfileWidget = () => {
)}
>
<TokenTableList
headerCellClassName="!bg-background-level1"
headerCellClassName="!bg-background-body"
isLoading={!wallets.length && isFetchingWallets}
data={data}
hideLastBorder
Expand Down
2 changes: 1 addition & 1 deletion apps/mochi-web/components/Profile/RecapSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export const RecapSection = () => {
const spending_pnl = getPnl(exchange?.spending_pnl)

return (
<Card className="px-0 pb-3 shadow-input bg-background-body">
<Card className="px-0 pb-3 shadow-input !bg-background-body">
<div className="flex items-center space-x-2 px-4">
<Typography level="h8">Your last 30 days recap</Typography>
<Tooltip
Expand Down
14 changes: 13 additions & 1 deletion apps/mochi-web/components/ProfileDropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { useFetchChangelogLatest } from '~hooks/app/useFetchChangelogLatest'
import { useRouter } from 'next/router'
import clsx from 'clsx'
import { isMobile } from '~utils/isMobile'
import {
DropdownMenu,
Expand Down Expand Up @@ -41,9 +44,11 @@ export default function ProfileDropdown({
children?: ReactNode
className?: string
}) {
const { pathname } = useRouter()
const { setIsNavOpen } = useIsNavOpenStore()
const { isLoggedIn, profile } = useLoginWidget()
const { activeTheme, setTheme, theme } = useTheme()
const { data: changelogData } = useFetchChangelogLatest()

let triggerRender = null
if (children) {
Expand Down Expand Up @@ -71,7 +76,14 @@ export default function ProfileDropdown({
<DropdownMenuPortal>
<DropdownMenuContent
wrapperClassName="z-[60]"
className="overflow-y-auto w-screen flex flex-col rounded-none h-[calc(100vh-56px)] lg:m-0 lg:block lg:w-auto lg:h-auto lg:rounded-lg lg:max-h-[calc(100dvh-100px)]"
className={clsx(
'overflow-y-auto w-screen flex flex-col rounded-none lg:m-0 lg:block lg:w-auto lg:h-auto lg:rounded-lg lg:max-h-[calc(100vh-100px)]',
{
'h-[calc(100vh-112px)]':
pathname === ROUTES.HOME && !!changelogData,
'h-[calc(100vh-56px)]': pathname !== ROUTES.HOME,
},
)}
sideOffset={9}
collisionPadding={{
right: 32,
Expand Down
49 changes: 32 additions & 17 deletions packages/web3/connect-wallet-widget/src/connect-wallet-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
useEffect,
useMemo,
useReducer,
useRef,
} from 'react'
import {
ExclamationTriangleOutlined,
Expand Down Expand Up @@ -64,8 +65,8 @@ const ConnectWalletWidget = forwardRef<
onConnectSuccess,
walletId,
}) => {
const debounce = useRef(0)
const connectors = useMemo(() => getProviders(dispatch), [dispatch])
const walletById = connectors.EVM.find((c) => c.id && c.id === walletId)

const [state, setState] = useReducer<Reducer>(
(state, action) => {
Expand All @@ -75,28 +76,42 @@ const ConnectWalletWidget = forwardRef<
}
},
{
step: walletById ? Step.Connecting : Step.Idle,
wallet: walletById || null,
step: Step.Idle,
wallet: null,
error: null,
},
)

useEffect(() => {
if (state.error) return
state.wallet
// connect and sign message
?.connect()
.then((res) => {
if (!res || !state.wallet) {
const error = 'Something went wrong'
setState({ error })
return
}
onConnectSuccess?.(state.wallet, res)
setState({ step: Step.Authenticated })
})
const walletById = connectors.EVM.find((c) => c.id && c.id === walletId)

setState({
step: walletById ? Step.Connecting : Step.Idle,
wallet: walletById || null,
error: null,
})
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [walletId])

useEffect(() => {
window.clearTimeout(debounce.current)
debounce.current = window.setTimeout(() => {
if (state.error || !state.wallet) return
state.wallet
// connect and sign message
.connect()
.then((res) => {
if (!res || !state.wallet) {
const error = 'Something went wrong'
setState({ error })
return
}
onConnectSuccess?.(state.wallet, res)
setState({ step: Step.Authenticated })
})
}, 100)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [state.error, state.wallet])
}, [state.wallet])

useEffect(() => {
if (state.step === Step.Idle) {
Expand Down
48 changes: 35 additions & 13 deletions packages/web3/login-widget/src/login-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,12 @@ export default function LoginContent({
step: number
direction: number
walletId?: string
isInteractive: boolean
}>({
step: chain ? 2 : 1,
direction: 0,
isInteractive: false,
})
const [isInteractive, setIsInteractive] = useState(false)

const handleAfterConnect = useCallback(
async (
Expand Down Expand Up @@ -168,7 +169,7 @@ export default function LoginContent({

useEffect(() => {
if (state.step) {
setTimeout(() => setIsInteractive(true), 350)
setTimeout(() => setState((s) => ({ ...s, isInteractive: true })), 350)
}
}, [state.step])

Expand Down Expand Up @@ -215,8 +216,12 @@ export default function LoginContent({
variant="soft"
color="neutral"
onClick={() => {
setIsInteractive(false)
setState({ step: 2, direction: 1, walletId: 'app.phantom' })
setState({
isInteractive: false,
step: 2,
direction: 1,
walletId: 'app.phantom',
})
}}
>
<Typography fontWeight="md" level="h7" color="neutral">
Expand All @@ -234,8 +239,12 @@ export default function LoginContent({
variant="soft"
color="neutral"
onClick={() => {
setIsInteractive(false)
setState({ step: 2, direction: 1, walletId: 'io.metamask' })
setState({
isInteractive: false,
step: 2,
direction: 1,
walletId: 'io.metamask',
})
}}
>
<Typography fontWeight="md" level="h7" color="neutral">
Expand All @@ -249,8 +258,12 @@ export default function LoginContent({
variant="soft"
color="neutral"
onClick={() => {
setIsInteractive(false)
setState({ step: 2, direction: 1, walletId: 'me.rainbow' })
setState({
isInteractive: false,
step: 2,
direction: 1,
walletId: 'me.rainbow',
})
}}
>
<Typography fontWeight="md" level="h7" color="neutral">
Expand All @@ -263,10 +276,14 @@ export default function LoginContent({
className={loginIntroBodyWalletButtonClsx()}
variant="soft"
color="neutral"
disabled={!isInteractive}
disabled={!state.isInteractive}
onClick={() => {
setIsInteractive(false)
setState({ step: 2, direction: 1, walletId: undefined })
setState({
isInteractive: false,
step: 2,
direction: 1,
walletId: undefined,
})
}}
>
<Typography fontWeight="md" level="h7" color="neutral">
Expand All @@ -292,8 +309,12 @@ export default function LoginContent({
<div className={loginWalletListHeaderClsx()}>
<IconButton
onClick={() => {
setIsInteractive(false)
setState({ step: 1, direction: -1, walletId: undefined })
setState({
isInteractive: false,
step: 1,
direction: -1,
walletId: undefined,
})
}}
label="close"
variant="link"
Expand All @@ -319,6 +340,7 @@ export default function LoginContent({
onStartConnect={(wallet) =>
setTitle(`Connect to ${wallet.name} Wallet`)
}
onEndConnect={() => setTitle('Supported Wallets')}
walletId={state.walletId}
/>
{/* {!chain && !isConnecting && ( */}
Expand Down

0 comments on commit 9e0d58b

Please sign in to comment.