Skip to content

Commit

Permalink
fix invoice expiration
Browse files Browse the repository at this point in the history
  • Loading branch information
cstenglein committed Jul 3, 2022
1 parent 8700395 commit 0346a5f
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 29 deletions.
81 changes: 66 additions & 15 deletions backend-mock/lightning.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ router.post("/add-invoice", (req, res) => {
`call to /api/v1/lightning/add-invoice with value ${req.query.value_msat} and memo ${req.query.memo}`
);
res.send(
// LND invoice
JSON.stringify({
payment_request:
"lnbcrt2u1pseumjxpp5v86496waqjpnt2y6wxa77er2wsrp6afqqmnk3ap0kzjr857vj7ksdqvvdhk6mt9de6qcqzpgxqrrsssp5dvku88d87th4wqmstcl4watfsje0azhk35wtey3vlh59nrr7s2qs9qyyssq3j2l3e3d022vz290j2m5asp7sgud036gfxg2ltm33nm2tcxqz7mntcfd8s3s5v28cna25nmraf75ugsvrflalhamvqrep6fed7amuvcqxnzjpe",
"lnbcrt500u1p3vza0ppp5nyyutzvav66suf7070wxje3ys7mrx44283l6u82cywjrc0ylunhsdqqcqzpgxqyz5vqsp5j5wdagc9nwxsqu9z2r562nznwqlgw760tr8nkx7ty3ahrks73lgq9qyyssqjf0r2apc84cvcyrp4w3rt3ymm44hl2kveavjsmjee9xdc35s8a6j3zyzqckkpyehgxpvuyqe4q9r5uejaqysg6vslr2wdt82wg4jm7cqp3xxp9",
})
// CLN invoice
// JSON.stringify({
// payment_request:
// "lnbcrt500u1p3vzavmsp5pmsj2spnr2lnwc2zsvk34aknjgdgx4gvh2ysmhtla2z97vtdanhspp5kkgdwd64vtrc357f37k83y3cse3e78z6nnxsw52r7gl5dut8grzsdp92phkcctjypykuan0d93k2grxdaezqcmpwfhkcxqyjw5qcqp29qyysgq23lvlur06f7ltsct9tl8pjaezztpmm8z4hmq03nh7yscanww60zravptucv8l7ekeefp80050c8rwrywty932l0wtyke5dn0shzlg5gpxctemt",
// })
);
});

Expand All @@ -34,37 +40,38 @@ router.get("/decode-pay-req", (req, res) => {
);

setTimeout(() => {
// LND invoice
return res.status(200).send(
JSON.stringify({
destination:
"0323dbd695d801553837f9907100f304abd153932bb000a3a7ea9132ff3e7437a1",
"03fd5eeea1e7ef8bf25124e5bb0f4546e1dd28ce09d6c0d5136f417d74e8afb270",
payment_hash:
"dc171b0d9a6c33d40ba2d9ed95819b29af40d83132b15072ab4e8b60feb08b90",
num_satoshis: 20,
timestamp: 1893456000000,
expiry: 36000,
description: "TEST",
"9909c5899d66b50e27cff3dc69662487b63356aa3c7fae1d5823a43c3c9fe4ef",
num_satoshis: 50000,
timestamp: 1656845793,
expiry: 86400,
description: "",
description_hash: "",
fallback_addr: "",
cltv_expiry: 40,
route_hints: [],
payment_addr:
"24efc95be534b44b801ea5603b9aa1ad5424196972c7a3357b478e773b55f22e",
num_msat: 20000,
"951cdea3059b8d0070a250e9a54c53703e877b4f58cf3b1bcb247b71da1e8fd0",
num_msat: 50000000,
features: [
{
key: 9,
key: 14,
value: {
name: "tlv-onion",
is_required: false,
name: "payment-addr",
is_required: true,
is_known: true,
},
},
{
key: 14,
key: 9,
value: {
name: "payment-addr",
is_required: true,
name: "tlv-onion",
is_required: false,
is_known: true,
},
},
Expand All @@ -77,9 +84,53 @@ router.get("/decode-pay-req", (req, res) => {
},
},
],
currency: "",
})
);
}, 1500);

// CLN invoice
// return res.status(200).send(JSON.stringify({
// "destination": "0221861fdbe92325c98bf90c61b68b8419ba825d6b8901eb46fa1c5f9fc7ec7eee",
// "payment_hash": "b590d7375562c788d3c98fac78923886639f1c5a9ccd075143f23f46f16740c5",
// "num_satoshis": 50000,
// "timestamp": 1656845723,
// "expiry": 604800,
// "description": "Polar Invoice for carol",
// "description_hash": "",
// "fallback_addr": "",
// "cltv_expiry": 10,
// "route_hints": [],
// "payment_addr": "0ee12540331abf376142832d1af6d3921a83550cba890ddd7fea845f316decef",
// "num_msat": 50000000,
// "features": [
// {
// "key": 14,
// "value": {
// "name": "payment-addr",
// "is_required": true,
// "is_known": true
// }
// },
// {
// "key": 17,
// "value": {
// "name": "multi-path-payments",
// "is_required": false,
// "is_known": true
// }
// },
// {
// "key": 8,
// "value": {
// "name": "tlv-onion",
// "is_required": true,
// "is_known": true
// }
// }
// ],
// "currency": ""
// }));
});

