Skip to content

Commit

Permalink
Fix: Ask for notification permission before starting a long running task
Browse files Browse the repository at this point in the history
  • Loading branch information
minibits-cash committed Feb 13, 2025
1 parent b21f12c commit b125fb9
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "minibits_wallet",
"version": "0.2.0-beta.8",
"version": "0.2.0-beta.9",
"private": true,
"scripts": {
"android:clean": "cd android && ./gradlew clean",
Expand Down
38 changes: 37 additions & 1 deletion src/screens/ExportBackupScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const ExportBackupScreen = function ExportBackup({ route }: Props) {
const [isMintsInBackup, setIsMintsInBackup] = useState(true)
const [isContactsInBackup, setIsContactsInBackup] = useState(true)
const [isResultModalVisible, setIsResultModalVisible] = useState(false)
const [isNotificationModalVisible, setIsNotificationModalVisible] = useState(false)
const [resultModalInfo, setResultModalInfo] = useState<
{status: TransactionStatus; title?: string, message: string} | undefined
>()
Expand Down Expand Up @@ -133,12 +134,18 @@ export const ExportBackupScreen = function ExportBackup({ route }: Props) {
}, [isSwapAllSentToQueue])


const openNotificationSettings = async function() {
await notifee.openNotificationSettings()
}

const toggleResultModal = () => {
setIsResultModalVisible(previousState => !previousState)
WalletTask.syncStateWithAllMintsQueue({isPending: true})
}

const toggleNotificationModal = () =>
setIsNotificationModalVisible(previousState => !previousState)


const toggleBackupEcashSwitch = () =>
setIsEcashInBackup(previousState => !previousState)
Expand All @@ -152,7 +159,14 @@ export const ExportBackupScreen = function ExportBackup({ route }: Props) {
setIsContactsInBackup(previousState => !previousState)


const optimizeProofAmountsStart = function () {
const optimizeProofAmountsStart = async function () {
const enabled = await NotificationService.areNotificationsEnabled()

if(!enabled) {
toggleNotificationModal()
return
}

Alert.alert(
'Optimize ecash proofs',
'Do you want to swap your wallet ecash for proofs with optimal denominations? The size of your backup will decrease.',
Expand Down Expand Up @@ -545,6 +559,28 @@ export const ExportBackupScreen = function ExportBackup({ route }: Props) {
onBackButtonPress={toggleResultModal}
onBackdropPress={toggleResultModal}
/>
<BottomModal
isVisible={isNotificationModalVisible ? true : false}
ContentComponent={
<>
<ResultModalInfo
icon="faTriangleExclamation"
iconColor={colors.palette.accent300}
title={"Permission needed"}
message={"Minibits needs a permission to display notification while this task will be running."}
/>
<View style={$buttonContainer}>
<Button
preset="secondary"
text={'Open settings'}
onPress={openNotificationSettings}
/>
</View>
</>
}
onBackButtonPress={toggleNotificationModal}
onBackdropPress={toggleNotificationModal}
/>
</Screen>
)
}
Expand Down
12 changes: 5 additions & 7 deletions src/screens/RecoverWalletAddressScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,23 +170,21 @@ export const RecoverWalletAddressScreen = observer(function RecoverWalletAddress
<Card
style={$card}
ContentComponent={
<>
<ListItem
text={profileToRecover.nip05}
subText="This is the wallet address linked to the provided seed."
LeftComponent={<View style={[$numIcon, { backgroundColor: numIconColor }]}><Text text='2' /></View>}
style={$item}
bottomSeparator
/>
}
/>
<Card
style={[$card]}
ContentComponent={
<ListItem
text={'Do not forget!'}
subText="Your current address will reset, but current wallet seed phrase will NOT be changed. Make a backup!"
text={'Do not lose your ecash!'}
subText="Your current wallet seed phrase will NOT be changed. Keep it in a safe place!"
LeftComponent={<View style={[$numIcon, { backgroundColor: numIconColor }]}><Text text='3' /></View>}
style={$item}
/>
</>
}
/>
</>
Expand Down
48 changes: 46 additions & 2 deletions src/screens/RecoveryOptionsScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {observer} from 'mobx-react-lite'
import React, {useState, useEffect} from 'react'
import {TextStyle, View, ViewStyle} from 'react-native'
import notifee, { AndroidImportance } from '@notifee/react-native'
import {spacing, useThemeColor, colors} from '../theme'
import {
Button,
Expand All @@ -11,6 +12,7 @@ import {
ErrorModal,
InfoModal,
Loading,
BottomModal,
} from '../components'
import {useHeader} from '../utils/useHeader'
import {log} from '../services/logService'
Expand All @@ -21,6 +23,7 @@ import EventEmitter from '../utils/eventEmitter'
import { translate } from '../i18n'
import { NotificationService } from '../services/notificationService'
import { StaticScreenProps, useNavigation } from '@react-navigation/native'
import { ResultModalInfo } from './Wallet/ResultModalInfo'

type Props = StaticScreenProps<{
fromScreen?: string
Expand All @@ -37,7 +40,8 @@ export const RecoveryOptionsScreen = observer(function RecoveryOptionsScreen({ r
const [isLoading, setIsLoading] = useState(false)
const [error, setError] = useState<AppError | undefined>()
const [info, setInfo] = useState('')
const [isSyncStateSentToQueue, setIsSyncStateSentToQueue] = useState<boolean>(false)
const [isSyncStateSentToQueue, setIsSyncStateSentToQueue] = useState<boolean>(false)
const [isNotificationModalVisible, setIsNotificationModalVisible] = useState(false)


useEffect(() => {
Expand All @@ -59,7 +63,14 @@ export const RecoveryOptionsScreen = observer(function RecoveryOptionsScreen({ r
}
}, [isSyncStateSentToQueue])

const openNotificationSettings = async function() {
await notifee.openNotificationSettings()
}


const toggleNotificationModal = () =>
setIsNotificationModalVisible(previousState => !previousState)


const gotoSeedRecovery = function () {
navigation.navigate('SeedRecovery')
Expand All @@ -77,6 +88,13 @@ export const RecoveryOptionsScreen = observer(function RecoveryOptionsScreen({ r


const checkSpent = async function () {
const enabled = await NotificationService.areNotificationsEnabled()

if(!enabled) {
toggleNotificationModal()
return
}

setIsLoading(true)
setIsSyncStateSentToQueue(true)

Expand Down Expand Up @@ -209,7 +227,28 @@ export const RecoveryOptionsScreen = observer(function RecoveryOptionsScreen({ r
{error && <ErrorModal error={error} />}
{info && <InfoModal message={info} />}
</View>

<BottomModal
isVisible={isNotificationModalVisible ? true : false}
ContentComponent={
<>
<ResultModalInfo
icon="faTriangleExclamation"
iconColor={colors.palette.accent300}
title={"Permission needed"}
message={"Minibits needs a permission to display notification while this task will be running."}
/>
<View style={$buttonContainer}>
<Button
preset="secondary"
text={'Open settings'}
onPress={openNotificationSettings}
/>
</View>
</>
}
onBackButtonPress={toggleNotificationModal}
onBackdropPress={toggleNotificationModal}
/>
</Screen>
)
},
Expand Down Expand Up @@ -258,3 +297,8 @@ const $item: ViewStyle = {
paddingHorizontal: spacing.small,
paddingLeft: 0,
}

const $buttonContainer: ViewStyle = {
flexDirection: 'row',
alignSelf: 'center',
}
2 changes: 1 addition & 1 deletion src/screens/SettingsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export const SettingsScreen = observer(function SettingsScreen({ route }: Props)

const handleBinaryVersionMismatchCallback = function(update: RemotePackage) {
// silent
// setIsNativeUpdateAvailable(true)
setIsNativeUpdateAvailable(true)
}

const gotoMints = function() {
Expand Down
2 changes: 1 addition & 1 deletion src/screens/WalletScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export const WalletScreen = observer(function WalletScreen({ route }: Props) {
const update = await codePush.checkForUpdate(deploymentKey, handleBinaryVersionMismatchCallback)

if (update && update.failedInstall !== true) { // do not announce update that failed to install before
// log.trace('[checkForUpdate]', update)
if(ANDROID_VERSION_NAME === update.appVersion) {
setUpdateDescription(update.description)
setUpdateSize(`${round(update.packageSize * 0.000001, 2)}MB`)
Expand All @@ -141,7 +142,6 @@ export const WalletScreen = observer(function WalletScreen({ route }: Props) {

}, [])



const handleBinaryVersionMismatchCallback = function(update: RemotePackage) {
log.info('[handleBinaryVersionMismatchCallback] triggered', ANDROID_VERSION_NAME, update)
Expand Down

0 comments on commit b125fb9

Please sign in to comment.