-
Notifications
You must be signed in to change notification settings - Fork 288
Add PocketChange UI for Monero wallet #5941
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
Open
claudinethelobster
wants to merge
1
commit into
EdgeApp:develop
Choose a base branch
from
claudinethelobster:feature/pocketchange-ui
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| import * as React from 'react' | ||
| import { View } from 'react-native' | ||
| import type { AirshipBridge } from 'react-native-airship' | ||
|
|
||
| import { useHandler } from '../../hooks/useHandler' | ||
| import { lstrings } from '../../locales/strings' | ||
| import { EdgeButton } from '../buttons/EdgeButton' | ||
| import { cacheStyles, type Theme, useTheme } from '../services/ThemeContext' | ||
| import { SettingsHeaderRow } from '../settings/SettingsHeaderRow' | ||
| import { SettingsSwitchRow } from '../settings/SettingsSwitchRow' | ||
| import { EdgeText, Paragraph } from '../themed/EdgeText' | ||
| import { EdgeModal } from './EdgeModal' | ||
|
|
||
| const POCKET_AMOUNTS_XMR = [0.1, 0.2, 0.3, 0.5, 0.8, 1.3] | ||
|
|
||
| export interface PocketChangeConfig { | ||
| enabled: boolean | ||
| amountIndex: number | ||
| } | ||
|
|
||
| interface Props { | ||
| bridge: AirshipBridge<PocketChangeConfig | undefined> | ||
| initialConfig: PocketChangeConfig | ||
| } | ||
|
|
||
| export const PocketChangeModal: React.FC<Props> = props => { | ||
| const { bridge, initialConfig } = props | ||
| const theme = useTheme() | ||
| const styles = getStyles(theme) | ||
| const [enabled, setEnabled] = React.useState(initialConfig.enabled) | ||
| const [amountIndex, setAmountIndex] = React.useState( | ||
| initialConfig.amountIndex | ||
| ) | ||
|
|
||
| const handleCancel = useHandler((): void => { | ||
| bridge.resolve(undefined) | ||
| }) | ||
|
|
||
| const handleSave = useHandler((): void => { | ||
| bridge.resolve({ enabled, amountIndex }) | ||
| }) | ||
|
|
||
| const handleToggle = useHandler((): void => { | ||
| setEnabled(prev => !prev) | ||
| }) | ||
|
|
||
| const handleDecrease = useHandler((): void => { | ||
| setAmountIndex(prev => Math.max(0, prev - 1)) | ||
| }) | ||
|
|
||
| const handleIncrease = useHandler((): void => { | ||
| setAmountIndex(prev => Math.min(POCKET_AMOUNTS_XMR.length - 1, prev + 1)) | ||
| }) | ||
|
|
||
| return ( | ||
| <EdgeModal | ||
| bridge={bridge} | ||
| onCancel={handleCancel} | ||
| title={lstrings.pocketchange_title} | ||
| > | ||
| <View style={styles.container}> | ||
| <Paragraph>{lstrings.pocketchange_description}</Paragraph> | ||
|
|
||
| <SettingsSwitchRow | ||
| label={lstrings.pocketchange_enable} | ||
| value={enabled} | ||
| onPress={handleToggle} | ||
| /> | ||
|
|
||
| {enabled ? ( | ||
| <> | ||
| <SettingsHeaderRow label={lstrings.pocketchange_amount_header} /> | ||
|
|
||
| <View style={styles.stepperRow}> | ||
| <EdgeButton | ||
| label="−" | ||
| type="secondary" | ||
| mini | ||
| onPress={handleDecrease} | ||
| disabled={amountIndex <= 0} | ||
| /> | ||
| <EdgeText style={styles.amountText}> | ||
| {POCKET_AMOUNTS_XMR[amountIndex]} XMR{' '} | ||
| {lstrings.pocketchange_per_pocket} | ||
| </EdgeText> | ||
| <EdgeButton | ||
| label="+" | ||
| type="secondary" | ||
| mini | ||
| onPress={handleIncrease} | ||
| disabled={amountIndex >= POCKET_AMOUNTS_XMR.length - 1} | ||
| /> | ||
| </View> | ||
|
|
||
| <Paragraph>{lstrings.pocketchange_explainer}</Paragraph> | ||
| </> | ||
| ) : null} | ||
|
|
||
| <View style={styles.saveButton}> | ||
| <EdgeButton label={lstrings.pocketchange_save} onPress={handleSave} /> | ||
| </View> | ||
| </View> | ||
| </EdgeModal> | ||
| ) | ||
| } | ||
|
|
||
| const getStyles = cacheStyles((theme: Theme) => ({ | ||
| container: { | ||
| paddingHorizontal: theme.rem(0.5) | ||
| }, | ||
| stepperRow: { | ||
| flexDirection: 'row', | ||
| alignItems: 'center', | ||
| justifyContent: 'center', | ||
| paddingVertical: theme.rem(0.5) | ||
| }, | ||
| amountText: { | ||
| fontSize: theme.rem(1.1), | ||
| marginHorizontal: theme.rem(1) | ||
| }, | ||
| saveButton: { | ||
| marginTop: theme.rem(1), | ||
| marginBottom: theme.rem(0.5) | ||
| } | ||
| })) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unvalidated
amountIndexcausesundefineddisplay textMedium Severity
The
savedobject fromwallet.otherMethods.getPocketChangeSetting()is assigned directly toinitialConfigwith no bounds check onamountIndex. If the plugin returns an index outside[0, 5],POCKET_AMOUNTS_XMR[amountIndex]evaluates toundefined, rendering"undefined XMR per pocket"in the modal. WithNaN, the stepper buttons become non-functional sinceMath.max/Math.minwithNaNalways returnsNaN.Additional Locations (1)
src/components/modals/PocketChangeModal.tsx#L82-L83Reviewed by Cursor Bugbot for commit ef1d4c5. Configure here.