Skip to content

Commit

Permalink
ZEUS-1899: ZEUS Pay: add ability to delete address
Browse files Browse the repository at this point in the history
  • Loading branch information
kaloudis committed Feb 15, 2025
1 parent 8503c50 commit 0e65b01
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 4 deletions.
3 changes: 3 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"general.payNfc": "Pay via NFC",
"general.confirm": "Confirm",
"general.cancel": "Cancel",
"general.delete": "Delete",
"general.warning": "Warning",
"general.error": "Error",
"general.danger": "Danger!",
Expand Down Expand Up @@ -1211,6 +1212,8 @@
"views.Settings.LightningAddressSettings.notifications.push": "Push",
"views.Settings.LightningAddressSettings.routeHintsExplainer1": "Including route hints will help the LSP forward your payment to you using your unannounced channels.",
"views.Settings.LightningAddressSettings.routeHintsExplainer2": "This has a privacy tradeoff in that it will expose your unannounced channels to the LSP.",
"views.Settings.LightningAddress.deleteAddress": "Delete Address",
"views.Settings.LightningAddress.deleteAddressConfirm": "Are you sure you want to delete your ZEUS Pay Lightning address? This action cannot be undone.",
"views.Settings.LightningAddressInfo.title": "Lightning address info",
"views.Settings.LightningAddressInfo.explainer1": "This lightning address is hosted and powered by our LSP, OLYMPUS by ZEUS. It allows you to accept payments even when you're offline.",
"views.Settings.LightningAddressInfo.explainer2": "It uses payment hashes generated on your device, and hodl invoices, which means the LSP can only temporarily hold the funds and forward them along to you, or return them to the sender (after a 24 hour expiry period), effectively making it self-custodial.",
Expand Down
58 changes: 58 additions & 0 deletions stores/LightningAddressStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -968,4 +968,62 @@ export default class LightningAddressStore {
this.lightningAddressHandle = '';
this.lightningAddressDomain = '';
};

@action
public deleteAddress = async () => {
this.error = false;
this.error_msg = '';
this.loading = true;

try {
const authResponse = await ReactNativeBlobUtil.fetch(
'POST',
`${LNURL_HOST}/lnurl/auth`,
{ 'Content-Type': 'application/json' },
JSON.stringify({
pubkey: this.nodeInfoStore.nodeInfo.identity_pubkey
})
);

const authData = authResponse.json();
if (authResponse.info().status !== 200) throw authData.error;

const { verification } = authData;
const signData = await BackendUtils.signMessage(verification);
const signature = signData.zbase || signData.signature;

const deleteResponse = await ReactNativeBlobUtil.fetch(
'POST',
`${LNURL_HOST}/lnurl/delete`,
{ 'Content-Type': 'application/json' },
JSON.stringify({
pubkey: this.nodeInfoStore.nodeInfo.identity_pubkey,
message: verification,
signature
})
);

const deleteData = deleteResponse.json();
if (deleteResponse.info().status !== 200) throw deleteData.error;

// Clear local storage and reset store state
await Storage.setItem(ADDRESS_ACTIVATED_STRING, false);
await Storage.setItem(HASHES_STORAGE_STRING, '');
this.reset();

runInAction(() => {
this.loading = false;
});

return true;
} catch (error) {
runInAction(() => {
this.error = true;
this.error_msg =
error?.toString() || 'Failed to delete account';
this.loading = false;
});
throw error;
}
};
}
43 changes: 39 additions & 4 deletions views/Settings/LightningAddress/LightningAddressSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import * as React from 'react';
import { ScrollView, View } from 'react-native';
import { ScrollView, View, Alert } from 'react-native';
import { Icon, ListItem } from 'react-native-elements';
import { inject, observer } from 'mobx-react';
import { StackNavigationProp } from '@react-navigation/stack';

import Text from '../../../components/Text';
import Button from '../../../components/Button';
import DropdownSetting from '../../../components/DropdownSetting';
import Header from '../../../components/Header';
import Screen from '../../../components/Screen';
import Switch from '../../../components/Switch';
import Header from '../../../components/Header';
import Text from '../../../components/Text';
import { ErrorMessage } from '../../../components/SuccessErrorMessage';
import LoadingIndicator from '../../../components/LoadingIndicator';
import { StackNavigationProp } from '@react-navigation/stack';

import SettingsStore, {
NOTIFICATIONS_PREF_KEYS,
Expand Down Expand Up @@ -78,6 +79,31 @@ export default class LightningAddressSettings extends React.Component<
});
}

confirmDelete = () => {
Alert.alert(
localeString('views.Settings.LightningAddress.deleteAddress'),
localeString(
'views.Settings.LightningAddress.deleteAddressConfirm'
),
[
{
text: localeString('general.cancel'),
style: 'cancel'
},
{
text: localeString('general.delete'),
onPress: () => {
const { LightningAddressStore } = this.props;
LightningAddressStore.deleteAddress().then(() => {
this.props.navigation.goBack();
});
},
style: 'destructive'
}
]
);
};

render() {
const { navigation, SettingsStore, LightningAddressStore } = this.props;
const {
Expand Down Expand Up @@ -372,6 +398,15 @@ export default class LightningAddressSettings extends React.Component<
color={themeColor('secondaryText')}
/>
</ListItem>
<View style={{ marginTop: 40, marginBottom: 20 }}>
<Button
title={localeString(
'views.Settings.LightningAddress.deleteAddress'
)}
onPress={this.confirmDelete}
warning
/>
</View>
</ScrollView>
</View>
</Screen>
Expand Down

0 comments on commit 0e65b01

Please sign in to comment.