Skip to content

Commit

Permalink
using themeColor for readonly badge, added LNC check for supportsLigh…
Browse files Browse the repository at this point in the history
…tningSends
  • Loading branch information
myxmaster committed Oct 18, 2023
1 parent 6d2b04b commit 289554d
Show file tree
Hide file tree
Showing 13 changed files with 142 additions and 80 deletions.
1 change: 1 addition & 0 deletions backends/CLightningREST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ export default class CLightningREST extends LND {
supportsLnurlAuth = () => true;
supportsOnchainSends = () => true;
supportsOnchainReceiving = () => true;
supportsLightningSends = () => true;
supportsKeysend = () => true;
supportsChannelManagement = () => true;
supportsPendingChannels = () => false;
Expand Down
1 change: 1 addition & 0 deletions backends/Eclair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ export default class Eclair {
supportsLnurlAuth = () => true;
supportsOnchainSends = () => true;
supportsOnchainReceiving = () => true;
supportsLightningSends = () => true;
supportsKeysend = () => false;
supportsChannelManagement = () => true;
supportsPendingChannels = () => false;
Expand Down
1 change: 1 addition & 0 deletions backends/EmbeddedLND.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export default class EmbeddedLND extends LND {
supportsLnurlAuth = () => true;
supportsOnchainSends = () => true;
supportsOnchainReceiving = () => true;
supportsLightningSends = () => true;
supportsKeysend = () => true;
supportsChannelManagement = () => true;
supportsPendingChannels = () => true;
Expand Down
1 change: 1 addition & 0 deletions backends/LND.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ export default class LND {
supportsLnurlAuth = () => true;
supportsOnchainSends = () => true;
supportsOnchainReceiving = () => true;
supportsLightningSends = () => true;
supportsKeysend = () => true;
supportsChannelManagement = () => true;
supportsPendingChannels = () => true;
Expand Down
1 change: 1 addition & 0 deletions backends/LightningNodeConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ export default class LightningNodeConnect {
supportsLnurlAuth = () => true;
supportsOnchainSends = () => this.permSendCoins;
supportsOnchainReceiving = () => this.permNewAddress;
supportsLightningSends = () => this.permSendCoins;
supportsKeysend = () => true;
supportsChannelManagement = () => this.permOpenChannel;
supportsPendingChannels = () => true;
Expand Down
6 changes: 6 additions & 0 deletions backends/LndHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ export default class LndHub extends LND {
// LNBits
stores?.settingsStore?.lndhubUrl?.includes('/lndhub/ext/')
);
supportsLightningSends = () => {
return !(
stores?.settingsStore?.lndhubUrl?.includes('/lndhub/ext/') &&
stores.settingsStore.username === 'invoice'
);
};
supportsKeysend = () => false;
supportsChannelManagement = () => false;
supportsPendingChannels = () => false;
Expand Down
1 change: 1 addition & 0 deletions backends/Spark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ export default class Spark {
supportsLnurlAuth = () => false;
supportsOnchainSends = () => true;
supportsOnchainReceiving = () => true;
supportsLightningSends = () => true;
supportsKeysend = () => false;
supportsChannelManagement = () => true;
supportsPendingChannels = () => false;
Expand Down
59 changes: 35 additions & 24 deletions components/LayerBalances/LightningSwipeableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,32 +105,43 @@ export default class LightningSwipeableRow extends Component<
);
};

private renderActions = (progress: Animated.AnimatedInterpolation) => (
<View
style={{
marginLeft: 15,
width: BackendUtils.supportsRouting() ? 200 : 135,
flexDirection: I18nManager.isRTL ? 'row-reverse' : 'row'
}}
>
{this.renderAction(
localeString('general.receive'),
BackendUtils.supportsRouting() ? 200 : 135,
progress
)}
{BackendUtils.supportsRouting() &&
this.renderAction(
localeString('general.routing'),
200,
private renderActions = (progress: Animated.AnimatedInterpolation) => {
const width =
BackendUtils.supportsRouting() &&
BackendUtils.supportsLightningSends()
? 200
: BackendUtils.supportsRouting() ||
BackendUtils.supportsLightningSends()
? 135
: 70;
return (
<View
style={{
marginLeft: 15,
width,
flexDirection: I18nManager.isRTL ? 'row-reverse' : 'row'
}}
>
{this.renderAction(
localeString('general.receive'),
width,
progress
)}
{this.renderAction(
localeString('general.send'),
BackendUtils.supportsRouting() ? 200 : 135,
progress
)}
</View>
);
{BackendUtils.supportsRouting() &&
this.renderAction(
localeString('general.routing'),
width,
progress
)}
{BackendUtils.supportsLightningSends() &&
this.renderAction(
localeString('general.send'),
width,
progress
)}
</View>
);
};

private swipeableRow?: Swipeable;

Expand Down
17 changes: 17 additions & 0 deletions components/WalletHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import handleAnything, { isClipboardValue } from '../utils/handleAnything';
import { localeString } from '../utils/LocaleUtils';
import PrivacyUtils from '../utils/PrivacyUtils';
import { themeColor } from '../utils/ThemeUtils';
import BackendUtils from '../utils/BackendUtils';

import Add from '../assets/images/SVG/Add.svg';
import ClipboardSVG from '../assets/images/SVG/Clipboard.svg';
Expand Down Expand Up @@ -282,6 +283,20 @@ export default class WalletHeader extends React.Component<
</>
);

const ReadOnlyBadge = () => {
return !BackendUtils.supportsLightningSends() ? (
<Badge
value={localeString('general.readOnlyWallet')}
badgeStyle={{
backgroundColor: themeColor('error'),
borderWidth: 0,
marginLeft: 8,
marginRight: 8
}}
/>
) : null;
};

const SearchButton = () => (
<TouchableOpacity
onPress={() => ChannelsStore!.toggleSearch()}
Expand Down Expand Up @@ -411,12 +426,14 @@ export default class WalletHeader extends React.Component<
)?.toString()}
</Text>
<NetworkBadge />
<ReadOnlyBadge />
<TorBadge />
</Row>
</View>
) : (
<Row>
<NetworkBadge />
<ReadOnlyBadge />
<TorBadge />
</Row>
)
Expand Down
2 changes: 2 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"general.content": "Content",
"general.lightningInvoice": "Lightning invoice",
"general.or": "or",
"general.readOnlyWallet": "Read-only Wallet",
"nostr.keys": "Nostr keys",
"nostr.pubkey": "Nostr pubkey",
"nostr.privkey": "Nostr private key",
Expand Down Expand Up @@ -495,6 +496,7 @@
"views.PaymentRequest.lndGettingReadyReceive": "LND is getting ready to receive payments. Please wait.",
"views.PaymentRequest.isPmtHashSigValid": "Payment hash signature",
"views.PaymentRequest.isRelaysSigValid": "Relays signature",
"views.PaymentRequest.notAllowedToSend": "This wallet is not allowed to send funds!",
"views.Receive.title": "Receive",
"views.Receive.successCreate": "Successfully created invoice",
"views.Receive.warningLndHub": "Please note that LNDHub has a fixed on-chain address",
Expand Down
1 change: 1 addition & 0 deletions utils/BackendUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class BackendUtils {
supportsLnurlAuth = () => this.call('supportsLnurlAuth');
supportsOnchainSends = () => this.call('supportsOnchainSends');
supportsOnchainReceiving = () => this.call('supportsOnchainReceiving');
supportsLightningSends = () => this.call('supportsLightningSends');
supportsKeysend = () => this.call('supportsKeysend');
supportsChannelManagement = () => this.call('supportsChannelManagement');
supportsPendingChannels = () => this.call('supportsPendingChannels');
Expand Down
128 changes: 72 additions & 56 deletions views/PaymentRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ export default class PaymentRequest extends React.Component<
{!loading && !loadingFeeEstimate && !!pay_req && (
<View style={styles.content}>
<>
{noBalance && (
{!BackendUtils.supportsLightningSends() && (
<View
style={{
paddingTop: 10,
Expand All @@ -417,11 +417,26 @@ export default class PaymentRequest extends React.Component<
>
<WarningMessage
message={localeString(
'views.Send.noLightningBalance'
'views.PaymentRequest.notAllowedToSend'
)}
/>
</View>
)}
{noBalance &&
BackendUtils.supportsLightningSends() && (
<View
style={{
paddingTop: 10,
paddingBottom: 10
}}
>
<WarningMessage
message={localeString(
'views.Send.noLightningBalance'
)}
/>
</View>
)}
{isNoAmountInvoice ? (
<AmountInput
amount={customAmount}
Expand Down Expand Up @@ -1100,61 +1115,62 @@ export default class PaymentRequest extends React.Component<
</>
)}

{!!pay_req && (
<View style={styles.button}>
<Button
title={localeString(
'views.PaymentRequest.payInvoice'
)}
icon={
lightningReadyToSend
? {
name: 'send',
size: 25
}
: undefined
}
onPress={() => {
if (isZaplocker)
LnurlPayStore.broadcastAttestation();
this.sendPayment(
feeOption,
String(percentAmount),
{
payment_request:
paymentRequest,
amount: satAmount
? satAmount.toString()
: undefined,
max_parts:
enableMultiPathPayment
? maxParts
: null,
max_shard_amt:
enableMultiPathPayment
? maxShardAmt
: null,
fee_limit_sat: isLnd
? feeLimitSat
: null,
max_fee_percent:
isCLightning
? maxFeePercentFormatted
{!!pay_req &&
BackendUtils.supportsLightningSends() && (
<View style={styles.button}>
<Button
title={localeString(
'views.PaymentRequest.payInvoice'
)}
icon={
lightningReadyToSend
? {
name: 'send',
size: 25
}
: undefined
}
onPress={() => {
if (isZaplocker)
LnurlPayStore.broadcastAttestation();
this.sendPayment(
feeOption,
String(percentAmount),
{
payment_request:
paymentRequest,
amount: satAmount
? satAmount.toString()
: undefined,
max_parts:
enableMultiPathPayment
? maxParts
: null,
max_shard_amt:
enableMultiPathPayment
? maxShardAmt
: null,
fee_limit_sat: isLnd
? feeLimitSat
: null,
outgoing_chan_id:
outgoingChanId,
last_hop_pubkey:
lastHopPubkey,
amp: enableAmp,
timeout_seconds:
timeoutSeconds
}
);
}}
disabled={!lightningReadyToSend}
/>
</View>
)}
max_fee_percent:
isCLightning
? maxFeePercentFormatted
: null,
outgoing_chan_id:
outgoingChanId,
last_hop_pubkey:
lastHopPubkey,
amp: enableAmp,
timeout_seconds:
timeoutSeconds
}
);
}}
disabled={!lightningReadyToSend}
/>
</View>
)}
</View>
)}
</ScrollView>
Expand Down
3 changes: 3 additions & 0 deletions views/Wallet/KeypadPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,9 @@ export default class KeypadPane extends React.PureComponent<
});
}}
buttonStyle={{ height: 40 }}
disabled={
!BackendUtils.supportsLightningSends()
}
/>
</View>
</View>
Expand Down

0 comments on commit 289554d

Please sign in to comment.