Skip to content

Commit

Permalink
feat: Add payjoin sends
Browse files Browse the repository at this point in the history
  • Loading branch information
benalleng authored and benthecarman committed Jan 25, 2024
1 parent c680ab2 commit 8ff11a2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/i18n/en/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ export default {
error_keysend: "Keysend failed",
error_LNURL: "LNURL Pay failed",
error_expired: "Invoice is expired",
payjoin_send:
"This is a payjoin! The Mutiny will continue until privacy improves",
payment_pending: "Payment pending",
payment_pending_description:
"It's taking a while, but it's possible this payment may still go through. Please check 'Activity' for the current status.",
Expand Down
4 changes: 4 additions & 0 deletions src/logic/waila.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { Result } from "~/utils";
await initWaila();

export type ParsedParams = {
original: string;
address?: string;
payjoin_enabled?: boolean;
invoice?: string;
amount_sats?: bigint;
network?: string;
Expand Down Expand Up @@ -53,7 +55,9 @@ export function toParsedParams(
return {
ok: true,
value: {
original: str,
address: params.address,
payjoin_enabled: params.payjoin_supported,
invoice: params.invoice,
amount_sats: params.amount_sats,
network,
Expand Down
21 changes: 20 additions & 1 deletion src/routes/Send.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,9 @@ export function Send() {
const [nodePubkey, setNodePubkey] = createSignal<string>();
const [lnurlp, setLnurlp] = createSignal<string>();
const [lnAddress, setLnAddress] = createSignal<string>();
const [originalScan, setOriginalScan] = createSignal<string>();
const [address, setAddress] = createSignal<string>();
const [payjoinEnabled, setPayjoinEnabled] = createSignal<boolean>();
const [description, setDescription] = createSignal<string>();
const [contactId, setContactId] = createSignal<string>();
const [isHodlInvoice, setIsHodlInvoice] = createSignal<boolean>(false);
Expand Down Expand Up @@ -414,9 +416,11 @@ export function Send() {
function handleDestination(source: ParsedParams | undefined) {
if (!source) return;
setParsingDestination(true);

setOriginalScan(source.original);
try {
if (source.address) setAddress(source.address);
if (source.payjoin_enabled)
setPayjoinEnabled(source.payjoin_enabled);
if (source.memo) setDescription(source.memo);
if (source.contact_id) setContactId(source.contact_id);

Expand Down Expand Up @@ -594,6 +598,16 @@ export function Send() {
tags
);

sentDetails.amount = amountSats();
sentDetails.destination = address();
sentDetails.txid = txid;
sentDetails.fee_estimate = feeEstimate() ?? 0;
} else if (payjoinEnabled()) {
const txid = await state.mutiny_wallet?.send_payjoin(
originalScan()!,
amountSats(),
tags
);
sentDetails.amount = amountSats();
sentDetails.destination = address();
sentDetails.txid = txid;
Expand Down Expand Up @@ -789,6 +803,11 @@ export function Send() {
setChosenMethod={setSourceFromMethod}
/>
</Show>
<Show when={payjoinEnabled()}>
<InfoBox accent="green">
<p>{i18n.t("send.payjoin_send")}</p>
</InfoBox>
</Show>
<Show when={!isAmtEditable()}>
<AmountEditable
initialAmountSats={amountSats()}
Expand Down
1 change: 1 addition & 0 deletions src/state/megaStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ export const Provider: ParentComponent = (props) => {
} else {
if (
result.value?.address ||
result.value?.payjoin_enabled ||
result.value?.invoice ||
result.value?.node_pubkey ||
(result.value?.lnurl && !result.value.is_lnurl_auth)
Expand Down

0 comments on commit 8ff11a2

Please sign in to comment.