Skip to content

Commit

Permalink
Add a Battery Saver warning to Services
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon-edge committed Sep 27, 2024
1 parent e74195d commit 071f1f3
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- added: Battery Saver warning message for Android
- added: Buy conversion tracking for Moonpay
- added: Error tracking for failure to report conversions to referral server
- changed: Remove whitespaces from custom token contract address input
Expand Down
51 changes: 51 additions & 0 deletions src/components/services/Services.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { asDate, asJSON, asObject, uncleaner } from 'cleaners'
import { EdgeAccount } from 'edge-core-js'
import * as React from 'react'
import { EmitterSubscription } from 'react-native'
import { AirshipBridge } from 'react-native-airship'
import { powerSavingModeChanged, powerSavingOn } from 'react-native-power-saving-mode'

import { updateExchangeInfo } from '../../actions/ExchangeInfoActions'
import { refreshConnectedWallets } from '../../actions/FioActions'
Expand All @@ -11,13 +14,15 @@ import { ENV } from '../../env'
import { useAsyncEffect } from '../../hooks/useAsyncEffect'
import { useHandler } from '../../hooks/useHandler'
import { useRefresher } from '../../hooks/useRefresher'
import { lstrings } from '../../locales/strings'
import { defaultAccount } from '../../reducers/CoreReducer'
import { FooterAccordionEventService } from '../../state/SceneFooterState'
import { useDispatch, useSelector } from '../../types/reactRedux'
import { NavigationBase } from '../../types/routerTypes'
import { height, ratioHorizontal, ratioVertical, width } from '../../util/scaling'
import { snooze } from '../../util/utils'
import { FioCreateHandleModal } from '../modals/FioCreateHandleModal'
import { AlertDropdown } from '../navigation/AlertDropdown'
import { AccountCallbackManager } from './AccountCallbackManager'
import { ActionQueueService } from './ActionQueueService'
import { Airship } from './AirshipInstance'
Expand Down Expand Up @@ -123,6 +128,52 @@ export function Services(props: Props) {
'Services 2'
)

// Subscribe to Android Power Saver state, and show a warning only if it
// changes from off to on:
useAsyncEffect(
async () => {
// This method is only available for Android
if (powerSavingOn == null) return

let airshipBridge: AirshipBridge<void> | undefined
const handlePowerSavingModeChanged = async (isPowerSavingModeOn: boolean) => {
if (isPowerSavingModeOn && airshipBridge == null) {
await Airship.show(bridge => {
airshipBridge = bridge // Capture the bridge here
return <AlertDropdown bridge={bridge} message={lstrings.warning_battery_saver} warning persistent />
}).then(() => {
airshipBridge = undefined
})
} else if (!isPowerSavingModeOn && airshipBridge != null) {
// Dismiss the alert when power-saving mode turns off and there's an
// active warning that wasn't dismissed
airshipBridge.resolve()
}
}

// Show warning if Power Saver mode is on initially on app boot
await handlePowerSavingModeChanged(await powerSavingOn())

// Subscribe to Power Saver mode changes
let subscription: EmitterSubscription | undefined
if (powerSavingModeChanged != null) {
subscription = powerSavingModeChanged(handlePowerSavingModeChanged)
}

// Cleanup
return () => {
if (subscription != null) {
subscription.remove()
}
if (airshipBridge != null) {
airshipBridge.resolve()
}
}
},
[],
'Services 3'
)

// Methods to call periodically
useRefresher(
async () => {
Expand Down
1 change: 1 addition & 0 deletions src/locales/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ const strings = {
'The entered contract address differs from the contract address of built-in token %1$s. Please proceed with caution and verify the contract is legitimate as use of this token can result in loss of funds. If you have questions about this feature or contract please contact %2$s.',
warning_token_exists_1s: 'The entered token already exists as a built-in token %1$s',
warning_uk_risk: `Don't invest unless you're prepared to lose all the money you invest. This is a high-risk investment and you should not expect to be protected if something goes wrong. Take 2 min to learn more.`,
warning_battery_saver: `Battery Saver mode detected. Balances and transactions may be inaccurate`,

// Alert component:
alert_dropdown_alert: 'Alert! ',
Expand Down
1 change: 1 addition & 0 deletions src/locales/strings/enUS.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"warning_token_code_override_2s": "The entered contract address differs from the contract address of built-in token %1$s. Please proceed with caution and verify the contract is legitimate as use of this token can result in loss of funds. If you have questions about this feature or contract please contact %2$s.",
"warning_token_exists_1s": "The entered token already exists as a built-in token %1$s",
"warning_uk_risk": "Don't invest unless you're prepared to lose all the money you invest. This is a high-risk investment and you should not expect to be protected if something goes wrong. Take 2 min to learn more.",
"warning_battery_saver": "Battery Saver mode detected. Balances and transactions may be inaccurate",
"alert_dropdown_alert": "Alert! ",
"alert_dropdown_warning": "Warning! ",
"azteco_success": "You've redeemed an Azteco bitcoin card. Funds should arrive shortly.",
Expand Down

0 comments on commit 071f1f3

Please sign in to comment.