forked from MutinyWallet/mutiny-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwaila.ts
More file actions
75 lines (68 loc) · 2.07 KB
/
Copy pathwaila.ts
File metadata and controls
75 lines (68 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import initWaila, { PaymentParams } from "@mutinywallet/waila-wasm";
import { Result } from "~/utils";
// Make sure we've initialzied waila before we try to use it
await initWaila();
export type ParsedParams = {
original: string;
address?: string;
payjoin_enabled?: boolean;
invoice?: string;
amount_sats?: bigint;
network?: string;
memo?: string;
privateTag?: string;
node_pubkey?: string;
lnurl?: string;
lightning_address?: string;
nostr_wallet_auth?: string;
fedimint_invite?: string;
is_lnurl_auth?: boolean;
contact_id?: string;
cashu_token?: string;
};
export function toParsedParams(
str: string,
ourNetwork: string
): Result<ParsedParams> {
let params;
try {
params = new PaymentParams(str || "");
} catch (e) {
console.error(e);
return { ok: false, error: new Error("Invalid payment request") };
}
// If WAILA doesn't return a network we should default to our own
// If the networks is testnet and we're on signet we should use signet
const network = !params.network
? ourNetwork
: params.network === "testnet" && ourNetwork === "signet"
? "signet"
: params.network;
if (network !== ourNetwork) {
return {
ok: false,
error: new Error(
`Destination is for ${params.network} but you're on ${ourNetwork}`
)
};
}
return {
ok: true,
value: {
original: str,
address: params.address,
payjoin_enabled: params.payjoin_supported,
invoice: params.invoice,
amount_sats: params.amount_sats,
network,
memo: params.memo,
node_pubkey: params.node_pubkey,
lnurl: params.lnurl,
lightning_address: params.lightning_address,
nostr_wallet_auth: params.nostr_wallet_auth,
is_lnurl_auth: params.is_lnurl_auth,
fedimint_invite: params.fedimint_invite_code,
cashu_token: params.cashu_token
}
};
}