Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert JS to TS (commits 7-13 of PR435) - attempt#2 #585

Merged
merged 13 commits into from
Sep 26, 2024

Conversation

webwarrior-ws
Copy link
Contributor

Supersedes #557. Added a commit that should fix bug in disputes.

@grunch grunch requested review from Catrya and grunch September 3, 2024 14:31
Copy link
Member

@Catrya Catrya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @webwarrior-ws @Mersho
When the admin goes to take a dispute this error appears in the logs:

[2024-09-04T10:09:59.680-04:00] error: Community was not found in DB Error: Community was not found in DB
    at /home/catry/bot/bot/validations.js:208:27
    at step (/home/catry/bot/bot/validations.js:56:23)
    at Object.next (/home/catry/bot/bot/validations.js:37:53)
    at fulfilled (/home/catry/bot/bot/validations.js:28:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Copy link
Member

@Catrya Catrya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also happened to me that the wizard_add_invoice_init message was not being sent in any order even though it entered the wizard because any command or invoice that I sent to it would delete it. However, I stopped it and started it again and it worked.

Copy link
Member

@Catrya Catrya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When sending an invoice to receive, it always returns this error to the buyer: Invoice expiry is too short

@webwarrior-ws webwarrior-ws force-pushed the convert-to-ts-remaining branch 3 times, most recently from fae0e71 to e79a108 Compare September 5, 2024 08:39
@webwarrior-ws
Copy link
Contributor Author

The bugs should be fixed now, but I haven't tested.

@webwarrior-ws
Copy link
Contributor Author

It also happened to me that the wizard_add_invoice_init message was not being sent in any order even though it entered the wizard because any command or invoice that I sent to it would delete it. However, I stopped it and started it again and it worked.

Not sure about this one. Maybe it was because validateAdmin failed.

@webwarrior-ws webwarrior-ws requested a review from Catrya September 5, 2024 13:03
@Catrya
Copy link
Member

Catrya commented Sep 6, 2024

Hola@webwarrior-ws @Mersho Cuando el administrador va a tomar una disputa aparece este error en los registros:

[2024-09-04T10:09:59.680-04:00] error: Community was not found in DB Error: Community was not found in DB
    at /home/catry/bot/bot/validations.js:208:27
    at step (/home/catry/bot/bot/validations.js:56:23)
    at Object.next (/home/catry/bot/bot/validations.js:37:53)
    at fulfilled (/home/catry/bot/bot/validations.js:28:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

This error has already been solved

Copy link
Member

@Catrya Catrya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Al enviar una factura para recibir, siempre devuelve este error al comprador:Invoice expiry is too short

@webwarrior-ws @Mersho That error is still there, it always says Invoice expiry is too short but if I change to or any other branch and put the same invoice it accepts it without problem

@webwarrior-ws
Copy link
Contributor Author

Al enviar una factura para recibir, siempre devuelve este error al comprador:Invoice expiry is too short

@webwarrior-ws @Mersho That error is still there, it always says Invoice expiry is too short but if I change to or any other branch and put the same invoice it accepts it without problem

I tried with my test setup and could not reproduce this bug.

@Catrya
Copy link
Member

Catrya commented Sep 9, 2024

@grunch could you try to reproduce it? I can't get that error not to appear, thanks :)

@webwarrior-ws
Copy link
Contributor Author

Added some debug logging. Maybe that will help with identifying the problem.

@Catrya
Copy link
Member

Catrya commented Sep 9, 2024

Added some debug logging. Maybe that will help with identifying the problem.

Well, the bot did not show the wizard_add_invoice_init message and this error appeared:
[2024-09-09T09:49:10.191-04:00] error: All promises were rejected AggregateError: All promises were rejected

But I knew it was 500 sats so I put the invoice and this appears:

Date(invoice.expires_at) = Mon Sep 09 2024 10:49:28 GMT-0400 (hora de verano de Cuba)
latestDate = Mon Sep 09 2024 10:49:47 GMT-0400 (hora de verano de Cuba)
INVOICE_EXPIRATION_WINDOW = 3600000

@webwarrior-ws
Copy link
Contributor Author

I don't see any bug in lnp2pBot code here. Invoice expires less than INVOICE_EXPIRATION_WINDOW (1 hour) from time of running, and that results in error.
I don't know why main branch doesn't result in error in the same scenario. Maybe this code never worked as intended? I noticed that in original code, Date is compared to string.

@knocte
Copy link
Contributor

knocte commented Sep 10, 2024

Maybe this code never worked as intended? I noticed that in original code, Date is compared to string.

Looks like we need @grunch's input here?

@grunch
Copy link
Member

grunch commented Sep 10, 2024

Hi guys!

I'm testing it, after I take a dispute of an order created in the global channel is works perfectly, after I take a dispute of an order created on a community it doesn't work, here the log

[2024-09-10T11:48:18.398-03:00] error: 400: Bad Request: can't parse entities: Character '.' is reserved and must be escaped with the preceding '\' Error: 400: Bad Request: can't parse entities: Character '.' is reserved and must be escaped with the preceding '\'
    at Telegram.callApi (/home/grunch/dev/bot-warrior/node_modules/telegraf/lib/core/network/client.js:264:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async exports.disputeData (/home/grunch/dev/bot-warrior/bot/modules/dispute/messages.js:90:5)
    at async exports.takeDispute (/home/grunch/dev/bot-warrior/bot/modules/dispute/actions.js:39:3)
    at async execute (/home/grunch/dev/bot-warrior/node_modules/telegraf/lib/composer.js:468:17)
    at async /home/grunch/dev/bot-warrior/node_modules/telegraf/lib/composer.js:469:21

@webwarrior-ws
Copy link
Contributor Author

@grunch I have tried to reproduce the bug, but I can't take a dispute - when I click on "Take dispute" button I get a message "You have been banned!". As I only have 2 telegram accounts, solver user is one of the participants, maybe that's the issue?

@webwarrior-ws
Copy link
Contributor Author

Me and @knocte managed to take and resolve dispute in community. That error looks like contents of some variable is not escaped properly. I've seen a commit in main that adds escaping. I rebased this branch. Maybe this will also solve the bug. If not, I added a commit that dumps contents of the problematic message into console.

@grunch
Copy link
Member

grunch commented Sep 12, 2024

@grunch I have tried to reproduce the bug, but I can't take a dispute - when I click on "Take dispute" button I get a message "You have been banned!". As I only have 2 telegram accounts, solver user is one of the participants, maybe that's the issue?

Yes, we ban users after being involved on n disputes, I think that restriction is not useful and we should remove it in the future, but to continue just remove the ban on the document for that user, change field banned to false, then try again

@knocte
Copy link
Contributor

knocte commented Sep 13, 2024

change field banned to false, then try again

Francisco, that is old info. After webwarrior wrote that message, I assisted him in his testing, being the 3rd user in his setup (the solver, in particular), and he couldn't reproduce the issue. See #585 (comment) , and test again with the new logs added please.

@grunch
Copy link
Member

grunch commented Sep 16, 2024

@grunch I have tried to reproduce the bug, but I can't take a dispute - when I click on "Take dispute" button I get a message "You have been banned!". As I only have 2 telegram accounts, solver user is one of the participants, maybe that's the issue?

Hi @webwarrior-ws sorry for the delay, are you able to run the bot in this branch? I'm testing and I'm getting this errors

[2024-09-16T17:22:26.672-03:00] error: ResubcribeInvoice catch: 503,UnexpectedGetInvoicesError,[object Object] 
[2024-09-16T17:23:00.027-03:00] error: 503,FailedToConnectToDaemon 
[2024-09-16T17:23:00.028-03:00] error: node info catch error: TypeError: Cannot read properties of undefined (reading 'is_synced_to_chain') 
[2024-09-16T17:24:00.022-03:00] error: 503,FailedToConnectToDaemon 
[2024-09-16T17:24:00.022-03:00] error: node info catch error: TypeError: Cannot read properties of undefined (reading 'is_synced_to_chain') 

I that we are having conflics, can you solve them and we can try again?

Mersho and others added 2 commits September 24, 2024 10:12
The languageModel & fiatModel interface created to type-check
the data and ensure that it conforms to
the expected structure and format.
This can help you avoid errors and bugs when
working with the data in your code.
This commit enables resolveJsonModule to import module
with '.json' extension.

Co-authored-by: webwarrior <[email protected]>
The --downlevelIteration flag is a TypeScript compiler
option that enables support for iterating over new
concepts like Map, Set, or Generator in older JavaScript
runtimes. By default, TypeScript targets ES3, which does
not support these features. If you use a for...of loop or
a spread operator on an iterable object, you may get an error.
Use Date instead of Date.toISOString cause paid_at has type
Date and during the conversion from js to ts,
we got compilation errors.

Co-authored-by: webwarrior <[email protected]>
Mersho and others added 10 commits September 24, 2024 10:12
Using null instead of a boolean/undefined type is better.
I had to change the '|', otherwise typescript would
complain this error msg:
```
The '|' operator is not allowed for boolean types.
Consider using '||' instead.
```

Co-authored-by: webwarrior <[email protected]>
Fix bugs in validations.ts introduced in d36a6b7 when porting
to TypeScript.
Fixed bug in validateAdmin that would throw an error when
community is null even though null value is valid in this case.
Don't convert dates to strings in isValidInvoice.
Added debug logging for case when `Invoice expiry is too short`
error is encountered.
Added debug logging of message that caused error when taking
dispute in community.
@webwarrior-ws
Copy link
Contributor Author

@grunch I've rebased PR branch and there are no merge conflicts now. I've also tested it with standard sell/buy procedure and got no 503 errors that you have mentioned.

Copy link
Member

@grunch grunch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for solving the conflicts, I just tested it again and I found a new bug, here the log:

[2024-09-24T14:56:16.092-03:00] error: 400: Bad Request: can't parse entities: Character '.' is reserved and must be escaped with the preceding '\' Error: 400: Bad Request: can't parse entities: Character '.' is reserved and must be escaped with the preceding '\'
    at Telegram.callApi (/home/grunch/dev/bot-warrior/node_modules/telegraf/lib/core/network/client.js:315:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async exports.disputeData (/home/grunch/dev/bot-warrior/bot/modules/dispute/messages.js:114:5)

I dig in a bit and I found that you can't use object properties inside locales, so I changed, here the patch, can you apply this on the other languages? thanks

diff --git a/bot/modules/dispute/messages.js b/bot/modules/dispute/messages.js
index a887012..d8bc775 100644
--- a/bot/modules/dispute/messages.js
+++ b/bot/modules/dispute/messages.js
@@ -1,4 +1,8 @@
-const { getDisputeChannel, getDetailedOrder, sanitizeMD } = require('../../../util');
+const {
+  getDisputeChannel,
+  getDetailedOrder,
+  sanitizeMD,
+} = require('../../../util');
 const { logger } = require('../../../logger');
 
 exports.beginDispute = async (ctx, initiator, order, buyer, seller) => {
@@ -91,11 +95,11 @@ exports.disputeData = async (
     // Fix Issue 543: Escape underscores in usernames
     const escapedInitiatorUsername = sanitizeMD(initiatorUser.username);
     const escapedCounterPartyUsername = sanitizeMD(counterPartyUser.username);
-    
+
     const message = ctx.i18n.t('dispute_started_channel', {
-      initiatorUser: { ...initiatorUser, username: escapedInitiatorUsername },
+      initiatorUser: escapedInitiatorUsername,
       initiatorTgId: initiatorUser.tg_id,
-      counterPartyUser: { ...counterPartyUser, username: escapedCounterPartyUsername },
+      counterPartyUser: escapedCounterPartyUsername,
       counterPartyUserTgId: counterPartyUser.tg_id,
       buyer,
       seller,
@@ -107,11 +111,9 @@ exports.disputeData = async (
       buyerToken: order.buyer_dispute_token,
     });
     console.log(`Contens of message:\n${message}`);
-    await ctx.telegram.sendMessage(
-      solver.tg_id,
-      message,
-      { parse_mode: 'MarkdownV2' }
-    );
+    await ctx.telegram.sendMessage(solver.tg_id, message, {
+      parse_mode: 'MarkdownV2',
+    });
     // message to both parties letting them know the dispute
     // has been taken by a solver
     await ctx.telegram.sendMessage(
diff --git a/locales/es.yaml b/locales/es.yaml
index 9baf03f..26cbc22 100644
--- a/locales/es.yaml
+++ b/locales/es.yaml
@@ -202,16 +202,16 @@ order_detail: |
 seller: vendedor
 buyer: comprador
 dispute_started_channel: |
-  El ${type} @${initiatorUser.username} TG ID: ${initiatorTgId}
-  ha iniciado una disputa con @${counterPartyUser.username} TG ID: ${counterPartyUserTgId} en la orden:
+  El ${type} @${initiatorUser} TG ID: ${initiatorTgId}
+  ha iniciado una disputa con @${counterPartyUser} TG ID: ${counterPartyUserTgId} en la orden:
 
   ${detailedOrder}
 
   Seller Token: ${sellerToken}
   Buyer Token: ${buyerToken}
 
-  @${initiatorUser.username} ya tiene ${buyerDisputes} disputas
-  @${counterPartyUser.username} ya tiene ${sellerDisputes} disputas
+  @${initiatorUser} ya tiene ${buyerDisputes} disputas
+  @${counterPartyUser} ya tiene ${sellerDisputes} disputas
 you_started: '🥴 Has iniciado una disputa en tu orden con Id: ${orderId}.'
 counterpart_started: '🥴 Tu contraparte ha iniciado una disputa en tu orden con Id: ${orderId}.'
 dispute_started: '${who} Un solver te atenderá pronto, cuando él/la solver sea asignado a tu disputa el bot te dirá su username, solo él/ella podrá atenderte. Puedes escribirle directamente, pero si él/ella te contacta primero, debes pedirle que te diga cuál es el token de tu disputa, tu token es: ${token}.'
diff --git a/util/index.ts b/util/index.ts
index 0b1bc7e..902d9e4 100644
--- a/util/index.ts
+++ b/util/index.ts
@@ -368,7 +368,7 @@ const getDetailedOrder = (i18n: I18nContext, order: IOrder, buyer: UserDocument,
     takenAt = sanitizeMD(takenAt);
     const previousDisputeStatus = sanitizeMD(order.previous_dispute_status);
     const status = sanitizeMD(order.status);
-    const fee = order.fee ? Number(order.fee) : '';
+    const fee = order.fee ? sanitizeMD(Number(order.fee)) : '';
     const creator =
       order.creator_id === buyerId ? buyerUsername : sellerUsername;
     const buyerAge = buyer? getUserAge(buyer) : '';

Don't use object properties inside locales, as it doesn't work
and leads to parse errors.
@webwarrior-ws webwarrior-ws force-pushed the convert-to-ts-remaining branch from ede5ef3 to 706b9fd Compare September 26, 2024 12:34
@webwarrior-ws
Copy link
Contributor Author

@grunch applied your patch, updated locales and disputes test

@grunch
Copy link
Member

grunch commented Sep 26, 2024

@grunch applied your patch, updated locales and disputes test

great job, thanks for this contribution, as we are receiving some donations we want to give back some sats to our contributors, it's more of a symbolic gesture of gratitude 😃

Please add as a comment a lightning invoice with amount of 200,000 sats

@grunch grunch merged commit a46260d into lnp2pBot:main Sep 26, 2024
4 checks passed
@webwarrior-ws
Copy link
Contributor Author

lnbc2m1pn0dtz0pp5ru28d55mfjw2aypjvsu7xnd5uj7363mz095slnwmca05mcequ9nscqpjsp5vuprh07ze5nk2k6rhx7zjy67axfqmsej9gmt6a7zudhsy7ej8zas9q7sqqqqqqqqqqqqqqqqqqqsqqqqqysgqdqqmqz9gxqyjw5qrzjqwryaup9lh50kkranzgcdnn2fgvx390wgj5jd07rwr3vxeje0glcll6lyxlsu4fuhqqqqqlgqqqqqeqqjqu7s52ap9967fnyvqc9nphcccsqpl3txa679zpzw2f0h6gwqhex7qwf5y2eywlmd5wyjx9e7k5ckn2luml34c304mtyuze87zy5mkfdgpmqngrw

@grunch
Copy link
Member

grunch commented Sep 27, 2024

lnbc2m1pn0dtz0pp5ru28d55mfjw2aypjvsu7xnd5uj7363mz095slnwmca05mcequ9nscqpjsp5vuprh07ze5nk2k6rhx7zjy67axfqmsej9gmt6a7zudhsy7ej8zas9q7sqqqqqqqqqqqqqqqqqqqsqqqqqysgqdqqmqz9gxqyjw5qrzjqwryaup9lh50kkranzgcdnn2fgvx390wgj5jd07rwr3vxeje0glcll6lyxlsu4fuhqqqqqlgqqqqqeqqjqu7s52ap9967fnyvqc9nphcccsqpl3txa679zpzw2f0h6gwqhex7qwf5y2eywlmd5wyjx9e7k5ckn2luml34c304mtyuze87zy5mkfdgpmqngrw

Payment hash: 1f1476d29b4c9cae90326439e34db4e4bd1d476279690fcddbc75f4de320e167
Payment status: SUCCEEDED, preimage: ed4600e227269b6d29068d1b7eb51e8bd77f9137b94e334e6bcb561b5ffcc7cf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants