Skip to content

Commit

Permalink
feat(wallet): add open beta warning
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcnk committed Jun 10, 2024
1 parent dacebe3 commit 94972b7
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 23 deletions.
2 changes: 1 addition & 1 deletion apps/extension/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@palladxyz/extension",
"version": "0.5.0",
"version": "0.5.1",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
2 changes: 1 addition & 1 deletion packages/features/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@palladxyz/features",
"version": "0.5.0",
"version": "0.5.1",
"description": "",
"type": "module",
"module": "dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/features/src/address-book/views/address-book.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const AddressBookView = ({
<div
// biome-ignore lint/suspicious/noArrayIndexKey: won't update
key={index}
className="relative px-6 flex justify-between btn text-base font-medium overflow-x-auto group"
className="relative px-6 flex justify-between btn text-base font-medium overflow-hidden group"
data-testid="addressBook/contact"
>
<Link to="/send" state={{ address: contact.address }}>
Expand Down
19 changes: 6 additions & 13 deletions packages/features/src/common/store/app.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,40 @@
import { getLocalPersistence } from "@palladxyz/persistence"
import { DEFAULT_NETWORK } from "@palladxyz/vault"
import { create } from "zustand"
import { createJSONStorage, persist } from "zustand/middleware"

import { VaultState } from "../lib/const"

// TODO: Make network a generic type that can support networks other than just Mina
type AppState = {
network: string
vaultState: VaultState
shareData: boolean
betaBannerVisible: boolean
}

type AppQueries = {
isInitialized: () => boolean
}

type AppMutators = {
setNetwork: (network: string) => void
setVaultState: (vaultState: VaultState) => void
setVaultStateInitialized: () => void
setVaultStateUninitialized: () => void
setShareData: (shareData: boolean) => void
setBetaBannerVisible: (betaBannerVisible: boolean) => void
}

type AppStore = AppState & AppMutators & AppQueries

// TODO: this should be with vite
// const VITE_APP_DEFAULT_NETWORK = import.meta.env.VITE_APP_DEFAULT_NETWORK || 'Mainnet'
const defaultNetwork = DEFAULT_NETWORK