router.post("/send-payment", (req, res) => {
Expand Down
2 changes: 1 addition & 1 deletion backend-mock/sse/ln_info_lite.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const lnInfoLite = () => {
console.info("sending ln_info_lite");

util.sendSSE("ln_info_lite", {
implementation: "LND",
implementation: "LND_GRPC",
version: "0.13.0-beta commit=v0.13.0-beta",
identity_pubkey: "somePubKey@Toraddress:port",
num_pending_channels: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const basicProps: Props = {
fee: "",
invoiceAmount: 0,
invoiceType: TxType.LIGHTNING,
timestamp: 1893456000000, // 01 Jan 2030 00:00:00 GMT
timestamp: 1893456000, // 01 Jan 2030 00:00:00 GMT
};

describe("ConfirmSendModal", () => {
Expand Down Expand Up @@ -90,7 +90,7 @@ describe("ConfirmSendModal", () => {
<I18nextProvider i18n={i18n}>
<ConfirmSendModal
{...basicProps}
timestamp={1640995200000} // "Sat Jan 01 2022 08:00:00
timestamp={1640995200} // "Sat Jan 01 2022 08:00:00
expiry={36000}
/>
</I18nextProvider>
Expand Down Expand Up @@ -136,7 +136,7 @@ describe("ConfirmSendModal", () => {
await screen.findByRole("button", {
name: "check.svg settings.confirm",
})
).not.toBeDisabled();
).toBeDisabled();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type Props = {
fee: string;
invoiceAmount: number;
invoiceType: TxType;
/** epoch time in seconds */
timestamp: number;
};

Expand All @@ -50,13 +51,11 @@ const ConfirmSendModal: FC<Props> = ({
setAmountInput(+event.target.value);
};

const invoiceExpiryDate = timestamp + expiry;
const invoiceExpiryDate = (timestamp + expiry) * 1000;
const invoiceExpiryDateDecorated = new Intl.DateTimeFormat("default", {
dateStyle: "medium",
timeStyle: "medium",
})
.format(invoiceExpiryDate)
.toString();
}).format(new Date(invoiceExpiryDate));
const isInvoiceExpired: boolean = isLnTx && invoiceExpiryDate < Date.now();
const isInvoiceAmountBiggerThanBalance: boolean = invoiceAmount > balance;
const isValidLnInvoice: boolean =
Expand All @@ -66,7 +65,7 @@ const ConfirmSendModal: FC<Props> = ({
const {
register,
handleSubmit,
formState: { errors, isValid, submitCount },
formState: { errors, isValid },
} = useForm<IFormInputs>({
mode: "onChange",
});
Expand Down Expand Up @@ -190,7 +189,7 @@ const ConfirmSendModal: FC<Props> = ({
<button
className="bd-button flex py-2 px-3"
type="submit"
disabled={(submitCount > 0 && !isValid) || !isValidLnInvoice}
disabled={!isValid || !isValidLnInvoice}
>
<CheckIcon />
&nbsp; {t("settings.confirm")}
Expand Down
2 changes: 1 addition & 1 deletion src/models/ln-info-lite.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface LnInfoLite {
implementation: string | null;
implementation: "LND_GRPC" | "CLN_GRPC" | "NULL" | "" | null;
version: string;
identity_pubkey: string;
num_pending_channels: number;
Expand Down
4 changes: 1 addition & 3 deletions src/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ const Home: FC = () => {
}, [t, lightningState, bitcoin, bitcoin_msg, lightning_msg]);

const isLnImplSelected =
implementation !== null &&
implementation !== "" &&
implementation !== "NONE";
implementation === "LND_GRPC" || implementation === "CLN_GRPC";

const getTransactions = useCallback(async () => {
if (!isLnImplSelected || (lightningState && lightningState !== "done")) {
Expand Down

0 comments on commit 0346a5f

Please sign in to comment.