Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(wallet-mobile): address details styling #3759

Merged
merged 6 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion apps/wallet-mobile/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ const useStyles = ({
container: {
backgroundColor,
...atoms.flex,
...atoms.flex_grow,
banklesss marked this conversation as resolved.
Show resolved Hide resolved
...atoms.flex_row,
...atoms.align_start,
...atoms.justify_center,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ export const ClipboardProvider = ({children}: Props) => {
const styles = useStyles()
const [copied, setCopied] = React.useState<CopiedState | null>(null)
const {height, width} = useWindowDimensions()
const copy: ClipboardContext['copy'] = ({text, feedback = 'Copied', event}) => {
const copy: ClipboardContext['copy'] = ({text, feedback = 'Copied', event, offsetX = 0, offsetY = 0}) => {
Clipboard.setString(text)
setCopied({
feedback,
locationY: event ? event.nativeEvent.pageY - 50 : height * 0.85,
locationX: (event?.nativeEvent.pageX ?? width * 0.5) - feedback.length * 4,
locationY: (event ? event.nativeEvent.pageY - 50 : height * 0.85) + offsetY,
banklesss marked this conversation as resolved.
Show resolved Hide resolved
locationX: (event?.nativeEvent.pageX ?? width * 0.5) - feedback.length * 4 + offsetX,
})
setTimeout(() => setCopied(null), FEEDBACK_TIMEOUT)
}
Expand Down Expand Up @@ -70,6 +70,8 @@ type CopyProps = {
text: string
feedback?: string
event?: GestureResponderEvent
offsetX?: number
offsetY?: number
}
type ClipboardContext = {
copy: (a: CopyProps) => void
Expand Down
6 changes: 4 additions & 2 deletions apps/wallet-mobile/src/components/CopyButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ type CopyButtonProps = {
children?: React.ReactNode
style?: StyleProp<ViewStyle>
message?: string
offsetX?: number
offsetY?: number
}

export const CopyButton = ({title, value, onCopy, message}: CopyButtonProps) => {
export const CopyButton = ({title, value, onCopy, message, offsetX, offsetY}: CopyButtonProps) => {
const {isCopying, copy} = useCopy()
const {atoms} = useTheme()

Expand All @@ -28,7 +30,7 @@ export const CopyButton = ({title, value, onCopy, message}: CopyButtonProps) =>
icon={isCopying ? Icon.CopySuccess : Icon.Copy}
rightIcon
onPress={(event) => {
copy({text: value, feedback: message, event})
copy({text: value, feedback: message, event, offsetX, offsetY})
onCopy?.()
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export const ShareDetailsCard = ({address, spendingHash, stakingHash}: AddressDe
<View style={styles.textRow}>
<Text style={styles.textAddressDetails}>{address}</Text>

<CopyButton value={address} onCopy={handleAddressOnCopy} message={strings.addressCopiedMsg} />
<View>
<Copy value={address} onCopy={handleAddressOnCopy} message={strings.addressCopiedMsg} />
</View>
</View>
</View>

Expand All @@ -57,7 +59,7 @@ export const ShareDetailsCard = ({address, spendingHash, stakingHash}: AddressDe
<View style={styles.textRow}>
<Text style={styles.textAddressDetails}>{stakingHash}</Text>

<CopyButton value={stakingHash} message={strings.addressCopiedMsg} />
<Copy value={stakingHash} message={strings.addressCopiedMsg} />
</View>
</View>
)}
Expand All @@ -69,7 +71,7 @@ export const ShareDetailsCard = ({address, spendingHash, stakingHash}: AddressDe
<View style={styles.textRow}>
<Text style={styles.textAddressDetails}>{spendingHash}</Text>

<CopyButton value={spendingHash} message={strings.addressCopiedMsg} />
<Copy value={spendingHash} message={strings.addressCopiedMsg} />
</View>
</View>
)}
Expand All @@ -87,6 +89,14 @@ export const ShareDetailsCard = ({address, spendingHash, stakingHash}: AddressDe
)
}

const Copy = ({value, message, onCopy}: {value: string; message: string; onCopy?: () => void}) => {
return (
<View>
<CopyButton value={value} message={message} onCopy={onCopy} offsetX={-50} offsetY={-10} />
</View>
)
}

const useStyles = () => {
const screenWidth = useWindowDimensions().width
const {atoms, color} = useTheme()
Expand Down
Loading