Skip to content

Commit

Permalink
Register push token on changing notification settings
Browse files Browse the repository at this point in the history
  • Loading branch information
minibits-cash committed May 30, 2024
1 parent 35ebb00 commit f90033d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ function App(props: AppProps) {
log.debug('[useInitialRootStore]', {deviceToken})

// Save new or refreshed token to local and server profile
if (deviceToken.length > 0 && deviceToken !== walletProfileStore.device) {
walletProfileStore.setDevice(deviceToken)
if (deviceToken.length > 0) {
await walletProfileStore.setDevice(deviceToken)
}

// Set initial websocket to close as it might have remained open on last app close
Expand Down
8 changes: 6 additions & 2 deletions src/models/WalletProfileStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,12 @@ export const WalletProfileStoreModel = types
return self
}),
setDevice: flow(function* setDevice(device: string) {
self.device = device
yield MinibitsClient.updateDeviceToken(self.pubkey, {deviceToken: device})
try {
yield MinibitsClient.updateDeviceToken(self.pubkey, {deviceToken: device})
self.device = device
} catch (e: any) {
log.error('[setDevice]', e.message)
}
}),
setNip05(nip05: string) { // used in migration to v3 model
self.nip05 = nip05
Expand Down
2 changes: 1 addition & 1 deletion src/screens/SettingsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const SettingsScreen: FC<SettingsScreenProps> = observer(
log.debug('[SettingsScreen.useEffect]', {deviceToken})

// Save new or refreshed token to local and server profile
if (deviceToken.length > 0 && deviceToken !== walletProfileStore.device) {
if (deviceToken.length) {
walletProfileStore.setDevice(deviceToken)
}
} catch (e: any) {
Expand Down

0 comments on commit f90033d

Please sign in to comment.