export const useAppStore = create<AppStore>()(
persist(
(set, get) => ({
network: defaultNetwork,
betaBannerVisible: true,
vaultState: VaultState[VaultState.UNINITIALIZED],
shareData: true,
isInitialized: () => {
const { vaultState } = get()
return vaultState === VaultState[VaultState.INITIALIZED]
},
setNetwork(network) {
return set({
network,
})
},
setShareData(shareData) {
return set({ shareData })
},
Expand All @@ -59,6 +49,9 @@ export const useAppStore = create<AppStore>()(
const { setVaultState } = get()
return setVaultState(VaultState.UNINITIALIZED)
},
setBetaBannerVisible(betaBannerVisible) {
return set({ betaBannerVisible })
},
}),
{
name: "PalladApp",
Expand Down
10 changes: 6 additions & 4 deletions packages/features/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Toaster } from "sonner"

import { AddressBookRoute } from "./address-book/routes/address-book"
import { NewAddressRoute } from "./address-book/routes/new-address"
import { useAppStore } from "./common/store/app"
import { ErrorView } from "./error-renderer/views/error"
import { UnlockWalletRoute } from "./lock/routes/unlock-wallet"
import { NotFoundRoute } from "./not-found/routes/not-found"
Expand Down Expand Up @@ -42,11 +43,12 @@ import { OverviewRoute } from "./wallet/routes/overview"

dayjs.extend(relativeTime)

const mixpanelConfig = {
track_pageview: true,
}

export const Router = () => {
const shareData = useAppStore((state) => state.shareData)
const mixpanelConfig = {
track_pageview: true,
opt_out_tracking_by_default: shareData ?? false,
}
return (
<MixpanelProvider
config={mixpanelConfig}
Expand Down
11 changes: 10 additions & 1 deletion packages/features/src/settings/routes/privacy.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import { useAppStore } from "@/common/store/app"
import { useNavigate } from "react-router-dom"
import { PrivacyView } from "../views/privacy"

export const PrivacyRoute = () => {
const navigate = useNavigate()
return <PrivacyView onCloseClicked={() => navigate(-1)} />
const shareData = useAppStore((state) => state.shareData)
const setShareData = useAppStore((state) => state.setShareData)
return (
<PrivacyView
onCloseClicked={() => navigate(-1)}
shareData={shareData}
setShareData={setShareData}
/>
)
}
16 changes: 14 additions & 2 deletions packages/features/src/settings/views/privacy.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { AppLayout } from "@/components/app-layout"
import { SettingsPageLayout } from "@/components/settings-page-layout"
import clsx from "clsx"

type PrivacyViewProps = {
onCloseClicked: () => void
shareData: boolean
setShareData: (shareData: boolean) => void
}

export const PrivacyView = ({ onCloseClicked }: PrivacyViewProps) => {
export const PrivacyView = ({
onCloseClicked,
shareData,
setShareData,
}: PrivacyViewProps) => {
return (
<AppLayout>
<SettingsPageLayout title="Privacy" onCloseClicked={onCloseClicked}>
Expand All @@ -16,7 +23,12 @@ export const PrivacyView = ({ onCloseClicked }: PrivacyViewProps) => {
</div>
<input
type="checkbox"
className="toggle [--tglbg:#F6C177] bg-white hover:bg-white border-[#F6C177]"
className={clsx(
"toggle bg-white hover:bg-white border-[#F6C177]",
shareData && "[--tglbg:#F6C177]",
)}
checked={shareData}
onChange={(event) => setShareData(event.target.checked)}
/>
</div>
</SettingsPageLayout>
Expand Down
26 changes: 26 additions & 0 deletions packages/features/src/wallet/components/info-bar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { InfoIcon, XIcon } from "lucide-react"

type InfoBarProps = {
onClose: () => void
}

export const InfoBar = ({ onClose }: InfoBarProps) => {
return (
<div className="px-8">
<div className="flex gap-2 items-center w-full bg-secondary p-4 rounded-xl">
<div className="p-2 bg-neutral rounded-full">
<InfoIcon className="text-primary" />
</div>
<div className="flex flex-col">
<h2>Open Beta version</h2>
<p className="text-gray-400 text-sm">
Only works for Berkeley before Mainnet launch
</p>
</div>
<button type="button" onClick={onClose}>
<XIcon size={20} className="text-gray-400" />
</button>
</div>
</div>
)
}
7 changes: 7 additions & 0 deletions packages/features/src/wallet/routes/overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useFiatPrice } from "@palladxyz/offchain-data"
import { useAccount } from "@/common/hooks/use-account"
import { useTransactions } from "@/common/hooks/use-transactions"

import { useAppStore } from "@/common/store/app"
import { format } from "date-fns"
import { take, takeLast } from "rambda"
import { useState } from "react"
Expand All @@ -15,6 +16,10 @@ export const OverviewRoute = () => {
>()
const navigate = useNavigate()
const account = useAccount()
const betaBannerVisible = useAppStore((state) => state.betaBannerVisible)
const setBetaBannerVisible = useAppStore(
(state) => state.setBetaBannerVisible,
)
const { data: transactions, isLoading: transactionsLoading } =
useTransactions()
const latestTwoTransactions = take(2, transactions ?? [])
Expand Down Expand Up @@ -50,6 +55,8 @@ export const OverviewRoute = () => {
setCurrentPriceIndex={setCurrentPriceIndex}
transactions={latestTwoTransactions}
publicAddress={account.data?.publicKey ?? ""}
betaBannerVisible={betaBannerVisible}
setBetaBannerVisible={setBetaBannerVisible}
onSend={() => navigate("/send")}
onReceive={() => navigate("/receive")}
/>
Expand Down
8 changes: 8 additions & 0 deletions packages/features/src/wallet/views/overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Skeleton } from "@/components/skeleton"
import type { Tx } from "@palladxyz/pallad-core"
import { Link } from "react-router-dom"
import SlotCounter from "react-slot-counter"
import { InfoBar } from "../components/info-bar"
import { PortfolioValueChart } from "../components/portfolio-value-chart"
import { TxTile } from "../components/tx-tile"

Expand All @@ -17,6 +18,8 @@ type OverviewViewProps = {
setCurrentPriceIndex: (currentPriceIndex: number | undefined) => void
transactions: Tx[]
publicAddress: string
betaBannerVisible: boolean
setBetaBannerVisible: (betaBannerVisible: boolean) => void
onSend: () => void
onReceive: () => void
}
Expand All @@ -30,13 +33,18 @@ export const OverviewView = ({
setCurrentPriceIndex,
transactions,
publicAddress,
betaBannerVisible,
setBetaBannerVisible,
onSend,
onReceive,
}: OverviewViewProps) => {
const [bucks, cents] = balance.toFixed(2).toString().split(".")
return (
<AppLayout>
<MenuBar variant="dashboard" publicAddress={publicAddress} />
{betaBannerVisible ? (
<InfoBar onClose={() => setBetaBannerVisible(false)} />
) : null}
<Skeleton loading={loading} h="62px">
<PortfolioValueChart
lastMonthPrices={lastMonthPrices}
Expand Down

0 comments on commit 94972b7

Please sign in to comment.