Skip to content

Commit

Permalink
update the gc url param. Update the notification token set for wallets
Browse files Browse the repository at this point in the history
  • Loading branch information
chloehjung15 committed Mar 23, 2023
1 parent f442002 commit d33a2fb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion class/deeplink-schema-match.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
14 changes: 14 additions & 0 deletions class/wallets/lightning-custodian-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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
}

/**
Expand Down Expand Up @@ -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;
}


}

Expand Down
17 changes: 12 additions & 5 deletions screen/settings/bolthubSettings.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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');

Expand Down Expand Up @@ -60,6 +61,7 @@ const BolthubSettings: React.FC & { navigationOptions: NavigationOptionsGetter }
const [isNotificationsEnabled, setNotificationsEnabled] = useState(false);
const [isShowTokenInfo, setShowTokenInfo] = useState(0);
const [tokenInfo, setTokenInfo] = useState('<empty>');
const { wallets } = useContext(BlueStorageContext);

const { colors } = useTheme();
const route = useRoute();
Expand Down Expand Up @@ -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',
},
Expand All @@ -139,7 +141,7 @@ const BolthubSettings: React.FC & { navigationOptions: NavigationOptionsGetter }
);
}
})();
}, [params?.gcurl]);
}, [params?.gc]);


const onNotificationsSwitch = async value => {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion screen/wallets/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ const WalletTransactions = () => {
// setDataSource([...getTransactionsSliced(limit)]);
}
await Notifications.tryToObtainPermissions();
Notifications.majorTomToGroundControl([], [], [], [wallet.getLogin()]);
wallet.pushNotificationToken();

setIsLoading(false);
setTimeElapsed(prev => prev + 1);
Expand Down

0 comments on commit d33a2fb

Please sign in to comment.