Skip to content

Commit 74a5087

Browse files
committed
Add BestRateBadge
This component can be used with the PaymentOptionCard as the renderRight prop. This is apart of the new fiat buy UI design.
1 parent 37efb57 commit 74a5087

File tree

3 files changed

+89
-1
lines changed

3 files changed

+89
-1
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import * as React from 'react'
2+
import { type LayoutChangeEvent, StyleSheet, View } from 'react-native'
3+
import Svg, { Polygon } from 'react-native-svg'
4+
5+
import { lstrings } from '../../locales/strings'
6+
import { styled } from '../hoc/styled'
7+
import { useTheme } from '../services/ThemeContext'
8+
import { EdgeText } from '../themed/EdgeText'
9+
10+
// TODO: Render a badge icon
11+
export const BestRateBadge = () => {
12+
const theme = useTheme()
13+
14+
const [dimensions, setDimensions] = React.useState({ width: 70, height: 100 })
15+
const { width, height } = dimensions
16+
17+
const handleLayout = (event: LayoutChangeEvent) => {
18+
const { width, height } = event.nativeEvent.layout
19+
setDimensions({ width, height })
20+
}
21+
22+
// Compute a 5-point star sized around the text box
23+
const { svgWidth, svgHeight, points } = React.useMemo(() => {
24+
const padding = theme.rem(0.75)
25+
const svgWidth = width + padding * 2
26+
const svgHeight = height + padding * 2
27+
28+
const centerX = svgWidth / 2
29+
const centerY = svgHeight / 2
30+
const outerRadius = Math.max(width, height) / 2 + padding * 0.9
31+
const innerRadius = outerRadius * 0.75
32+
33+
const numPoints = 14
34+
const totalVertices = numPoints * 2 // outer+inner alternating
35+
const startAngle = -Math.PI / 2 // Point up
36+
37+
const pts: Array<{ x: number; y: number }> = []
38+
for (let i = 0; i < totalVertices; i++) {
39+
const isOuter = i % 2 === 0
40+
const radius = isOuter ? outerRadius : innerRadius
41+
const angle = startAngle + (i * Math.PI) / numPoints
42+
const x = centerX + radius * Math.cos(angle)
43+
const y = centerY + radius * Math.sin(angle)
44+
pts.push({ x, y })
45+
}
46+
47+
const points = pts.map(p => `${p.x},${p.y}`).join(' ')
48+
return { svgWidth, svgHeight, points }
49+
}, [height, theme, width])
50+
51+
return (
52+
<BestRateBadgeContainer onLayout={handleLayout}>
53+
<Svg
54+
width={svgWidth}
55+
height={svgHeight}
56+
viewBox={`0 0 ${svgWidth} ${svgHeight}`}
57+
style={[
58+
StyleSheet.absoluteFillObject,
59+
{ top: -theme.rem(0.75), left: -theme.rem(0.75) }
60+
]}
61+
>
62+
<Polygon
63+
points={points}
64+
fill="none"
65+
stroke={theme.iconTappable}
66+
strokeWidth={2}
67+
/>
68+
</Svg>
69+
<BestRateText>{lstrings.string_best_rate_badge_text}</BestRateText>
70+
</BestRateBadgeContainer>
71+
)
72+
}
73+
74+
const BestRateBadgeContainer = styled(View)(theme => ({
75+
alignItems: 'center',
76+
justifyContent: 'center'
77+
}))
78+
79+
const BestRateText = styled(EdgeText)(theme => ({
80+
fontSize: theme.rem(0.5),
81+
fontWeight: 'bold',
82+
color: theme.primaryText,
83+
textAlign: 'center',
84+
letterSpacing: 0,
85+
zIndex: 1
86+
}))

src/locales/en_US.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,7 @@ const strings = {
13851385
string_warning: 'Warning', // Generic string. Same with wc_smartcontract_warning_title
13861386
string_report_error: 'Report Error',
13871387
string_report_sent: 'Report sent.',
1388+
string_best_rate_badge_text: 'Best\nRate',
13881389

13891390
step: 'Step',
13901391
scan_as_in_scan_barcode: 'Scan',

src/locales/strings/enUS.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,8 @@
10901090
"string_warning": "Warning",
10911091
"string_report_error": "Report Error",
10921092
"string_report_sent": "Report sent.",
1093-
"step": "Step",
1093+
"string_best_rate_badge_text": "Best\nRate",
1094+
"step_prefix_s": "Step %s:",
10941095
"scan_as_in_scan_barcode": "Scan",
10951096
"enter_as_in_enter_address_with_keyboard": "Enter",
10961097
"delete_account_title": "Delete Account",

0 commit comments

Comments
 (0)