|
| 1 | +import { |
| 2 | + XStack, |
| 3 | + Stack, |
| 4 | + styled, |
| 5 | + type XStackProps, |
| 6 | + AnimatePresence, |
| 7 | + LinearGradient, |
| 8 | + usePwa, |
| 9 | +} from '@my/ui' |
| 10 | +import { useSendAccount } from 'app/utils/send-accounts' |
| 11 | +import { useSendAccountBalances } from 'app/utils/useSendAccountBalances' |
| 12 | +import { parseUnits } from 'viem' |
| 13 | +import { coinsDict } from 'app/data/coins' |
| 14 | +import { baseMainnet, usdcAddress } from '@my/wagmi' |
| 15 | +import { HomeButtons } from '../features/home/HomeButtons' |
| 16 | +import { useScrollDirection } from '../provider/scroll' |
| 17 | +import { ProfileButtons } from 'app/features/profile/ProfileButtons' |
| 18 | +import { useUser } from 'app/utils/useUser' |
| 19 | +import { useProfileLookup } from 'app/utils/useProfileLookup' |
| 20 | +import { useProfileScreenParams } from 'app/routers/params' |
| 21 | + |
| 22 | +const Row = styled(XStack, { |
| 23 | + w: '100%', |
| 24 | + ai: 'center', |
| 25 | + mx: 'auto', |
| 26 | + jc: 'space-around', |
| 27 | + gap: '$4', |
| 28 | + maw: 768, |
| 29 | + $gtLg: { |
| 30 | + pt: '$4', |
| 31 | + }, |
| 32 | +}) |
| 33 | + |
| 34 | +export const Home = ({ children, ...props }: XStackProps) => { |
| 35 | + const isPwa = usePwa() |
| 36 | + const { isLoading: isLoadingSendAccount } = useSendAccount() |
| 37 | + const { balances, isLoading: isLoadingBalances } = useSendAccountBalances() |
| 38 | + const usdcBalance = balances?.USDC |
| 39 | + const canSend = |
| 40 | + usdcBalance !== undefined && |
| 41 | + usdcBalance >= parseUnits('.20', coinsDict[usdcAddress[baseMainnet.id]].decimals) |
| 42 | + |
| 43 | + const { direction } = useScrollDirection() |
| 44 | + |
| 45 | + const isLoading = isLoadingSendAccount || isLoadingBalances |
| 46 | + |
| 47 | + return ( |
| 48 | + <> |
| 49 | + {children} |
| 50 | + <AnimatePresence> |
| 51 | + {!isLoading && direction !== 'down' && ( |
| 52 | + <Stack |
| 53 | + w={'100%'} |
| 54 | + pb={isPwa ? '$1' : '$5'} |
| 55 | + px="$4" |
| 56 | + $platform-web={{ |
| 57 | + position: 'fixed', |
| 58 | + bottom: 0, |
| 59 | + }} |
| 60 | + $gtLg={{ |
| 61 | + display: 'none', |
| 62 | + }} |
| 63 | + animation="200ms" |
| 64 | + opacity={1} |
| 65 | + animateOnly={['scale', 'transform', 'opacity']} |
| 66 | + enterStyle={{ opacity: 0, scale: 0.9 }} |
| 67 | + exitStyle={{ opacity: 0, scale: 0.95 }} |
| 68 | + > |
| 69 | + <LinearGradient |
| 70 | + h={'150%'} |
| 71 | + top={'-50%'} |
| 72 | + start={{ x: 0, y: 1 }} |
| 73 | + end={{ x: 0, y: 0 }} |
| 74 | + locations={[0, 0.33]} |
| 75 | + fullscreen |
| 76 | + colors={['transparent', '$background']} |
| 77 | + $gtLg={{ display: 'none' }} |
| 78 | + /> |
| 79 | + <Row {...props}> |
| 80 | + <Stack f={1} w="50%" flexDirection="row-reverse" maw={350}> |
| 81 | + <HomeButtons.DepositButton /> |
| 82 | + </Stack> |
| 83 | + {canSend && ( |
| 84 | + <Stack f={1} w="50%" jc={'center'} maw={350}> |
| 85 | + <HomeButtons.SendButton /> |
| 86 | + </Stack> |
| 87 | + )} |
| 88 | + </Row> |
| 89 | + </Stack> |
| 90 | + )} |
| 91 | + </AnimatePresence> |
| 92 | + </> |
| 93 | + ) |
| 94 | +} |
| 95 | + |
| 96 | +export const Profile = ( |
| 97 | + { children, ...props }: XStackProps //@todo another use case for a generated type for our route names |
| 98 | +) => { |
| 99 | + const isPwa = usePwa() |
| 100 | + const [{ sendid, tag }] = useProfileScreenParams() |
| 101 | + const identifier = tag ?? sendid ?? '' |
| 102 | + const identifierType = tag ? 'tag' : 'sendid' |
| 103 | + const { profile, isLoading } = useUser() |
| 104 | + const { data: otherUserProfile } = useProfileLookup(identifierType, identifier?.toString() || '') |
| 105 | + |
| 106 | + const { direction } = useScrollDirection() |
| 107 | + |
| 108 | + const isVisible = Boolean(otherUserProfile) && profile?.send_id !== otherUserProfile?.sendid |
| 109 | + |
| 110 | + return ( |
| 111 | + <> |
| 112 | + {children} |
| 113 | + <AnimatePresence> |
| 114 | + {!isLoading && isVisible && direction !== 'down' && ( |
| 115 | + <Stack |
| 116 | + w={'100%'} |
| 117 | + pb={isPwa ? '$1' : '$5'} |
| 118 | + px="$4" |
| 119 | + $platform-web={{ |
| 120 | + position: 'fixed', |
| 121 | + bottom: 0, |
| 122 | + }} |
| 123 | + $gtLg={{ |
| 124 | + display: 'none', |
| 125 | + }} |
| 126 | + animation="200ms" |
| 127 | + opacity={1} |
| 128 | + animateOnly={['scale', 'transform', 'opacity']} |
| 129 | + enterStyle={{ opacity: 0, scale: 0.9 }} |
| 130 | + exitStyle={{ opacity: 0, scale: 0.95 }} |
| 131 | + > |
| 132 | + <LinearGradient |
| 133 | + h={'150%'} |
| 134 | + top={'-50%'} |
| 135 | + start={{ x: 0, y: 1 }} |
| 136 | + end={{ x: 0, y: 0 }} |
| 137 | + locations={[0, 0.33]} |
| 138 | + fullscreen |
| 139 | + colors={['transparent', '$background']} |
| 140 | + $gtLg={{ display: 'none' }} |
| 141 | + /> |
| 142 | + <Row {...props}> |
| 143 | + <Stack w={200}> |
| 144 | + <ProfileButtons.SendButton |
| 145 | + identifier={otherUserProfile?.tag ?? otherUserProfile?.sendid ?? ''} |
| 146 | + idType="tag" |
| 147 | + /> |
| 148 | + </Stack> |
| 149 | + </Row> |
| 150 | + </Stack> |
| 151 | + )} |
| 152 | + </AnimatePresence> |
| 153 | + </> |
| 154 | + ) |
| 155 | +} |
| 156 | + |
| 157 | +export const MobileButtonRowLayout = { |
| 158 | + Home: Home, |
| 159 | + Profile: Profile, |
| 160 | +} |
0 commit comments