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

Contacts: Added Bolt12 offers #2288

Merged
merged 3 commits into from
Jul 18, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,7 @@
"views.PayCode.internalLabel": "Internal label",
"views.PayCodes.noPayCodes": "No pay codes created yet",
"views.Settings.Bolt12Address": "BOLT 12 address",
"views.Settings.Bolt12Offer": "BOLT 12 offer",
"views.Settings.Bolt12Address.requestButton": "Request Paycode",
"views.Settings.Bolt12Address.changeButton": "Change Paycode",
"views.Settings.Bolt12Address.handle": "Your handle",
Expand Down Expand Up @@ -1230,4 +1231,4 @@
"views.PendingHTLCs.expirationHeight": "Expiration height",
"views.PendingHTLCs.recommendationIOS": "It's recommended to leave ZEUS running while there are pending HTLCs to prevent force closes.",
"views.PendingHTLCs.recommendationAndroid": "It's recommended to enable Persistent LND or leave ZEUS running while there are pending HTLCs to prevent force closes."
}
}
42 changes: 38 additions & 4 deletions models/Contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default class Contact extends BaseModel {
public contactId: string;
public lnAddress: Array<string>;
public bolt12Address: Array<string>;
public bolt12Offer: Array<string>;
public onchainAddress: Array<string>;
public pubkey: Array<string>;
public nip05: Array<string>;
Expand All @@ -32,7 +33,10 @@ export default class Contact extends BaseModel {
!this.bolt12Address[0] ||
this.bolt12Address[0] === '') &&
(!this.onchainAddress[0] || this.onchainAddress[0] === '') &&
(!this.pubkey[0] || this.pubkey[0] === '')
(!this.pubkey[0] || this.pubkey[0] === '') &&
(!this.bolt12Offer ||
!this.bolt12Offer[0] ||
this.bolt12Offer[0] === '')
);
}

Expand All @@ -43,7 +47,24 @@ export default class Contact extends BaseModel {
this.bolt12Address[0] !== '' &&
(!this.lnAddress[0] || this.lnAddress[0] === '') &&
(!this.onchainAddress[0] || this.onchainAddress[0] === '') &&
(!this.pubkey[0] || this.pubkey[0] === '')
(!this.pubkey[0] || this.pubkey[0] === '') &&
(!this.bolt12Offer ||
!this.bolt12Offer[0] ||
this.bolt12Offer[0] === '')
);
}

@computed public get isSingleBolt12Offer(): boolean {
return (
this.bolt12Offer &&
this.bolt12Offer.length === 1 &&
this.bolt12Offer[0] !== '' &&
(!this.lnAddress[0] || this.lnAddress[0] === '') &&
(!this.onchainAddress[0] || this.onchainAddress[0] === '') &&
(!this.pubkey[0] || this.pubkey[0] === '') &&
(!this.bolt12Address ||
!this.bolt12Address[0] ||
this.bolt12Address[0] === '')
);
}

Expand All @@ -56,7 +77,10 @@ export default class Contact extends BaseModel {
(!this.bolt12Address ||
!this.bolt12Address[0] ||
this.bolt12Address[0] === '') &&
(!this.pubkey[0] || this.pubkey[0] === '')
(!this.pubkey[0] || this.pubkey[0] === '') &&
(!this.bolt12Offer ||
!this.bolt12Offer[0] ||
this.bolt12Offer[0] === '')
);
}

Expand All @@ -69,7 +93,10 @@ export default class Contact extends BaseModel {
(!this.bolt12Address ||
!this.bolt12Address[0] ||
this.bolt12Address[0] === '') &&
(!this.onchainAddress[0] || this.onchainAddress[0] === '')
(!this.onchainAddress[0] || this.onchainAddress[0] === '') &&
(!this.bolt12Offer ||
!this.bolt12Offer[0] ||
this.bolt12Offer[0] === '')
);
}

Expand All @@ -81,6 +108,10 @@ export default class Contact extends BaseModel {
return this.bolt12Address?.length > 0 && this.bolt12Address[0] !== '';
}

@computed public get hasBolt12Offer(): boolean {
return this.bolt12Offer?.length > 0 && this.bolt12Offer[0] !== '';
}

@computed public get hasOnchainAddress(): boolean {
return this.onchainAddress?.length > 0 && this.onchainAddress[0] !== '';
}
Expand All @@ -97,6 +128,9 @@ export default class Contact extends BaseModel {
this.bolt12Address?.forEach((address) => {
if (address && address !== '') count++;
});
this.bolt12Offer?.forEach((address) => {
if (address && address !== '') count++;
});
this.onchainAddress.forEach((address) => {
if (address && address !== '') count++;
});
Expand Down
38 changes: 38 additions & 0 deletions views/ContactDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default class ContactDetails extends React.Component<
contact: {
lnAddress: [''],
bolt12Address: [''],
bolt12Offer: [''],
onchainAddress: [''],
pubkey: [''],
nip05: [''],
Expand Down Expand Up @@ -463,6 +464,43 @@ export default class ContactDetails extends React.Component<
</View>
)}

{contact.hasBolt12Offer && (
<View>
{contact.bolt12Offer.map(
(address: string, index: number) => (
<TouchableOpacity
key={index}
onPress={() =>
this.sendAddress(address)
}
>
<View style={styles.contactRow}>
<LightningBolt />
<Text
style={{
...styles.contactFields,
color: themeColor(
'chain'
)
}}
>
{address.length > 23
? `${address.substring(
0,
10
)}...${address.substring(
address.length -
10
)}`
: address}
</Text>
</View>
</TouchableOpacity>
)
)}
</View>
)}

{contact.hasPubkey && (
<View>
{contact.pubkey.map(
Expand Down
18 changes: 17 additions & 1 deletion views/Send.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ export default class Send extends React.Component<SendProps, SendState> {
const {
hasLnAddress,
hasBolt12Address,
hasBolt12Offer,
hasOnchainAddress,
hasPubkey,
hasMultiplePayableAddresses
Expand Down Expand Up @@ -557,6 +558,15 @@ export default class Send extends React.Component<SendProps, SendState> {
: item.bolt12Address[0];
}

if (hasBolt12Offer) {
return item.bolt12Offer[0].length > 23
? `${item.bolt12Offer[0].slice(
0,
10
)}...${item.bolt12Offer[0].slice(-10)}`
: item.bolt12Offer[0];
}

if (hasOnchainAddress) {
return item.onchainAddress[0].length > 23
? `${item.onchainAddress[0].slice(
Expand Down Expand Up @@ -585,6 +595,8 @@ export default class Send extends React.Component<SendProps, SendState> {
this.validateAddress(item.lnAddress[0]);
} else if (contact.isSingleBolt12Address) {
this.validateAddress(item.bolt12Address[0]);
} else if (contact.isSingleBolt12Offer) {
this.validateAddress(item.bolt12Offer[0]);
} else if (contact.isSingleOnchainAddress) {
this.validateAddress(item.onchainAddress[0]);
} else if (contact.isSinglePubkey) {
Expand Down Expand Up @@ -687,8 +699,12 @@ export default class Send extends React.Component<SendProps, SendState> {
const paymentOptions = [localeString('views.Send.lnPayment')];

if (BackendUtils.supportsOffers()) {
paymentOptions.push(localeString('views.Settings.Bolt12Address'));
paymentOptions.push(
localeString('views.Settings.Bolt12Address'),
localeString('views.Settings.Bolt12Offer')
);
}

if (BackendUtils.supportsOnchainSends()) {
paymentOptions.push(localeString('views.Send.btcAddress'));
}
Expand Down
Loading
Loading