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

Sending Lightning: Success: display preimage #1970

Merged
merged 2 commits into from
Feb 13, 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
16 changes: 15 additions & 1 deletion models/Payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,21 @@ export default class Payment extends BaseModel {
}

@computed public get getPreimage(): string {
return this.preimage || this.payment_preimage;
if (this.preimage) {
if (this.preimage?.type === 'Buffer') {
this.preimage = Base64Utils.bytesToHex(this.preimage.data);
}
return this.preimage;
}
if (this.payment_preimage) {
if (this.payment_preimage?.type === 'Buffer') {
this.payment_preimage = Base64Utils.bytesToHex(
this.payment_preimage.data
);
}
return this.payment_preimage;
}
return '';
}

@computed public get isIncomplete(): boolean {
Expand Down
10 changes: 8 additions & 2 deletions stores/TransactionsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default class TransactionsStore {
@observable transaction: Transaction | null;
@observable payment_route: any; // Route
@observable payment_preimage: string | null;
@observable isIncomplete: boolean | null;
@observable payment_hash: any;
@observable payment_error: any;
@observable onchain_address: string;
Expand Down Expand Up @@ -70,6 +71,7 @@ export default class TransactionsStore {
this.transaction = null;
this.payment_route = null;
this.payment_preimage = null;
this.isIncomplete = null;
this.payment_hash = null;
this.payment_error = null;
this.onchain_address = '';
Expand Down Expand Up @@ -209,6 +211,7 @@ export default class TransactionsStore {
this.error = false;
this.payment_route = null;
this.payment_preimage = null;
this.isIncomplete = null;
this.payment_hash = null;
this.payment_error = null;
this.status = null;
Expand Down Expand Up @@ -306,8 +309,11 @@ export default class TransactionsStore {
public handlePayment = (result: any) => {
this.loading = false;
this.payment_route = result.payment_route;
this.payment_preimage = result.payment_preimage;
this.payment_hash = new Payment(result).paymentHash;

const payment = new Payment(result);
this.payment_preimage = payment.getPreimage;
this.payment_hash = payment.paymentHash;
this.isIncomplete = payment.isIncomplete;

const implementation = this.settingsStore.implementation;

Expand Down
38 changes: 21 additions & 17 deletions views/SendingLightning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ export default class SendingLightning extends React.Component<
error_msg,
payment_hash,
payment_preimage,
payment_error
payment_error,
isIncomplete
} = TransactionsStore;
const { storedNotes } = this.state;

Expand Down Expand Up @@ -317,22 +318,25 @@ export default class SendingLightning extends React.Component<
/>
</View>
)}
{!!payment_hash && !error && !payment_error && (
<View style={{ width: '90%' }}>
<CopyBox
heading={localeString(
'views.SendingLightning.paymentHash'
)}
headingCopied={`${localeString(
'views.SendingLightning.paymentHash'
)} ${localeString(
'components.ExternalLinkModal.copied'
)}`}
theme="dark"
URL={payment_hash}
/>
</View>
)}
{!!payment_preimage &&
!isIncomplete &&
!error &&
!payment_error && (
<View style={{ width: '90%' }}>
<CopyBox
heading={localeString(
'views.Payment.paymentPreimage'
)}
headingCopied={`${localeString(
'views.Payment.paymentPreimage'
)} ${localeString(
'components.ExternalLinkModal.copied'
)}`}
theme="dark"
URL={payment_preimage}
/>
</View>
)}
{
<View
style={[
Expand Down
Loading