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

Invoices: simplify copy format #1360

Merged
merged 1 commit into from
Mar 15, 2023
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
4 changes: 3 additions & 1 deletion components/CollapsedQR.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface CollapsedQRProps {
showText?: string;
collapseText?: string;
copyText?: string;
copyValue?: string;
hideText?: boolean;
expanded?: boolean;
textBottom?: boolean;
Expand Down Expand Up @@ -82,6 +83,7 @@ export default class CollapsedQR extends React.Component<
value,
showText,
copyText,
copyValue,
collapseText,
hideText,
expanded,
Expand Down Expand Up @@ -141,7 +143,7 @@ export default class CollapsedQR extends React.Component<
onPress={() => this.toggleCollapse()}
/>
)}
<CopyButton copyValue={value} title={copyText} />
<CopyButton copyValue={copyValue || value} title={copyText} />
{Platform.OS === 'android' && (
<Button
title={
Expand Down
16 changes: 15 additions & 1 deletion views/Receive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,11 @@ export default class Receive extends React.Component<
const haveUnifiedInvoice = !!payment_request && !!address;
const haveInvoice = !!payment_request || !!address;

let unifiedInvoice, lnInvoice, btcAddress;
let unifiedInvoice,
lnInvoice,
lnInvoiceCopyValue,
btcAddress,
btcAddressCopyValue;
// if format is case insensitive, format as all caps to save QR space, otherwise present in original format
const onChainFormatted =
address && address === address.toLowerCase()
Expand All @@ -758,6 +762,7 @@ export default class Receive extends React.Component<

if (payment_request) {
lnInvoice = `lightning:${payment_request.toUpperCase()}`;
lnInvoiceCopyValue = payment_request;
}

if (address) {
Expand All @@ -776,6 +781,12 @@ export default class Receive extends React.Component<
: `message=${memo.replace(/ /g, '%20')}`
: ''
}`;

if (Number(satAmount) > 0 || memo) {
btcAddressCopyValue = btcAddress;
} else {
btcAddressCopyValue = address;
}
}

const belowDustLimit: boolean =
Expand Down Expand Up @@ -930,6 +941,7 @@ export default class Receive extends React.Component<
haveUnifiedInvoice && (
<CollapsedQR
value={lnInvoice}
copyValue={lnInvoiceCopyValue}
copyText={localeString(
'views.Receive.copyInvoice'
)}
Expand All @@ -942,6 +954,7 @@ export default class Receive extends React.Component<
haveUnifiedInvoice && (
<CollapsedQR
value={btcAddress}
copyValue={btcAddressCopyValue}
copyText={localeString(
'views.Receive.copyAddress'
)}
Expand All @@ -953,6 +966,7 @@ export default class Receive extends React.Component<
!haveUnifiedInvoice) && (
<CollapsedQR
value={lnInvoice}
copyValue={lnInvoiceCopyValue}
copyText={localeString(
'views.Receive.copyAddress'
)}
Expand Down