Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AddEditNode: add Spark QR scanner #1004

Merged
merged 1 commit into from
May 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions Navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Invoice from './views/Invoice';
import BTCPayConfigQRScanner from './views/BTCPayConfigQRScanner';
import LNDConnectConfigQRScanner from './views/LNDConnectConfigQRScanner';
import LNDHubQRScanner from './views/LNDHubQRScanner';
import SparkQRScanner from './views/SparkQRScanner';
import NodeInfo from './views/NodeInfo';
import Lockscreen from './views/Lockscreen';

Expand Down Expand Up @@ -211,6 +212,9 @@ const AppScenes = {
},
ImportAccountQRScanner: {
screen: ImportAccountQRScanner
},
SparkQRScanner: {
screen: SparkQRScanner
}
};

Expand Down
3 changes: 3 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
"views.Settings.AddEditNode.scanLndconnect": "Scan lndconnect config",
"views.Settings.AddEditNode.scanBtcpay": "Scan BTCPay config",
"views.Settings.AddEditNode.scanLndhub": "Scan LNDHub QR",
"views.Settings.AddEditNode.scanSpark": "Scan Spark QR",
"views.Settings.AddEditNode.deleteNode": "Delete Node config",
"views.Settings.AddEditNode.copyNode": "Copy Node config",
"views.Settings.AddEditNode.nodeInterface": "Node interface",
Expand All @@ -132,6 +133,8 @@
"views.Settings.Security.deletePIN": "Delete PIN",
"views.Settings.Security.deleteDuressPIN": "Delete Duress PIN",
"views.Settings.Security.scramblePIN": "Scramble PIN numbers",
"views.SparkQRScanner.text": "Scan a Spark QR code",
"views.SparkQRScanner.error": "Error fetching Spark config",
"views.ImportAccount.title": "Import account",
"views.ImportAccount.name": "Account Name",
"views.ImportAccount.extendedPubKey": "Extended Public Key (Xpub)",
Expand Down
8 changes: 0 additions & 8 deletions views/LNDHubQRScanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ export default class LNDHubQRScanner extends React.Component<
LNDHubQRProps,
{}
> {
constructor(props: any) {
super(props);

this.state = {
useInternalScanner: false
};
}

handleCodeScanned = (data: string) => {
const { navigation } = this.props;
handleAnything(data)
Expand Down
16 changes: 16 additions & 0 deletions views/Settings/AddEditNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,22 @@ export default class AddEditNode extends React.Component<
</View>
)}

{implementation === 'spark' && (
<View style={styles.button}>
<Button
title={localeString(
'views.Settings.AddEditNode.scanSpark'
)}
onPress={() =>
navigation.navigate('SparkQRScanner', {
index
})
}
secondary
/>
</View>
)}

{saved && (
<View style={styles.button}>
<Button
Expand Down
48 changes: 48 additions & 0 deletions views/SparkQRScanner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Alert } from 'react-native';
import QRCodeScanner from './../components/QRCodeScanner';
import { localeString } from './../utils/LocaleUtils';

interface SparkQRProps {
navigation: any;
}

export default class SparkQRScanner extends React.Component<SparkQRProps, {}> {
handleSparkInvoiceScanned = (data: string) => {
const { navigation } = this.props;

const index = navigation.getParam('index', null);

const [url, accessKey] = data.split('?access-key=');

if (url && accessKey) {
navigation.navigate('AddEditNode', {
node: { url, accessKey },
enableTor: url && url.includes('.onion'),
index
});
} else {
Alert.alert(
localeString('general.error'),
localeString('views.SparkQRScanner.error'),
[{ text: localeString('general.ok'), onPress: () => void 0 }],
{ cancelable: false }
);

navigation.navigate('Settings');
}
};

render() {
const { navigation } = this.props;

const index = navigation.getParam('index', null);

return (
<QRCodeScanner
text={localeString('views.SparkQRScanner.text')}
handleQRScanned={this.handleSparkInvoiceScanned}
goBack={() => navigation.navigate('AddEditNode', { index })}
/>
);
}
}