From d33a2fbc60eeb2ec12ddb1e30865feb576b5c3e7 Mon Sep 17 00:00:00 2001 From: Chloe Jung Date: Fri, 24 Mar 2023 12:10:15 +1300 Subject: [PATCH] update the gc url param. Update the notification token set for wallets --- class/deeplink-schema-match.js | 2 +- class/wallets/lightning-custodian-wallet.js | 14 ++++++++++++++ screen/settings/bolthubSettings.tsx | 17 ++++++++++++----- screen/wallets/transactions.js | 2 +- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/class/deeplink-schema-match.js b/class/deeplink-schema-match.js index e6cdbc8db7..1de228d1af 100644 --- a/class/deeplink-schema-match.js +++ b/class/deeplink-schema-match.js @@ -307,7 +307,7 @@ class DeeplinkSchemaMatch { static getGcUrlFromSetLndhubUrlAction(url) { if (!url.startsWith('bluewallet:setlndhuburl') && !url.startsWith('setlndhuburl')) return false; - const splt = this.gup('gcurl', url); + const splt = this.gup('gc', url); if (splt) return decodeURIComponent(splt); return false; } diff --git a/class/wallets/lightning-custodian-wallet.js b/class/wallets/lightning-custodian-wallet.js index 6ec271cbf4..5ff8202e0a 100644 --- a/class/wallets/lightning-custodian-wallet.js +++ b/class/wallets/lightning-custodian-wallet.js @@ -3,6 +3,8 @@ import Frisbee from 'frisbee'; import bolt11 from 'bolt11'; import { BitcoinUnit, Chain } from '../../models/bitcoinUnits'; import { isTorDaemonDisabled } from '../../blue_modules/environment'; +import Notifications from '../../blue_modules/notifications'; + const torrific = require('../../blue_modules/torrific'); export class LightningCustodianWallet extends LegacyWallet { static type = 'lightningCustodianWallet'; @@ -28,6 +30,7 @@ export class LightningCustodianWallet extends LegacyWallet { this.cardEnabled = true; this.cardDetails = false; this.createcardurl = ''; + this.notificationTokenPushed = false; //set to true if the notification token has been pushed to gc for this wallet } /** @@ -1030,6 +1033,17 @@ export class LightningCustodianWallet extends LegacyWallet { return this.createcard(); } + async pushNotificationToken() { + // if(this.notificationTokenPushed) { + // //token has already been pushed for this wallet + // return false; + // } + + return Notifications.majorTomToGroundControl([], [], [], [this.getLogin()]); + // return (this.notificationTokenPushed = true); + // return true; + } + } diff --git a/screen/settings/bolthubSettings.tsx b/screen/settings/bolthubSettings.tsx index c7024bae80..ca745c802b 100644 --- a/screen/settings/bolthubSettings.tsx +++ b/screen/settings/bolthubSettings.tsx @@ -1,6 +1,6 @@ import AsyncStorage from '@react-native-async-storage/async-storage'; import { RouteProp, useNavigation, useRoute } from '@react-navigation/native'; -import React, { useCallback, useEffect, useState } from 'react'; +import React, { useCallback, useEffect, useState, useContext } from 'react'; import { Alert, I18nManager, Linking, StyleSheet, TextInput, TouchableWithoutFeedback, View, PermissionsAndroid } from 'react-native'; import { Button, Icon } from 'react-native-elements'; @@ -13,6 +13,7 @@ import alert from '../../components/Alert'; import navigationStyle, { NavigationOptionsGetter } from '../../components/navigationStyle'; import { useTheme } from '../../components/themes'; import loc from '../../loc'; +import { BlueStorageContext } from '../../blue_modules/storage-context'; const PushNotification = require('react-native-push-notification'); @@ -60,6 +61,7 @@ const BolthubSettings: React.FC & { navigationOptions: NavigationOptionsGetter } const [isNotificationsEnabled, setNotificationsEnabled] = useState(false); const [isShowTokenInfo, setShowTokenInfo] = useState(0); const [tokenInfo, setTokenInfo] = useState(''); + const { wallets } = useContext(BlueStorageContext); const { colors } = useTheme(); const route = useRoute(); @@ -121,15 +123,15 @@ const BolthubSettings: React.FC & { navigationOptions: NavigationOptionsGetter } (async () => { setNotificationURI(await Notifications.getSavedUri()); - if (params?.gcurl) { + if (params?.gc) { Alert.alert( - loc.formatString(loc.settings.set_lndhub_as_default, { url: params.gcurl }) as string, + loc.formatString(loc.settings.set_lndhub_as_default, { url: params.gc }) as string, '', [ { text: loc._.ok, onPress: () => { - params?.gcurl && setNotificationURI(params.gcurl); + params?.gc && setNotificationURI(params.gc); }, style: 'default', }, @@ -139,7 +141,7 @@ const BolthubSettings: React.FC & { navigationOptions: NavigationOptionsGetter } ); } })(); - }, [params?.gcurl]); + }, [params?.gc]); const onNotificationsSwitch = async value => { @@ -161,6 +163,11 @@ const BolthubSettings: React.FC & { navigationOptions: NavigationOptionsGetter } // ok, we dont have a token. we need to try to obtain permissions, configure callbacks and save token locally: await Notifications.tryToObtainPermissions(); } + + //get all wallets and send the token with wallet ids to groundcontrol + wallets.forEach(wallet => { + wallet.pushNotificationToken(); + }) } }); } else { diff --git a/screen/wallets/transactions.js b/screen/wallets/transactions.js index 7ff7192224..cc38a11073 100644 --- a/screen/wallets/transactions.js +++ b/screen/wallets/transactions.js @@ -204,7 +204,7 @@ const WalletTransactions = () => { // setDataSource([...getTransactionsSliced(limit)]); } await Notifications.tryToObtainPermissions(); - Notifications.majorTomToGroundControl([], [], [], [wallet.getLogin()]); + wallet.pushNotificationToken(); setIsLoading(false); setTimeElapsed(prev => prev + 1);