ekzyis e46f4f01b2
Wallet flow (#2362)
* Wallet flow

* Prepopulate fields of complementary protocol

* Remove TODO about one mutation for save

We need to save protocols in separate mutations so we can use the wallet id returned by the first protocol save for the following protocol saves and save them all to the same wallet.

* Fix badges not updated on wallet delete

* Fix useProtocol call

* Fix lightning address save via prompt

* Don't pass share as attribute to DOM

* Fix useCallback dependency

* Progress numbers as SVGs

* Fix progress line margins

* Remove unused saveWallet arguments

* Update cache with settings response

* Fix line does not connect with number 1

* Don't reuse page nav arrows in form nav

* Fix missing SVG hover style

* Fix missing space in wallet save log message

* Reuse CSS from nav.module.css

* align buttons and their icons/text

* center form progress line

* increase top padding of form on smaller screens

* provide margin above button bar on settings form

---------

Co-authored-by: k00b <k00b@stacker.news>
2025-08-26 09:19:52 -05:00

272 lines
5.4 KiB
JavaScript

import { gql } from '@apollo/client'
const VAULT_ENTRY_FIELDS = gql`
fragment VaultEntryFields on VaultEntry {
id
iv
value
}
`
export const CLEAR_VAULT = gql`
mutation ClearVault {
clearVault
}
`
const WALLET_PROTOCOL_FIELDS = gql`
${VAULT_ENTRY_FIELDS}
# need to use field aliases because of https://github.com/graphql/graphql-js/issues/53
fragment WalletProtocolFields on WalletProtocol {
id
name
send
enabled
config {
__typename
... on WalletSendNWC {
id
encryptedUrl: url {
...VaultEntryFields
}
}
... on WalletSendLNbits {
id
url
encryptedApiKey: apiKey {
...VaultEntryFields
}
}
... on WalletSendPhoenixd {
id
url
encryptedApiKey: apiKey {
...VaultEntryFields
}
}
... on WalletSendBlink {
id
encryptedCurrency: currency {
...VaultEntryFields
}
encryptedApiKey: apiKey {
...VaultEntryFields
}
}
... on WalletSendWebLN {
id
}
... on WalletSendLNC {
id
encryptedPairingPhrase: pairingPhrase {
...VaultEntryFields
}
encryptedLocalKey: localKey {
...VaultEntryFields
}
encryptedRemoteKey: remoteKey {
...VaultEntryFields
}
encryptedServerHost: serverHost {
...VaultEntryFields
}
}
... on WalletRecvNWC {
id
url
}
... on WalletRecvLNbits {
id
url
apiKey
}
... on WalletRecvPhoenixd {
id
url
apiKey
}
... on WalletRecvBlink {
id
currency
apiKey
}
... on WalletRecvLightningAddress {
id
address
}
... on WalletRecvCLNRest {
id
socket
rune
cert
}
... on WalletRecvLNDGRPC {
id
socket
macaroon
cert
}
}
}
`
const WALLET_TEMPLATE_FIELDS = gql`
fragment WalletTemplateFields on WalletTemplate {
# need to use field alias because of https://github.com/graphql/graphql-js/issues/53
id: name
send
receive
protocols {
id
name
send
}
}
`
const USER_WALLET_FIELDS = gql`
${WALLET_PROTOCOL_FIELDS}
${WALLET_TEMPLATE_FIELDS}
fragment WalletFields on Wallet {
id
name
priority
send
receive
protocols {
...WalletProtocolFields
}
template {
...WalletTemplateFields
}
}
`
const WALLET_OR_TEMPLATE_FIELDS = gql`
${USER_WALLET_FIELDS}
${WALLET_TEMPLATE_FIELDS}
fragment WalletOrTemplateFields on WalletOrTemplate {
... on Wallet {
...WalletFields
}
... on WalletTemplate {
...WalletTemplateFields
}
}
`
export const WALLETS = gql`
${WALLET_OR_TEMPLATE_FIELDS}
query Wallets {
wallets {
...WalletOrTemplateFields
}
}
`
export const WALLET = gql`
${WALLET_OR_TEMPLATE_FIELDS}
query Wallet($id: ID, $name: String) {
wallet(id: $id, name: $name) {
...WalletOrTemplateFields
}
}
`
export const REMOVE_WALLET = gql`
mutation removeWallet($id: ID!) {
removeWallet(id: $id)
}
`
export const SET_WALLET_PRIORITIES = gql`
mutation SetWalletPriorities($priorities: [WalletPriorityUpdate!]!) {
setWalletPriorities(priorities: $priorities)
}
`
export const UPDATE_WALLET_ENCRYPTION = gql`
mutation UpdateWalletEncryption($keyHash: String!, $wallets: [WalletEncryptionUpdate!]!) {
updateWalletEncryption(keyHash: $keyHash, wallets: $wallets)
}
`
export const UPDATE_KEY_HASH = gql`
mutation UpdateKeyHash($keyHash: String!) {
updateKeyHash(keyHash: $keyHash)
}
`
export const RESET_WALLETS = gql`
mutation ResetWallets($newKeyHash: String!) {
resetWallets(newKeyHash: $newKeyHash)
}
`
export const DELETE_WALLET = gql`
mutation deleteWallet($id: ID!) {
deleteWallet(id: $id)
}`
export const DISABLE_PASSPHRASE_EXPORT = gql`
mutation DisablePassphraseExport {
disablePassphraseExport
}
`
export const WALLET_SETTINGS = gql`
query WalletSettings {
walletSettings {
receiveCreditsBelowSats
sendCreditsBelowSats
proxyReceive
autoWithdrawMaxFeePercent
autoWithdrawMaxFeeTotal
autoWithdrawThreshold
}
}
`
export const SET_WALLET_SETTINGS = gql`
mutation SetWalletSettings($settings: WalletSettingsInput!) {
setWalletSettings(settings: $settings) {
receiveCreditsBelowSats
sendCreditsBelowSats
proxyReceive
autoWithdrawMaxFeePercent
autoWithdrawMaxFeeTotal
autoWithdrawThreshold
}
}
`
export const ADD_WALLET_LOG = gql`
mutation AddWalletLog($protocolId: Int, $level: String!, $message: String!, $timestamp: Date!, $invoiceId: Int) {
addWalletLog(protocolId: $protocolId, level: $level, message: $message, timestamp: $timestamp, invoiceId: $invoiceId)
}
`
export const WALLET_LOGS = gql`
query WalletLogs($protocolId: Int, $cursor: String, $debug: Boolean) {
walletLogs(protocolId: $protocolId, cursor: $cursor, debug: $debug) {
entries {
id
level
message
createdAt
wallet {
name
}
context
}
cursor
}
}
`
export const DELETE_WALLET_LOGS = gql`
mutation DeleteWalletLogs($protocolId: Int, $debug: Boolean) {
deleteWalletLogs(protocolId: $protocolId, debug: $debug)
}
`