stacker.news/components
ekzyis 371e7417ce
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 17:51:46 -05:00
..
nav Wallet definitions with uniform interface (#1243) 2024-07-20 17:51:46 -05:00
accordian-item.js Close related section (#1207) 2024-05-31 10:20:52 -05:00
action-dropdown.js Use module path aliases (#938) 2024-03-19 19:37:31 -05:00
action-tooltip.js fix action tooltip container 2024-07-12 17:34:46 -05:00
adv-post-form.js more accordian show states 2024-05-13 10:14:35 -05:00
adv-post-form.module.css fix height of foward percent on validation err 2023-09-12 17:04:49 -05:00
autowithdraw-shared.js Wallet definitions with uniform interface (#1243) 2024-07-20 17:51:46 -05:00
avatar.js Use module path aliases (#938) 2024-03-19 19:37:31 -05:00
banners.js Use <Alert> for auth banner in /settings (#1238) 2024-06-12 18:16:54 -05:00
banners.module.css Add new visitor welcome banner (#418) 2023-09-11 16:29:45 -05:00
block-height.js add halving to price carousel 2024-04-16 17:58:26 -05:00
bolt11-info.js add lnc attached wallet (#1104) 2024-04-26 21:22:30 -05:00
bookmark.js Toast (#431) 2023-08-25 18:21:51 -05:00
bounty-form.js backend payment optimism (#1195) 2024-07-01 12:02:29 -05:00
cancel-button.js make fee button less of a hack 2023-11-10 18:18:10 -06:00
chain-fee.js env vars for polling intervals (#1038) 2024-04-08 09:13:12 -05:00
charts-skeletons.js remove duplicative styles 2024-03-25 15:35:32 -04:00
charts.js Referral Rewards (#1262) 2024-07-10 19:23:05 -05:00
comment-edit.js backend payment optimism (#1195) 2024-07-01 12:02:29 -05:00
comment.js fix item spacing 2024-07-11 16:58:55 -05:00
comment.module.css refine comment padding 2024-07-12 15:18:13 -05:00
comments.js backend payment optimism (#1195) 2024-07-01 12:02:29 -05:00
countdown.js backend payment optimism (#1195) 2024-07-01 12:02:29 -05:00
dark-mode.js dark-mode needs to block block 2023-08-04 20:45:12 -05:00
delete.js backend payment optimism (#1195) 2024-07-01 12:02:29 -05:00
discussion-form.js backend payment optimism (#1195) 2024-07-01 12:02:29 -05:00
dont-link-this.js backend payment optimism (#1195) 2024-07-01 12:02:29 -05:00
error-boundary.js Use module path aliases (#938) 2024-03-19 19:37:31 -05:00
fee-button.js backend payment optimism (#1195) 2024-07-01 12:02:29 -05:00
fee-button.module.css small receipt styling 2023-11-10 09:22:14 -06:00
footer-rewards.js env vars for polling intervals (#1038) 2024-04-08 09:13:12 -05:00
footer.js Use njump.me for nostr links (#1120) 2024-04-28 17:25:25 -05:00
footer.module.css Bottom nav uses fixed position to fix firefox bug (#1011) 2024-04-04 18:50:52 -05:00
form.js Wallet definitions with uniform interface (#1243) 2024-07-20 17:51:46 -05:00
form.module.css backend payment optimism (#1195) 2024-07-01 12:02:29 -05:00
hat.js Allow SN users to edit special items forever (#1204) 2024-06-03 11:26:19 -05:00
header.module.css refine hiding bottom navbar when virtual keyboard opens 2024-03-28 18:18:44 -05:00
hidden-wallet-summary.js fix hidden wallet balance layout shift 2024-04-17 17:22:17 -05:00
hoverable-popover.js attempt fix for popovers 2024-07-12 10:15:57 -05:00
hoverable-popover.module.css Item popover (#1162) 2024-05-15 12:05:50 -05:00
image.js Fix images from media domain not loaded if imgproxyOnly enabled (#1153) 2024-05-06 16:39:20 -05:00
info.js Use module path aliases (#938) 2024-03-19 19:37:31 -05:00
invite.js add NEXT_PUBLIC_URL 2024-04-08 17:54:39 -05:00
invoice-status.js backend payment optimism (#1195) 2024-07-01 12:02:29 -05:00
invoice.js Wallet definitions with uniform interface (#1243) 2024-07-20 17:51:46 -05:00
invoice.module.css ready for invoices 2021-05-06 16:15:22 -05:00
item-act.js don't toast on invoice cancellation 2024-07-09 13:10:41 -05:00
item-full.js Handle Peertube Embeds (#1223) 2024-06-20 11:28:25 -05:00
item-info.js don't toast on invoice cancellation 2024-07-09 13:10:41 -05:00
item-job.js Use module path aliases (#938) 2024-03-19 19:37:31 -05:00
item-popover.js Item popover (#1162) 2024-05-15 12:05:50 -05:00
item.js fix item spacing 2024-07-11 16:58:55 -05:00
item.module.css refine comment padding 2024-07-12 15:18:13 -05:00
items.js fix item spacing 2024-07-11 16:58:55 -05:00
items.module.css working search 2022-01-27 13:18:48 -06:00
job-form.js backend payment optimism (#1195) 2024-07-01 12:02:29 -05:00
layout.js navigation -> nav 2024-03-26 19:49:10 -05:00
layout.module.css more spacing consistency 2024-03-27 14:04:04 -05:00
lightning-auth.js env vars for polling intervals (#1038) 2024-04-08 09:13:12 -05:00
lightning-auth.module.css Notifications with nostr info (#368) 2023-08-08 13:19:31 -05:00
lightning.js Use module path aliases (#938) 2024-03-19 19:37:31 -05:00
link-form.js backend payment optimism (#1195) 2024-07-01 12:02:29 -05:00
link-to-context.js turn #1063 logic into a component for use in all comment lists 2024-04-15 16:23:26 -05:00
link-to-context.module.css fix item spacing 2024-07-11 16:58:55 -05:00
log-message.js CLN autowithdrawal (#1042) 2024-04-14 17:34:21 -05:00
log-message.module.css Wallet Logs (#994) 2024-04-03 17:27:21 -05:00
logger.js Wallet definitions with uniform interface (#1243) 2024-07-20 17:51:46 -05:00
login-button.js Use module path aliases (#938) 2024-03-19 19:37:31 -05:00
login.js Use module path aliases (#938) 2024-03-19 19:37:31 -05:00
login.module.css more invite work 2021-10-15 13:05:34 -05:00
long-pressable.js Fix first zap when modal closed (#771) (#1055) 2024-04-12 18:37:04 -05:00
me.js env vars for polling intervals (#1038) 2024-04-08 09:13:12 -05:00
modal.js backend payment optimism (#1195) 2024-07-01 12:02:29 -05:00
more-footer.js fix item spacing 2024-07-11 16:58:55 -05:00
mute.js honor mutes when sending push notifications (#1145) 2024-05-12 13:55:56 -05:00
nostr-auth.js Use module path aliases (#938) 2024-03-19 19:37:31 -05:00
notifications.js improve notification header styling 2024-07-12 10:38:47 -05:00
notifications.module.css make sure all notifications have the same padding 2024-07-19 14:47:12 -05:00
page-loading.js Use module path aliases (#938) 2024-03-19 19:37:31 -05:00
past-bounties.js upgrade react-bootstrap 2023-07-24 13:53:53 -05:00
pay-bounty.js don't toast on invoice cancellation 2024-07-09 13:10:41 -05:00
pay-bounty.module.css upgrade react-bootstrap 2023-07-24 13:53:53 -05:00
payer-data.js LUD-18 Service Support (#518) 2023-10-03 14:35:53 -05:00
payment.js Wallet definitions with uniform interface (#1243) 2024-07-20 17:51:46 -05:00
poll-form.js backend payment optimism (#1195) 2024-07-01 12:02:29 -05:00
poll.js don't toast on invoice cancellation 2024-07-09 13:10:41 -05:00
poll.module.css increase poll choice length to 40 chars 2023-09-28 16:52:11 -05:00
post.js enhance navigation 2024-03-26 18:36:31 -05:00
price.js [1124] - Use Mempool For Fee Rate (#1171) 2024-05-15 10:26:49 -05:00
qr.js Wallet definitions with uniform interface (#1243) 2024-07-20 17:51:46 -05:00
recent-header.js fix item spacing 2024-07-11 16:58:55 -05:00
related.js Use module path aliases (#938) 2024-03-19 19:37:31 -05:00
reply.js refine comment padding 2024-07-12 15:18:13 -05:00
reply.module.css refine comment padding 2024-07-12 15:18:13 -05:00
root.js improve comment performance 2023-05-06 16:51:17 -05:00
search.js fix: custom calendar dark theme (#1123) 2024-05-11 20:32:44 -05:00
search.module.css search all territories by default + more intuitive search filters 2024-03-26 18:37:40 -05:00
seo.js Use module path aliases (#938) 2024-03-19 19:37:31 -05:00
serviceworker.js Wallet Logs (#994) 2024-04-03 17:27:21 -05:00
share.js dont use broken navigator.share on desktop safari 2024-06-14 13:44:36 -05:00
snl.js Use module path aliases (#938) 2024-03-19 19:37:31 -05:00
snow.js Use module path aliases (#938) 2024-03-19 19:37:31 -05:00
sub-select.js env vars for polling intervals (#1038) 2024-04-08 09:13:12 -05:00
sub-select.module.css enhance navigation 2024-03-26 18:36:31 -05:00
subscribe.js Toast (#431) 2023-08-25 18:21:51 -05:00
subscribeUser.js honor mutes when sending push notifications (#1145) 2024-05-12 13:55:56 -05:00
table-of-contents.js Use module path aliases (#938) 2024-03-19 19:37:31 -05:00
territory-form.js don't toast on invoice cancellation 2024-07-09 13:10:41 -05:00
territory-header.js fix item spacing 2024-07-11 16:58:55 -05:00
territory-list.js Use module path aliases (#938) 2024-03-19 19:37:31 -05:00
territory-payment-due.js don't toast on invoice cancellation 2024-07-09 13:10:41 -05:00
territory-transfer.js Use module path aliases (#938) 2024-03-19 19:37:31 -05:00
text.js don't import css into /lib 2024-06-25 17:18:21 -05:00
text.module.css Added support for <sub> <sup> in markdown (#1215) 2024-06-25 14:23:18 -05:00
toast.js hide overflow of toasts 2024-07-09 11:46:38 -05:00
toast.module.css backend payment optimism (#1195) 2024-07-01 12:02:29 -05:00
top-header.js fix item spacing 2024-07-11 16:58:55 -05:00
upvote.js backend payment optimism (#1195) 2024-07-01 12:02:29 -05:00
upvote.module.css refine comment padding 2024-07-12 15:18:13 -05:00
usage-header.js fix: custom calendar dark theme (#1123) 2024-05-11 20:32:44 -05:00
use-crossposter.js Nostr crossposting backlink + content fix (#1251) 2024-07-03 10:11:24 -05:00
use-data.js remove list jitter by initially preferring ssr 2023-08-06 13:04:25 -05:00
use-debounce-callback.js remove unused debounce callback deps 2023-10-06 16:34:16 -05:00
use-has-new-notes.js env vars for polling intervals (#1038) 2024-04-08 09:13:12 -05:00
use-item-submit.js don't toast on invoice cancellation 2024-07-09 13:10:41 -05:00
use-local-state.js Wallet definitions with uniform interface (#1243) 2024-07-20 17:51:46 -05:00
use-no-initial-effect.js reuse debounce hook more places 2023-10-06 15:01:51 -05:00
use-paid-mutation.js Wallet definitions with uniform interface (#1243) 2024-07-20 17:51:46 -05:00
use-quote-reply.js Use module path aliases (#938) 2024-03-19 19:37:31 -05:00
user-header.js backend payment optimism (#1195) 2024-07-01 12:02:29 -05:00
user-header.module.css Don't hide self in top even if hidden (#905) 2024-03-13 19:26:59 -05:00
user-list.js fix missing embellishment in rewards leaderboard 2024-05-06 11:41:02 -05:00
user-popover.js Item popover (#1162) 2024-05-15 12:05:50 -05:00
wallet-buttonbar.js Wallet definitions with uniform interface (#1243) 2024-07-20 17:51:46 -05:00
wallet-card.js Wallet definitions with uniform interface (#1243) 2024-07-20 17:51:46 -05:00
wallet-logger.js Wallet definitions with uniform interface (#1243) 2024-07-20 17:51:46 -05:00