|
| 1 | +import { useAddressLabel } from '#/address/AddressLabel'; |
| 2 | +import { AddressIcon } from '#/Identicon/AddressIcon'; |
| 3 | +import { PressableOpacity } from '#/PressableOpacity'; |
| 4 | +import { Scrollable } from '#/Scrollable'; |
| 5 | +import { Sheet } from '#/sheet/Sheet'; |
| 6 | +import { ContactOutlineIcon, OutboundIcon, ShareIcon, WebIcon } from '@theme/icons'; |
| 7 | +import { CORNER, ICON_SIZE } from '@theme/paper'; |
| 8 | +import { createStyles, useStyles } from '@theme/styles'; |
| 9 | +import { CHAINS } from 'chains'; |
| 10 | +import { Link } from 'expo-router'; |
| 11 | +import { asAddress, asChain } from 'lib'; |
| 12 | +import { View } from 'react-native'; |
| 13 | +import { Text } from 'react-native-paper'; |
| 14 | +import { z } from 'zod'; |
| 15 | +import { useLocalParams } from '~/hooks/useLocalParams'; |
| 16 | +import { useSelectedAccount } from '~/hooks/useSelectedAccount'; |
| 17 | +import { share } from '~/lib/share'; |
| 18 | +import { zUAddress } from '~/lib/zod'; |
| 19 | + |
| 20 | +const Params = z.object({ address: zUAddress() }); |
| 21 | + |
| 22 | +export default function AddressSheet() { |
| 23 | + const { styles } = useStyles(stylesheet); |
| 24 | + const { address } = useLocalParams(Params); |
| 25 | + const account = useSelectedAccount(); |
| 26 | + |
| 27 | + const explorer = CHAINS[asChain(address)].blockExplorers?.native.url; |
| 28 | + |
| 29 | + return ( |
| 30 | + <Sheet contentContainerStyle={styles.container}> |
| 31 | + <View style={styles.headerContainer}> |
| 32 | + <AddressIcon address={address} size={ICON_SIZE.large} /> |
| 33 | + |
| 34 | + <Text variant="headlineSmall">{useAddressLabel(address)}</Text> |
| 35 | + |
| 36 | + <Text variant="bodyMedium" style={styles.address}> |
| 37 | + {asAddress(address)} |
| 38 | + </Text> |
| 39 | + </View> |
| 40 | + |
| 41 | + <Scrollable horizontal contentContainerStyle={styles.actions}> |
| 42 | + <PressableOpacity style={styles.action} onPress={() => share({ url: address })}> |
| 43 | + <ShareIcon /> |
| 44 | + <Text variant="labelLarge">Share</Text> |
| 45 | + </PressableOpacity> |
| 46 | + |
| 47 | + {explorer && ( |
| 48 | + <Link href={`${explorer}address/${asAddress(address)}`} asChild> |
| 49 | + <PressableOpacity style={styles.action}> |
| 50 | + <WebIcon /> |
| 51 | + <Text variant="labelLarge">Explorer</Text> |
| 52 | + </PressableOpacity> |
| 53 | + </Link> |
| 54 | + )} |
| 55 | + |
| 56 | + <Link href={{ pathname: `/(nav)/contacts/[address]`, params: { address } }} asChild> |
| 57 | + <PressableOpacity style={styles.action}> |
| 58 | + <ContactOutlineIcon /> |
| 59 | + <Text variant="labelLarge">Contact</Text> |
| 60 | + </PressableOpacity> |
| 61 | + </Link> |
| 62 | + |
| 63 | + {account && ( |
| 64 | + <Link |
| 65 | + href={{ pathname: `/(nav)/[account]/(home)/send`, params: { account, to: address } }} |
| 66 | + asChild |
| 67 | + > |
| 68 | + <PressableOpacity style={styles.action}> |
| 69 | + <OutboundIcon /> |
| 70 | + <Text variant="labelLarge">Send</Text> |
| 71 | + </PressableOpacity> |
| 72 | + </Link> |
| 73 | + )} |
| 74 | + </Scrollable> |
| 75 | + </Sheet> |
| 76 | + ); |
| 77 | +} |
| 78 | + |
| 79 | +const stylesheet = createStyles(({ colors }) => ({ |
| 80 | + container: { |
| 81 | + paddingBottom: 16, |
| 82 | + }, |
| 83 | + headerContainer: { |
| 84 | + alignItems: 'center', |
| 85 | + gap: 8, |
| 86 | + marginHorizontal: 16, |
| 87 | + marginVertical: 8, |
| 88 | + }, |
| 89 | + address: { |
| 90 | + color: colors.onSurfaceVariant, |
| 91 | + }, |
| 92 | + actions: { |
| 93 | + justifyContent: 'center', |
| 94 | + gap: 16, |
| 95 | + paddingHorizontal: 16, |
| 96 | + marginVertical: 8, |
| 97 | + }, |
| 98 | + action: { |
| 99 | + alignItems: 'center', |
| 100 | + gap: 8, |
| 101 | + width: 80, |
| 102 | + paddingVertical: 8, |
| 103 | + borderRadius: CORNER.m, |
| 104 | + }, |
| 105 | +})); |
0 commit comments