2021-10-26 20:49:37 +00:00
|
|
|
import { gql } from '@apollo/client'
|
2023-02-04 00:08:08 +00:00
|
|
|
import { ITEM_FULL_FIELDS } from './items'
|
2021-10-26 20:49:37 +00:00
|
|
|
|
2024-07-01 17:02:29 +00:00
|
|
|
export const INVOICE_FIELDS = gql`
|
|
|
|
fragment InvoiceFields on Invoice {
|
|
|
|
id
|
|
|
|
hash
|
|
|
|
hmac
|
|
|
|
bolt11
|
|
|
|
satsRequested
|
|
|
|
satsReceived
|
|
|
|
cancelled
|
|
|
|
confirmedAt
|
|
|
|
expiresAt
|
|
|
|
nostr
|
|
|
|
isHeld
|
|
|
|
comment
|
|
|
|
lud18Data
|
|
|
|
actionState
|
|
|
|
actionType
|
2024-07-04 17:30:42 +00:00
|
|
|
actionError
|
2024-10-02 20:03:30 +00:00
|
|
|
confirmedPreimage
|
2024-07-01 17:02:29 +00:00
|
|
|
}`
|
|
|
|
|
|
|
|
export const INVOICE_FULL = gql`
|
|
|
|
${ITEM_FULL_FIELDS}
|
|
|
|
${INVOICE_FIELDS}
|
|
|
|
|
|
|
|
query Invoice($id: ID!) {
|
|
|
|
invoice(id: $id) {
|
|
|
|
...InvoiceFields
|
|
|
|
item {
|
|
|
|
...ItemFullFields
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`
|
|
|
|
|
2021-10-26 20:49:37 +00:00
|
|
|
export const INVOICE = gql`
|
2024-07-01 17:02:29 +00:00
|
|
|
${INVOICE_FIELDS}
|
|
|
|
|
2021-10-26 20:49:37 +00:00
|
|
|
query Invoice($id: ID!) {
|
|
|
|
invoice(id: $id) {
|
2024-07-01 17:02:29 +00:00
|
|
|
...InvoiceFields
|
2021-10-26 20:49:37 +00:00
|
|
|
}
|
|
|
|
}`
|
|
|
|
|
|
|
|
export const WITHDRAWL = gql`
|
|
|
|
query Withdrawl($id: ID!) {
|
|
|
|
withdrawl(id: $id) {
|
|
|
|
id
|
2023-11-09 17:50:43 +00:00
|
|
|
createdAt
|
2021-10-26 20:49:37 +00:00
|
|
|
bolt11
|
|
|
|
satsPaid
|
|
|
|
satsFeePaying
|
|
|
|
satsFeePaid
|
|
|
|
status
|
2024-01-07 17:00:24 +00:00
|
|
|
autoWithdraw
|
2024-04-26 00:33:24 +00:00
|
|
|
preimage
|
2021-10-26 20:49:37 +00:00
|
|
|
}
|
|
|
|
}`
|
2021-10-28 19:59:53 +00:00
|
|
|
|
2021-12-15 16:50:11 +00:00
|
|
|
export const WALLET_HISTORY = gql`
|
2023-02-04 00:08:08 +00:00
|
|
|
${ITEM_FULL_FIELDS}
|
2021-12-16 20:02:17 +00:00
|
|
|
|
2021-12-16 17:27:12 +00:00
|
|
|
query WalletHistory($cursor: String, $inc: String) {
|
|
|
|
walletHistory(cursor: $cursor, inc: $inc) {
|
2021-12-15 16:50:11 +00:00
|
|
|
facts {
|
|
|
|
id
|
2023-11-09 17:50:43 +00:00
|
|
|
bolt11
|
2024-01-07 17:00:24 +00:00
|
|
|
autoWithdraw
|
2021-12-15 16:50:11 +00:00
|
|
|
type
|
|
|
|
createdAt
|
2022-11-15 20:51:55 +00:00
|
|
|
sats
|
2021-12-15 16:50:11 +00:00
|
|
|
status
|
|
|
|
type
|
|
|
|
description
|
2023-09-24 01:14:49 +00:00
|
|
|
invoiceComment
|
2023-10-03 19:35:53 +00:00
|
|
|
invoicePayerData
|
2023-11-21 23:32:22 +00:00
|
|
|
subName
|
2021-12-16 20:02:17 +00:00
|
|
|
item {
|
2023-02-04 00:08:08 +00:00
|
|
|
...ItemFullFields
|
2021-12-16 20:02:17 +00:00
|
|
|
}
|
2021-12-15 16:50:11 +00:00
|
|
|
}
|
|
|
|
cursor
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2021-10-28 19:59:53 +00:00
|
|
|
export const CREATE_WITHDRAWL = gql`
|
|
|
|
mutation createWithdrawl($invoice: String!, $maxFee: Int!) {
|
|
|
|
createWithdrawl(invoice: $invoice, maxFee: $maxFee) {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}`
|
2022-01-23 17:21:55 +00:00
|
|
|
|
|
|
|
export const SEND_TO_LNADDR = gql`
|
2023-10-03 23:22:56 +00:00
|
|
|
mutation sendToLnAddr($addr: String!, $amount: Int!, $maxFee: Int!, $comment: String, $identifier: Boolean, $name: String, $email: String) {
|
|
|
|
sendToLnAddr(addr: $addr, amount: $amount, maxFee: $maxFee, comment: $comment, identifier: $identifier, name: $name, email: $email) {
|
2022-01-23 17:21:55 +00:00
|
|
|
id
|
|
|
|
}
|
|
|
|
}`
|
2024-02-13 19:17:56 +00:00
|
|
|
|
|
|
|
export const REMOVE_WALLET =
|
|
|
|
gql`
|
|
|
|
mutation removeWallet($id: ID!) {
|
|
|
|
removeWallet(id: $id)
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2024-08-18 16:32:25 +00:00
|
|
|
// XXX [WALLET] this needs to be updated if another server wallet is added
|
2024-02-13 19:17:56 +00:00
|
|
|
export const WALLET = gql`
|
|
|
|
query Wallet($id: ID!) {
|
|
|
|
wallet(id: $id) {
|
|
|
|
id
|
|
|
|
createdAt
|
|
|
|
priority
|
|
|
|
type
|
|
|
|
wallet {
|
|
|
|
__typename
|
2024-08-18 16:32:25 +00:00
|
|
|
... on WalletLightningAddress {
|
2024-02-13 19:17:56 +00:00
|
|
|
address
|
|
|
|
}
|
2024-08-19 22:41:52 +00:00
|
|
|
... on WalletLnd {
|
2024-02-13 19:17:56 +00:00
|
|
|
socket
|
|
|
|
macaroon
|
|
|
|
cert
|
|
|
|
}
|
2024-08-19 22:41:52 +00:00
|
|
|
... on WalletCln {
|
2024-04-14 22:34:21 +00:00
|
|
|
socket
|
|
|
|
rune
|
|
|
|
cert
|
|
|
|
}
|
2024-08-19 22:41:52 +00:00
|
|
|
... on WalletLnbits {
|
2024-08-12 22:23:39 +00:00
|
|
|
url
|
|
|
|
invoiceKey
|
|
|
|
}
|
2024-08-21 15:13:27 +00:00
|
|
|
... on WalletNwc {
|
|
|
|
nwcUrlRecv
|
|
|
|
}
|
2024-08-26 23:20:45 +00:00
|
|
|
... on WalletPhoenixd {
|
|
|
|
url
|
|
|
|
secondaryPassword
|
|
|
|
}
|
2024-02-13 19:17:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2024-08-18 16:32:25 +00:00
|
|
|
// XXX [WALLET] this needs to be updated if another server wallet is added
|
2024-02-13 19:17:56 +00:00
|
|
|
export const WALLET_BY_TYPE = gql`
|
|
|
|
query WalletByType($type: String!) {
|
|
|
|
walletByType(type: $type) {
|
|
|
|
id
|
|
|
|
createdAt
|
Wallet definitions with uniform interface (#1243)
* wip: Use uniform interface for wallets
* Fix import error
* Update wallet logging + other stuff
* add canPay and canSend to wallet definition
* rename 'default payment method' to 'enabled' and add enable + disable method
* Set canPay, canReceive in useWallet
* Enable wallet if just configured
* Don't pass logger to sendPayment
* Add logging to attach & detach
* Add schema to wallet def
* Add NWC wallet
* Fix unused isDefault saved in config
* Fix enableWallet
* wrong storage key was used
* broke if wallets with no configs existed
* Run validation during save
* Use INFO level for 'wallet disabled' message
* Pass config with spread operator
* Support help, optional, hint in wallet fields
* wip: Add LNC
* Fix 20s page load for /settings/wallets.json?nodata=true
For some reason, if nodata is passed (which is the case if going back), the page takes 20s to load.
* Fix extremely slow page load for LNC import
I noticed that the combination of
```
import { Form, PasswordInput, SubmitButton } from '@/components/form'
```
in components/wallet/lnc.js and the dynamic import via `await import` in components/wallet/index.js caused extremely slow page loads.
* Use normal imports
* Revert "Fix 20s page load for /settings/wallets.json?nodata=true"
This reverts commit deb476b3a966569fefcfdf4082d6b64f90fbd0a2.
Not using the dynamic import for LNC fixed the slow page load with ?nodata=true.
* Remove follow and show recent logs first
* Fix position of log start marker
* Add FIXMEs for LNC
I can't get LNC to connect. It just hangs forever on lnc.connect(). See FIXMEs.
* Remove logger.error since already handled in useWallet
* Don't require destructuring to pass props to input
* wip: Add LND autowithdrawals
* receiving wallets need to export 'server' object field
* don't print macaroon error stack
* fix missing wallet logs order update
* mark autowithdrawl settings as required
* fix server wallet logs deletion
* remove canPay and canReceive since it was confusing where it is available
TODO
* also use numeric priority for sending wallets to be consistent with how status for receiving wallets is determined
* define createInvoice function in wallet definition
* consistent wallet logs: sending wallets use 'wallet attached'+'wallet enabled/disabled' whereas receiving wallets use 'wallet created/updated'
* see FIXMEs
* Fix TypeError
* Fix sendPayment called with empty config
* removed useEffect such that config is available on first render
* fix hydration error using dynamic import without SSR
* Fix confusing UX around enabled
* Remove FIXMEs
Rebase on master seemed to have fixed these, weird
* Use same error format in toast and wallet log
* Fix usage of conditional hooks in useConfig
* Fix isConfigured
* Fix delete wallet logs on server
* Fix wallet logs refetch
onError does not exist on client.mutate
* Fix TypeError in isConfigured if no enabled wallet found
* Only include local/server config if required
* Fix another hydration error
* Fix server config not updated after save or detach
* Also use 'enabled' for server wallets
* Fix wallet logs not updated after server delete
* Consistent logs between local and server wallets
* 'wallet attached' on create
* 'wallet updated' on config updates
* 'wallet enabled' and 'wallet disabled' if checkbox changed
* 'wallet detached' on delete
* Also enable server wallets on create
* Disable checkbox if not configured yet
* Move all validation schema into lib/validate
* Implement drag & drop w/o persistence
* Use dynamic import for WalletCard
This fixes a lot of issues with hydration
* Save order as priority
* Fix autowithdrawSettings not applied
Form requires config in flat format but mutation requires autowithdraw settings in a separate 'settings' field.
I have decided that config will be in flat form format. It will be transformed into mutation format during save.
* Save dedicated enabled flag for server wallets
* wallet table now contains boolean column 'enabled'
* 'priority' is now a number everywhere
* use consistent order between how autowithdrawals are attempted and server wallets cards
* Fix onCanceled missing
* Fix typo
* Fix noisy changes in lib/validate
I moved the schema for lnbits, nwc and lnc out of lib/validate only to put them back in there later.
This commit should make the changeset cleaner by removing noise.
* Split arguments into [value,] config, context
* Run lnbits url.replace in validate and sendPayment
* Remove unnecessary WALLETS_QUERY
* Generate wallet mutation from fields
* Generate wallet resolver from fields
* Fix import inconsistency between app and worker
* Use wallet.createInvoice for autowithdrawals
* Fix success autowithdrawal log
* Fix wallet security banner shown for server wallets
* Add autowithdrawal to lightning address
* Add optional wallet short name for logging
* Fix draggable
* Fix autowithdraw loop
* Add missing hints
* Add CLN autowithdrawal
* Detach wallets and delete logs on logout
* Remove Wallet in lib/constants
* Use inject function for resolvers and typeDefs
* Fix priority ignored when fetching enabled wallet
* Fix draggable false on first page load due to SSR
* Use touches instead of dnd on mobile
Browsers don't support drag events for touch devices.
To have a consistent implementation for desktop and mobile, we would need to use mousedown/touchstart, mouseup/touchend and mousemove/touchmove.
For now, this commit makes changing the order possible on touch devices with simple touches.
* Fix duplicate CLN error
* Fix autowithdraw priority order
* Fix error per invalid bip39 word
* Update LNC code
* remove LNC FIXMEs
Mhh, I guess the TURN server was down or something? It now magically works. Or maybe it only works once per mnemonic?
* also removed the lnc.lnd.lightning.getInfo() call since we don't ask and need permission for this RPC for payments.
* setting a password does not work though. It fails with 'The password provided is not valid' which is triggered at https://github.com/lightninglabs/lnc-web/blob/main/lib/util/credentialStore.ts#L81.
* Fix order if wallet with no priority exists
* Use common sort
* Add link to lnbits.com
* Add example wallet def
* Remove TODOs
TODO in components/wallet-logger.js was handled.
I don't see a need for the TODO in lib/wallet.js anymore. This function will only be called with the wallet of type LIGHTNING_ADDRESS anyway.
* Remove console.log
* Toast priority save errors
* Fix leaking relay connections
* Remove 'tor or clearnet' hint for LN addresses
* Remove React dependency from wallet definitions
* Generate resolver name from walletField
* Move wallets into top level directory wallet/
* Put wallets into own folder
* Fix generateMutation
* remove resolverName property from wallet defs
* move function into lib/wallet
* use function in generateMutation on client to fix wrongly generated mutation
* Separate client and server imports by files
* wallets now consist of an index.js, a client.js and a server.js file
* client.js is imported on the client and contains the client portion
* server.js is imported on the server and contains the server porition
* both reexport index.js so everything in index.js can be shared by client and server
* every wallet contains a client.js file since they are all imported on the client to show the cards
* client.js of every wallet is reexported as an array in wallets/client.js
* server.js of every wallet is reexported as an array in wallets/server.js
FIXME: for some reason, worker does not properly import the default export of wallets/server.js
* Fix worker import of wallets/server
* Fix wallet.server usage
* I removed wallet.server in a previous commit
* the client couldn't determine which wallet was stored on the server since all server specific fields were set in server.js
* walletType and walletField are now set in index.js
* walletType is now used to determine if a wallet is stored on the server
* also included some formatting changes
* Fix w.default usage
Since package.json with { "type": "module" } was added, this is no longer needed.
* Fix id access in walletPrioritySort
* Fix autowithdrawal error log
* Generate validation schema for LNbits
* Generate validation schema for NWC
* Rename to torAllowed
* Generate validation schema for LNC
* Generate validation schema for LND
* Generate validation schema for LnAddr
* Remove stringTypes
* Generate validation schema for CLN
* Make clear that message belongs to test
* validate.message was used in tandem with validate.test
* it might be confused as the message if the validation for validate.type failed
* now validate.test can be a function or an object of { test, message } shape which matches Yup.test
* Remove validate.schema as a trap door
* make lnc work
* Return null if no wallet was found
* Revert code around schema generation
* Transform autowithdrawSchemaMembers into an object
* Rename schema to yupSchema
* Fix missing required for LNbits adminKey
* Support formik form-level validation
* Fix missing addWalletLog import
* Fix missing space after =
* fix merge conflict resolution mistake
* remove non-custodial* badges
* create guides for attaching wallets in sndev
* Use built-in formik validation or Yup schema but not both
* Rename: validate -> testConnectClient, testConnect -> testConnectServer
* make lnaddr autowithdraw work in dev
* move ATTACH docs to ./wallets and add lnaddr doc
* Fix missing rename: yupSchema -> fieldValidation
* Remove unused context
* Add documentation how to add wallets
---------
Co-authored-by: keyan <keyan.kousha+huumn@gmail.com>
Co-authored-by: Keyan <34140557+huumn@users.noreply.github.com>
2024-07-20 22:51:46 +00:00
|
|
|
enabled
|
2024-02-13 19:17:56 +00:00
|
|
|
priority
|
|
|
|
type
|
|
|
|
wallet {
|
|
|
|
__typename
|
2024-08-18 16:32:25 +00:00
|
|
|
... on WalletLightningAddress {
|
2024-02-13 19:17:56 +00:00
|
|
|
address
|
|
|
|
}
|
2024-08-19 22:41:52 +00:00
|
|
|
... on WalletLnd {
|
2024-02-13 19:17:56 +00:00
|
|
|
socket
|
|
|
|
macaroon
|
|
|
|
cert
|
|
|
|
}
|
2024-08-19 22:41:52 +00:00
|
|
|
... on WalletCln {
|
2024-04-14 22:34:21 +00:00
|
|
|
socket
|
|
|
|
rune
|
|
|
|
cert
|
|
|
|
}
|
2024-08-19 22:41:52 +00:00
|
|
|
... on WalletLnbits {
|
2024-08-12 22:23:39 +00:00
|
|
|
url
|
|
|
|
invoiceKey
|
|
|
|
}
|
2024-08-21 15:13:27 +00:00
|
|
|
... on WalletNwc {
|
|
|
|
nwcUrlRecv
|
|
|
|
}
|
2024-08-26 23:20:45 +00:00
|
|
|
... on WalletPhoenixd {
|
|
|
|
url
|
|
|
|
secondaryPassword
|
|
|
|
}
|
2024-02-13 19:17:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
export const WALLETS = gql`
|
|
|
|
query Wallets {
|
2024-10-14 15:49:06 +00:00
|
|
|
wallets{
|
|
|
|
id
|
|
|
|
priority
|
|
|
|
type,
|
|
|
|
canSend,
|
|
|
|
canReceive
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2024-10-16 07:21:05 +00:00
|
|
|
export const BEST_WALLETS = gql`
|
|
|
|
query BestWallets {
|
|
|
|
wallets (includeSenders: true, includeReceivers: true, onlyEnabled: true, prioritySort: "asc") {
|
|
|
|
id
|
|
|
|
priority
|
|
|
|
type
|
|
|
|
updatedAt
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
2024-10-14 15:49:06 +00:00
|
|
|
export const BEST_SEND_WALLETS = gql`
|
2024-10-18 16:40:06 +00:00
|
|
|
query BestSendWallets {
|
2024-10-16 07:21:05 +00:00
|
|
|
wallets (includeSenders: true, includeReceivers: false, onlyEnabled: true, prioritySort: "asc") {
|
2024-02-13 19:17:56 +00:00
|
|
|
id
|
|
|
|
priority
|
|
|
|
type
|
2024-10-15 21:00:01 +00:00
|
|
|
updatedAt
|
2024-02-13 19:17:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
Wallet Logs (#994)
* nwc wallet logs
* persist logs in IndexedDB
* Potential fix for empty error message
* load logs limited to 5m ago from IDB
* load logs from past via query param
* Add 5m, 1h, 6h links for earlier logs
* Show end of log
* Clamp to logStart
* Add log.module.css
* Remove TODO about persistence
* Use table for logs
* <table> fixes bad format with fixed width and message overflow into start of next row
* also using ---start of log--- instead of ---end of log--- now
* removed time string in header nav
* Rename .header to .logNav
* Simply load all logs and remove navigation
I realized the code for navigation was most likely premature optimization which even resulted in worse UX:
Using the buttons to load logs from 5m, 1h, 6h ago sometimes meant that nothing happened at all since there were no logs from 5m, 1h, 6h ago.
That's why I added a time string as "start of logs" so it's at least visible that it changed but that looked bad so I removed it.
But all of this was not necessary: I can simply load all logs at once and then the user can scroll around however they like.
I was worried that it would be bad for performance to load all logs at once since we might store a lot of logs but as mentioned, that's probably premature optimization.
WHEN a lot of logs are stored AND this becomes a problem (What problem even? Slow page load?), THEN we can think about this.
If page load ever becomes slow because of loading logs, we could probably simply not load the logs at page load but only when /wallet/logs is visited.
But for now, this works fine.
* Add follow checkbox
* Create WalletLogs component
* Embed wallet logs
* Remove test error
* Fix level padding
* Add LNbits logs
* Add logs for attaching LND and lnAddr
* Use err.message || err.toString?.() consistently
* Autowithdrawal logs
* Use details from LND error
* Don't log test invoice individually
* Also refetch logs on error
* Remove obsolete and annoying toasts
* Replace scrollIntoView with scroll
* Use constant embedded max-height
* Fix missing width: 100% for embedded logs
* Show full payment hash and preimage in logs
* Also parse details from LND errors on autowithdrawal failures
* Remove TODO
* Fix accidental removal of wss:// check
* Fix alignment of start marker and show empty if empty
* Fix sendPayment loop
* Split context in two
2024-04-03 22:27:21 +00:00
|
|
|
|
|
|
|
export const WALLET_LOGS = gql`
|
2024-10-04 11:59:32 +00:00
|
|
|
query WalletLogs($type: String, $from: String, $to: String, $cursor: String) {
|
|
|
|
walletLogs(type: $type, from: $from, to: $to, cursor: $cursor) {
|
|
|
|
cursor
|
|
|
|
entries {
|
|
|
|
id
|
|
|
|
createdAt
|
|
|
|
wallet
|
|
|
|
level
|
|
|
|
message
|
|
|
|
}
|
Wallet Logs (#994)
* nwc wallet logs
* persist logs in IndexedDB
* Potential fix for empty error message
* load logs limited to 5m ago from IDB
* load logs from past via query param
* Add 5m, 1h, 6h links for earlier logs
* Show end of log
* Clamp to logStart
* Add log.module.css
* Remove TODO about persistence
* Use table for logs
* <table> fixes bad format with fixed width and message overflow into start of next row
* also using ---start of log--- instead of ---end of log--- now
* removed time string in header nav
* Rename .header to .logNav
* Simply load all logs and remove navigation
I realized the code for navigation was most likely premature optimization which even resulted in worse UX:
Using the buttons to load logs from 5m, 1h, 6h ago sometimes meant that nothing happened at all since there were no logs from 5m, 1h, 6h ago.
That's why I added a time string as "start of logs" so it's at least visible that it changed but that looked bad so I removed it.
But all of this was not necessary: I can simply load all logs at once and then the user can scroll around however they like.
I was worried that it would be bad for performance to load all logs at once since we might store a lot of logs but as mentioned, that's probably premature optimization.
WHEN a lot of logs are stored AND this becomes a problem (What problem even? Slow page load?), THEN we can think about this.
If page load ever becomes slow because of loading logs, we could probably simply not load the logs at page load but only when /wallet/logs is visited.
But for now, this works fine.
* Add follow checkbox
* Create WalletLogs component
* Embed wallet logs
* Remove test error
* Fix level padding
* Add LNbits logs
* Add logs for attaching LND and lnAddr
* Use err.message || err.toString?.() consistently
* Autowithdrawal logs
* Use details from LND error
* Don't log test invoice individually
* Also refetch logs on error
* Remove obsolete and annoying toasts
* Replace scrollIntoView with scroll
* Use constant embedded max-height
* Fix missing width: 100% for embedded logs
* Show full payment hash and preimage in logs
* Also parse details from LND errors on autowithdrawal failures
* Remove TODO
* Fix accidental removal of wss:// check
* Fix alignment of start marker and show empty if empty
* Fix sendPayment loop
* Split context in two
2024-04-03 22:27:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|