Skip to content

Commit

Permalink
LNURL-auth: UI enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
kaloudis committed Sep 26, 2024
1 parent 7846c81 commit 00ae6fb
Showing 1 changed file with 72 additions and 67 deletions.
139 changes: 72 additions & 67 deletions views/LnurlAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ export default class LnurlAuth extends React.Component<
this.setState({ authenticating: true });

const { route } = this.props;
const { domain } = this.state;
const lnurl = route.params?.lnurlParams;
const u = url.parse(lnurl.callback);
const qs = querystring.parse(u.query);
Expand Down Expand Up @@ -203,17 +202,6 @@ export default class LnurlAuth extends React.Component<
signatureSuccess: false,
errorMsgAuth: data.reason
});
Alert.alert(
`[error] ${domain} says:`,
data.reason,
[
{
text: localeString('general.ok'),
onPress: () => void 0
}
],
{ cancelable: false }
);
return;
} else {
this.setState({
Expand All @@ -237,6 +225,13 @@ export default class LnurlAuth extends React.Component<
chooseAuthMode
} = this.state;

const hasError =
!preparingSignature &&
!signatureSuccess &&
!chooseAuthMode &&
!authenticating &&
!lnurlAuthSuccess;

const LndHubAuthMode = () => (
<DropdownSetting
title={localeString('views.LnurlAuth.lndHubAuthMode')}
Expand Down Expand Up @@ -279,67 +274,76 @@ export default class LnurlAuth extends React.Component<
>
{domain}
</Text>
</View>
{this.state.chooseAuthMode && (
<View style={styles.content}>
<View style={styles.dropdown}>
<LndHubAuthMode />

{this.state.chooseAuthMode && (
<View style={styles.content}>
<View style={styles.dropdown}>
<LndHubAuthMode />
</View>
</View>
</View>
)}
<View style={styles.content}>
<View style={styles.button}>
<Button
title={localeString('views.LnurlAuth.login')}
icon={{
name: 'vpn-key',
size: 25,
color: 'white'
}}
onPress={async () => {
if (chooseAuthMode && !signatureSuccess) {
this.setState({ chooseAuthMode: false });
await this.triggerSign();
this.sendValues();
} else {
this.sendValues();
}
}}
style={styles.button}
disabled={
(!signatureSuccess && !chooseAuthMode) ||
authenticating
)}
{(preparingSignature || authenticating) && (
<LightningIndicator />
)}
{lnurlAuthSuccess && (
<SuccessMessage
message={localeString(
'views.LnurlAuth.loginSuccess'
)}
/>
)}
{hasError && (
<ErrorMessage
message={
errorMsgAuth || localeString('general.error')
}
buttonStyle={{
backgroundColor: themeColor('highlight')
}}
/>
</View>
)}
</View>

<View style={styles.content}>
{(preparingSignature || authenticating) && (
<LightningIndicator />
)}
{lnurlAuthSuccess && (
<SuccessMessage
message={localeString(
'views.LnurlAuth.loginSuccess'
)}
<View style={{ marginBottom: 15 }}>
{(hasError || lnurlAuthSuccess) && (
<View style={styles.button}>
<Button
title={localeString('general.goBack')}
onPress={() => {
navigation.navigate('Wallet');
}}
style={styles.button}
/>
)}
{!preparingSignature &&
!signatureSuccess &&
!chooseAuthMode &&
!authenticating &&
!lnurlAuthSuccess && (
<ErrorMessage
message={
errorMsgAuth ||
localeString('general.error')
</View>
)}
{!hasError && !lnurlAuthSuccess && (
<View style={styles.button}>
<Button
title={localeString('views.LnurlAuth.login')}
icon={{
name: 'vpn-key',
size: 25,
color: 'white'
}}
onPress={async () => {
if (chooseAuthMode && !signatureSuccess) {
this.setState({
chooseAuthMode: false
});
await this.triggerSign();
this.sendValues();
} else {
this.sendValues();
}
/>
)}
</View>
}}
style={styles.button}
disabled={
(!signatureSuccess && !chooseAuthMode) ||
authenticating
}
buttonStyle={{
backgroundColor: themeColor('highlight')
}}
/>
</View>
)}
</View>
</Screen>
);
Expand All @@ -348,6 +352,7 @@ export default class LnurlAuth extends React.Component<

const styles = StyleSheet.create({
content: {
flex: 1,
paddingLeft: 20,
paddingRight: 20
},
Expand Down

0 comments on commit 00ae6fb

Please sign in to comment.