Commit Graph

31 Commits

Author SHA1 Message Date
Keyan 0b0e36e3cb
Monthly rewards (#890)
* show placeholder for hidden stackers in top

* top rewardability views

* make territory revenue idependent job

* monthly rewards and leaderboard on rewards pages

* fix earn reschedule

* add query for rewards leaderboard

* reduce likelihood of rewards racing with views

* fix earn and refine values views
2024-03-01 10:28:55 -06:00
Keyan ec4e1b5da7
LND autowithdraw (#806)
* wip

* wip

* improved validatation, test connection before save, code reuse

* worker send to lnd

* autowithdraw priority
2024-02-13 13:17:56 -06:00
keyan eb99fcef9e improve stat gathering 2024-01-19 15:19:26 -06:00
keyan 86e8350994 autowithdraw to lightning address 2024-01-11 13:10:07 -06:00
ekzyis 2151323c8d
Use LND subscriptions (#726)
* Use parallel invoice subscriptions

* Fix missing idempotency

* Log error

* Use cursor for invoice subscription

* Subscribe to outgoing payments for withdrawals

* Add TODO comments regarding migration to LND subscriptions

* Also use isPoll variable in checkInvoice

* Queue status check of pending withdrawals

* Use for loop to check pending withdrawals

* Reconnect to LND gRPC API on error

* Fix hash modified of applied migrations

* Separate wallet code from worker index

* refactor subscription code some more

* remove unnecessary subWrapper abstraction
* move all wallet related code into worker/wallet.js such that only a single import is needed in worker/index.js

* Migrate from polling to LND subscriptions

* Remove unnecessary reconnect code

* Add FIXME

* Add listener for HODL invoice updates

* Remove obsolete comment

* Update README

* Add job to cancel hodl invoice if expired

* Fix missing else

* small bug fixes and readability enhancements

* refine and add periodic redundant deposit/withdrawal checks

---------

Co-authored-by: ekzyis <ek@stacker.news>
Co-authored-by: Keyan <34140557+huumn@users.noreply.github.com>
Co-authored-by: keyan <keyan.kousha+huumn@gmail.com>
2024-01-08 16:37:58 -06:00
keyan a5e50821b7 gofac yourself 2023-12-14 11:30:51 -06:00
keyan 10203f565c territories 2023-12-04 21:34:06 -06:00
rleed d86d8b3bac
Provide option to clear withdrawal invoices (#591)
* add settings option

* add auto-drop worker

* add manual delete option

* add warning and note

* cleanup

* incorporate most review feedback

* add warning to settings option

* remove debugging tweaks and simplify

* refine auto delete bolt11s

* refine UI

---------

Co-authored-by: rleed <rleed1@pm.me>
Co-authored-by: Keyan <34140557+huumn@users.noreply.github.com>
2023-11-09 11:50:43 -06:00
ekzyis 8f590425dc
Image uploads (#576)
* Add icon to add images

* Open file explorer to select image

* Upload images to S3 on selection

* Show uploaded images below text input

* Link and remove image

* Fetch unsubmitted images from database

* Mark S3 images as submitted in imgproxy job

* Add margin-top

* Mark images as submitted on client after successful mutation

* Also delete objects in S3

* Allow items to have multiple uploads linked

* Overwrite old avatar

* Add fees for presigned URLs

* Use Github style upload

* removed upfront fees
* removed images provider since we no longer need to keep track of unsubmitted images on the client
* removed User.images resolver
* removed deleteImage mutation
* use Github style upload where it shows ![Uploading <filename>...]() first and then replaces that with ![<filename>](<url>) after successful upload

* Add Upload.paid boolean column

One item can have multiple images linked to it, but an image can also be used in multiple items (many-to-many relation).

Since we don't really care to which item an image is linked and vice versa, we just use a boolean column to mark if an image was already paid for.

This makes fee calculation easier since no JOINs are required.

* Add image fees during item creation/update

* we calculate image fees during item creation and update now
* function imageFees returns queries which deduct fees from user and mark images as paid + fees
* queries need to be run inside same transaction as item creation/update

* Allow anons to get presigned URLs

* Add comments regarding avatar upload

* Use megabytes in error message

* Remove unnecessary avatar check during image fees calculation

* Show image fees in frontend

* Also update image fees on blur

This makes sure that the images fees reflect the current state. For example, if an image was removed.

We could also add debounced requests.

* Show amount of unpaid images in receipt

* Fix fees in sats deducted from msats

* Fix algebraic order of fees

Spam fees must come immediately after the base fee since it multiplies the base fee.

* Fix image fees in edit receipt

* Fix stale fees shown

If we pay for an image and then want to edit the comment, the cache might return stale date; suggesting we didn't pay for the existing image yet.

* Add 0 base fee in edit receipt

* Remove 's' from 'image fees' in receipts

* Remove unnecessary async

* Remove 'Uploading <name>...' from text input on error

* Support upload of multiple files at once

* Add schedule to delete unused images

* Fix image fee display in receipts

* Use Drag and Drop API for image upload

* Remove dragOver style on drop

* Increase max upload size to 10MB to allow HQ camera pictures

* Fix free upload quota

* Fix stale image fees served

* Fix bad image fee return statements

* Fix multiplication with feesPerImage

* Fix NULL returned for size24h, sizeNow

* Remove unnecessary text field in query

* refactor: Unify <ImageUpload> and <Upload> component

* Add avatar cache busting using random query param

* Calculate image fee info in postgres function

* we now calculate image fee info in a postgres function which is much cleaner
* we use this function inside `create_item` and `update_item`: image fees are now deducted in the same transaction as creating/updating the item!
* reversed changes in `serializeInvoiceable`

* Fix line break in receipt

* Update upload limits

* Add comment about `e.target.value = null`

* Use debounce instead of onBlur to update image fees info

* Fix invoice amount

* Refactor avatar upload control flow

* Update image fees in onChange

* Fix rescheduling of other jobs

* also update schedule from every minute to every hour

* Add image fees in calling context

* keep item ids on uploads

* Fix incompatible onSubmit signature

* Revert "keep item ids on uploads"

This reverts commit 4688962abc.

* many2many item uploads

* pretty subdomain for images

* handle upload conditions for profile images and job logos

---------

Co-authored-by: ekzyis <ek@ekzyis.com>
Co-authored-by: ekzyis <ek@stacker.news>
2023-11-06 14:53:33 -06:00
SatsAllDay 1d394bebe1
Ephemeral item support (#570)
backend impl and some of the UI for ephemeral item support

more to come, this is just a WIP so far

Consolidate client-side ephemeral fee logic in FeeButton components for easier reuse

* update the update_item function to handle the case where an item was not
ephemeral, but now is, so we charge the user accordingly

* introduce `hasDeleteCommand` for a better logical abstraction for some use cases in the code

* introduce `EPHEMERAL_FEE_SATS` which is derived from `EPHEMERAL_FEE_MSATS`, so we don't
have to the same calculation over and over

Remove fees for ephemeral items

* remove unused markdownField prop in FeeButton

* remove empty migration

minor code cleanup

Centralize delete item by author code to reduce duplication
2023-10-22 11:02:58 -05:00
ekzyis b2b38d8924
Images v2 (#513) 2023-10-01 18:03:52 -05:00
keyan b740eeb2c4 fix subpackage linting #523 2023-09-26 14:58:36 -05:00
ekzyis dde82e25a5
Convert worker to ESM (#500)
* Convert worker to ESM

To use ESM for the worker, I created a package.json file in worker/ with `{ type: "module" }` as its sole content.

I then rewrote every import to use ESM syntax.

I also tried to set `{ type: "module" }` in the root package.json file to also use ESM in next.config.js.

However, this resulted in a weird problem: default imports were now getting imported as objects in this shape: `{ default: <defaultImport> }`.

Afaik, this should only be the case if you use "import * as foo from 'bar'" syntax: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#default_import

This is fixed by not using `{ type: "module" }` for some reason. However, then, next.config.js also doesn't support ESM import syntax anymore.

The documentation says that if you want to use ESM, you can use next.config.mjs: https://nextjs.org/docs/pages/api-reference/next-config-js

But I didn't want to use MJS extension since I don't have any experience with it. For example, not sure if it's good style to mix JS with MJS etc. So I kept the CJS import syntax there.

* Ignore worker/ during linting

I wasn't able to fix the following errors:

/home/runner/work/stacker.news/stacker.news/worker/auction.js:0:0: Parsing error: No Babel config file detected for /home/runner/work/stacker.news/stacker.news/worker/auction.js. Either disable config file checking with requireConfigFile: false, or configure Babel so that it can find the config files. (null)
/home/runner/work/stacker.news/stacker.news/worker/earn.js:0:0: Parsing error: No Babel config file detected for /home/runner/work/stacker.news/stacker.news/worker/earn.js. Either disable config file checking with requireConfigFile: false, or configure Babel so that it can find the config files. (null)
/home/runner/work/stacker.news/stacker.news/worker/index.js:0:0: Parsing error: No Babel config file detected for /home/runner/work/stacker.news/stacker.news/worker/index.js. Either disable config file checking with requireConfigFile: false, or configure Babel so that it can find the config files. (null)
/home/runner/work/stacker.news/stacker.news/worker/nostr.js:0:0: Parsing error: No Babel config file detected for /home/runner/work/stacker.news/stacker.news/worker/nostr.js. Either disable config file checking with requireConfigFile: false, or configure Babel so that it can find the config files. (null)
/home/runner/work/stacker.news/stacker.news/worker/ots.js:0:0: Parsing error: No Babel config file detected for /home/runner/work/stacker.news/stacker.news/worker/ots.js. Either disable config file checking with requireConfigFile: false, or configure Babel so that it can find the config files. (null)
/home/runner/work/stacker.news/stacker.news/worker/repin.js:0:0: Parsing error: No Babel config file detected for /home/runner/work/stacker.news/stacker.news/worker/repin.js. Either disable config file checking with requireConfigFile: false, or configure Babel so that it can find the config files. (null)
/home/runner/work/stacker.news/stacker.news/worker/search.js:0:0: Parsing error: No Babel config file detected for /home/runner/work/stacker.news/stacker.news/worker/search.js. Either disable config file checking with requireConfigFile: false, or configure Babel so that it can find the config files. (null)
/home/runner/work/stacker.news/stacker.news/worker/streak.js:0:0: Parsing error: No Babel config file detected for /home/runner/work/stacker.news/stacker.news/worker/streak.js. Either disable config file checking with requireConfigFile: false, or configure Babel so that it can find the config files. (null)
/home/runner/work/stacker.news/stacker.news/worker/trust.js:0:0: Parsing error: No Babel config file detected for /home/runner/work/stacker.news/stacker.news/worker/trust.js. Either disable config file checking with requireConfigFile: false, or configure Babel so that it can find the config files. (null)
/home/runner/work/stacker.news/stacker.news/worker/views.js:0:0: Parsing error: No Babel config file detected for /home/runner/work/stacker.news/stacker.news/worker/views.js. Either disable config file checking with requireConfigFile: false, or configure Babel so that it can find the config files. (null)
/home/runner/work/stacker.news/stacker.news/worker/wallet.js:0:0: Parsing error: No Babel config file detected for /home/runner/work/stacker.news/stacker.news/worker/wallet.js. Either disable config file checking with requireConfigFile: false, or configure Babel so that it can find the config files. (null)

I tried to tell babel where to find the babel config file (.babelrc), specifying the babel config in worker/package.json under "babel", using babel.config.json etc. to no avail.

However, afaict, we don't need babel for the worker since it won't run in a browser. Babel is only used to transpile code to target browsers.

But it still would be nice to lint the worker code with standard.

But we can figure this out later.

* Fix worker imports from lib/ and api/

This fixes the issue that we can't use `{ "type": "module" }` in the root package.json since it breaks the app with this error:

  app  | TypeError: next_auth_providers_credentials__WEBPACK_IMPORTED_MODULE_2__ is not a function
  app  |     at eval (webpack-internal:///./pages/api/auth/[...nextauth].js:218:20)
  app  |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
  app  | LND GRPC connection successful
  app  | - error pages/api/auth/[...nextauth].js (139:2) @ CredentialsProvider
  app  | - error Error [TypeError]: next_auth_providers_credentials__WEBPACK_IMPORTED_MODULE_2__ is not a function
  app  |     at eval (webpack-internal:///./pages/api/auth/[...nextauth].js:218:20) {
  app  |   digest: undefined
  app  | }
  app  |   137 |
  app  |   138 | const providers = [
  app  | > 139 |   CredentialsProvider({
  app  |       |  ^
  app  |   140 |     id: 'lightning',
  app  |   141 |     name: 'Lightning',
  app  |   142 |     credentials: {
  app  | TypeError: next_auth_providers_credentials__WEBPACK_IMPORTED_MODULE_2__ is not a function
  app  |     at eval (webpack-internal:///./pages/api/auth/[...nextauth].js:218:20)
  app  |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

build but we need to tell the worker that the files are MJS, else we get this error:

  worker  | file:///app/worker/wallet.js:3
  worker  | import { datePivot } from '../lib/time.js'
  worker  |          ^^^^^^^^^
  worker  | SyntaxError: Named export 'datePivot' not found. The requested module '../lib/time.js' is a CommonJS module, which may not support all module.exports as named exports.
  worker  | CommonJS modules can always be imported via the default export, for example using:
  worker  |
  worker  | import pkg from '../lib/time.js';
  worker  | const { datePivot } = pkg;
  worker  |
  worker  |     at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
  worker  |     at async ModuleJob.run (node:internal/modules/esm/module_job:190:5)
  worker  |
  worker  | Node.js v18.17.0
  worker  |
  worker exited with code 1

* Fix global not defined in browser context

* Also ignore api/ and lib/ during linting

I did not want to do this but I was not able to fix this error in any other way I tried:

  /home/ekzyis/programming/stacker.news/api/lnd/index.js:0:0: Parsing error: No Babel config file detected for /home/ekzyis/programming/stacker.news/api/lnd/index.js. Either disable config file checking with requ
ireConfigFile: false, or configure Babel so that it can find the config files. (null)

Did not want to look deeper into all this standard, eslint, babel configuration stuff ...

---------

Co-authored-by: ekzyis <ek@stacker.news>
Co-authored-by: Keyan <34140557+huumn@users.noreply.github.com>
2023-09-23 20:19:35 -05:00
keyan 5232b59625 upgrade to next-auth 4 (bonus: improve error pages) 2023-07-29 14:38:20 -05:00
keyan 28263bc6c7 rank views 2023-05-23 09:21:04 -05:00
keyan 0a3f5fd201 materialize dashboard in views 2023-05-19 17:38:39 -05:00
keyan 93d4581360 complete nip 57 support 2023-02-14 16:58:12 -06:00
keyan b3f7f24cff trigger streak when eligible 2023-02-02 13:47:09 -06:00
keyan 072e60c954 streaks 2023-02-01 17:40:49 -06:00
keyan 29c59d93ea open timestamps 2023-01-22 14:17:50 -06:00
keyan de863021f9 prevent apollo caching on the server 2022-11-24 13:22:58 -06:00
keyan 7aa6a02a08 make earning more tangible 2022-07-07 14:26:51 -05:00
keyan 7a78210cb6 improvements to earning 2022-03-18 07:29:02 -05:00
keyan 5ff856d061 earning 2022-03-17 15:13:19 -05:00
keyan 1338c026a3 create worker for auction ranking 2022-02-25 11:34:09 -06:00
keyan d413b49e24 search index functions 2022-01-25 14:57:40 -06:00
keyan 054aeea425 break out worker into files using HOF 2022-01-17 11:41:17 -06:00
keyan 7903dbdaf3 WIP trust 2022-01-14 17:43:12 -06:00
keyan cca43f1b2e manually retry wallet polling on ln errors 2022-01-07 10:41:53 -06:00
keyan c3e6627cea support pinned posts + recurring pins 2022-01-07 10:32:31 -06:00
keyan e950b0df7f add job queue 2022-01-05 14:37:34 -06:00