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

Feature: Show transaction hashes for claimed permits #173

Conversation

barebind
Copy link
Contributor

Resolves #138

@ubiquity-os-deployer
Copy link

ubiquity-os-deployer bot commented Feb 22, 2024

@0x4007
Copy link
Member

0x4007 commented Feb 22, 2024

73b9799

I'm working on a runtime fix at my branch now.

@0x4007 0x4007 marked this pull request as ready for review February 26, 2024 10:30
@0x4007 0x4007 self-requested a review as a code owner February 26, 2024 10:30
@0x4007
Copy link
Member

0x4007 commented Feb 26, 2024

I think you'll need to pull from development because the app doesn't run. Did you test this? Also I fixed the continuous deploys within the time that you opened this pull request. If you push again it should deploy here and we will know definitively if its an environment issue etc.

Uncaught TypeError: (define_extraRpcs_default[1] || []) is not iterable
    at constants.ts:46:95
    at index.ts:20:52

@barebind
Copy link
Contributor Author

I think you'll need to pull from development because the app doesn't run.

done.

@rndquu
Copy link
Member

rndquu commented Feb 27, 2024

@barebind This PR is ready for review, right?

@barebind
Copy link
Contributor Author

@barebind This PR is ready for review, right?

yes, I'm looking for adding database functions on my local supabase instance but getting a weird error. in any case there won't be any change on code side as it handles errors already. so yes, pr ready for review.

@barebind
Copy link
Contributor Author

Uncaught TypeError: (define_extraRpcs_default[1] || []) is not iterable
    at constants.ts:46:95
    at index.ts:20:52

I've tried on development branch too but still have this issue. it's not about this PR I would say. @pavlovcik

@barebind
Copy link
Contributor Author

Got it, it's /static/scripts/rewards/constants.ts file declaring wrong variable.

-declare const extraRpcs: Record<string, string[]>; // @DEV: passed in at build time check build/esbuild-build.ts
+declare const allNetworkUrls: Record<string, string[]>; // @DEV: passed in at build time check build/esbuild-build.ts
 
 export enum NetworkIds {
   Mainnet = 1,
   Goerli = 5,
   Gnosis = 100,
 }
-console.trace({ extraRpcs });
+console.trace({ allNetworkUrls });

Should I fix it on this PR?

@0x4007
Copy link
Member

0x4007 commented Feb 27, 2024

It should be fixed on most of the other branches why don't you investigate based on the other recently closed pulls and see what commit they are based on.

It seems unusual to me that the problem persists if you rebased (or even merged) from a later commit when it was fixed.

@barebind
Copy link
Contributor Author

added the fix PR #181 for the issue. @pavlovcik

@rndquu rndquu self-requested a review February 28, 2024 06:42
Copy link
Member

@rndquu rndquu left a comment

Choose a reason for hiding this comment

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

Getting an error "updating transaction hash is not allowed". I'm using pavlovcik's supabase public anon key. What am I doing wrong?

Screenshot 2024-02-28 at 10 11 07

static/scripts/rewards/web3/erc20-permit.ts Outdated Show resolved Hide resolved
@barebind
Copy link
Contributor Author

Getting an error "updating transaction hash is not allowed". I'm using pavlovcik's supabase public anon key. What am I doing wrong?

that error is coming from db function. the transaction column is not null so it doesn't allow to update it as we discussed before. but the thing you are supposed to see a toaster saying that the permit is already claimed. let me check it. can you post the permit url?

@barebind barebind requested a review from rndquu February 28, 2024 07:37
@rndquu
Copy link
Member

rndquu commented Feb 28, 2024

Getting an error "updating transaction hash is not allowed". I'm using pavlovcik's supabase public anon key. What am I doing wrong?

that error is coming from db function. the transaction column is not null so it doesn't allow to update it as we discussed before. but the thing you are supposed to see a toaster saying that the permit is already claimed. let me check it. can you post the permit url?

Why can we update only null fields? Is there a way to rewrite non null fields via supabase? I just don't get the rationale behind this logic on the supabase side.

Copy link
Member

@rndquu rndquu left a comment

Choose a reason for hiding this comment

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

Works fine

@barebind
Copy link
Contributor Author

Why can we update only null fields? Is there a way to rewrite non null fields via supabase? I just don't get the rationale behind this logic on the supabase side.

Maybe I misunderstood the context but I'm referring these conversations/quotes below.

In case that's too complex to implement: maybe it's simpler to just allow updating if it's null. #173 (comment)

Let it work this way, we'll fix it later when DB schema is stable (ubiquity/ubiquibot#919) #173 (comment)

@0x4007
Copy link
Member

0x4007 commented Feb 28, 2024

I just don't get the rationale behind this logic on the supabase side.

The rationale is that it seemed simple to implement and good for 99% of cases. Given that column level security is an advanced feature according to their docs:

"This is an advanced feature. We do not recommend using column-level privileges for most users.
Instead, we recommend using RLS policies in combination with a dedicated table for handling user
roles."

I figured it makes the most sense to do it the simple way, and then possibly get around to implementing column level security as a lower priority task in the future.

@rndquu
Copy link
Member

rndquu commented Feb 28, 2024

Why can we update only null fields? Is there a way to rewrite non null fields via supabase? I just don't get the rationale behind this logic on the supabase side.

Maybe I misunderstood the context but I'm referring these conversations/quotes below.

In case that's too complex to implement: maybe it's simpler to just allow updating if it's null. #173 (comment)

Let it work this way, we'll fix it later when DB schema is stable (ubiquity/ubiquibot#919) #173 (comment)

I meant if there is way to rewrite non null fields in supabase, because it seems strange that you can write (using supabase's public anon key) to null fields but can't override non empty

@barebind
Copy link
Contributor Author

I agree with the idea that this task focuses solving more like a

show proof that the permit was claimed because I grow tired of addressing this exact same complaint.

sort of problems. it is more about the UX rather than security. I think security concern should be another issue to discuss.

on the other hand though, I totally agree with @rndquu's comment in long term. simply checking not null doesn't mean anything from security standpoint.

@barebind
Copy link
Contributor Author

Where is the notification?

toaster.create("error", `Your reward for this task has already been claimed or invalidated.`);

@0x4007
Copy link
Member

0x4007 commented Feb 29, 2024

Where is the notification?

toaster.create("error", `Your reward for this task has already been claimed or invalidated.`);

This task is to show the transaction hash of the prior claim. Besides, what you're showing me already has been implemented and is live on pay.ubq.fi

@@ -74,6 +81,13 @@ export function claimErc20PermitHandler(permit: Erc20Permit, provider: JsonRpcPr
}

export async function checkPermitClaimable(permit: Erc20Permit, signer: ethers.providers.JsonRpcSigner | null, provider: JsonRpcProvider) {
const permitHash = await doesPermitHaveTxHash(permit);
if (permitHash !== null) {
const explorerLink = `<a href="${getExplorerLinkForTx(permit.networkId, permitHash)}" target=_blank >${shortenTxHash(permitHash)}</a>`;
Copy link
Member

@0x4007 0x4007 Feb 29, 2024

Choose a reason for hiding this comment

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

Oh I understand, its only if it exists in the database. Perhaps we can do an end-to-end test somehow? How did you test locally? We can just do the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

1- generate claim through script
2- write it to db manually (as null transaction column)
3- and test the rest :)

I assume that (I have to somehow) permits are written to db correctly.

Copy link
Member

@0x4007 0x4007 Feb 29, 2024

Choose a reason for hiding this comment

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

I suppose for another task we should replace the claim button with the transaction hash if it has already been claimed or validated.

We can substitute the claim button with one that has this icon, and upon mouse over it can say "View Claim"

<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M212.309-140.001q-30.308 0-51.308-21t-21-51.308v-535.382q0-30.308 21-51.308t51.308-21h252.305V-760H212.309q-4.616 0-8.463 3.846-3.846 3.847-3.846 8.463v535.382q0 4.616 3.846 8.463 3.847 3.846 8.463 3.846h535.382q4.616 0 8.463-3.846 3.846-3.847 3.846-8.463v-252.305h59.999v252.305q0 30.308-21 51.308t-51.308 21H212.309Zm176.46-206.615-42.153-42.153L717.847-760H560v-59.999h259.999V-560H760v-157.847L388.769-346.616Z"/></svg>

@barebind
Copy link
Contributor Author

Where is the notification?

toaster.create("error", `Your reward for this task has already been claimed or invalidated.`);

This task is to show the transaction hash of the prior claim. Besides, what you're showing me already has been implemented and is live on pay.ubq.fi

There are two different checks,

first one is db check for not-null-transaction-column if there is a hash then show the explorer link

toaster.create("error", `This reward has already been claimed. Transaction hash: ${explorerLink}`);

and the second one that you are seeing as a toaster message is claimed nonce check.

the order is as it is, first check db and then nonce.

@0x4007
Copy link
Member

0x4007 commented Feb 29, 2024

I'm testing now. Writing some notes. Some unrelated issue:

TypeError: Cannot set properties of null (setting 'innerHTML')
    at renderToFields (insert-table-data.ts:93:10)
    at insertErc20PermitTableData (insert-table-data.ts:15:3)
    at renderTransaction (render-transaction.ts:132:36)
Promise.catch (async)		
handler	@	erc20-permit.ts:72
  toFull.innerHTML = `<div>${receiverAddress}</div>`;

@0x4007
Copy link
Member

0x4007 commented Feb 29, 2024

Doesn't look like it works because I just tested on this.

image

@rndquu
Copy link
Member

rndquu commented Feb 29, 2024

I've tested this PR locally, not on CF deployments + the tx hash must exist in the DB in order for the notification with tx hash to be displayed

@0x4007
Copy link
Member

0x4007 commented Feb 29, 2024

I've tested this PR locally, not on CF deployments + the tx hash must exist in the DB in order for the notification with tx hash to be displayed

I think this feature should also include writing the data to the database. Even if my permit amount was of 0 it should still be recorded in the database.

@0x4007 0x4007 mentioned this pull request Feb 29, 2024
@barebind
Copy link
Contributor Author

I think this feature should also include writing the data to the database. Even if my permit amount was of 0 it should still be recorded in the database.

it actually writes the transaction hash to the database after the transaction is sent and confirmed.

I think your test case is an already claimed permit which has a null transaction column in the database. which shouldn't happen normally

@0x4007
Copy link
Member

0x4007 commented Feb 29, 2024

No I generated a new permit and claimed it. You can check the chain for a timestamp.

@rndquu
Copy link
Member

rndquu commented Feb 29, 2024

I've tested this PR locally, not on CF deployments + the tx hash must exist in the DB in order for the notification with tx hash to be displayed

I think this feature should also include writing the data to the database. Even if my permit amount was of 0 it should still be recorded in the database.

This PR does write tx hash to the permits.transaction field (if it is null)

@barebind
Copy link
Contributor Author

No I generated a new permit and claimed it. You can check the chain for a timestamp.

do you generate new permit manually? if the permit is on db with null hash(not claimed) it updates the permits.transaction with the sent transaction's hash.

it doesn't write the permit data to the database.

@0x4007
Copy link
Member

0x4007 commented Feb 29, 2024

I have the real private key in my .env so I generate real permits when I run yarn start.

When is it written to the database? It's a bit difficult for me to see in the code when I'm mobile.

@barebind
Copy link
Contributor Author

this pr is only updating already existing permit with the transaction hash. I was assuming permit is inserted to database when/where it's generated.

@barebind
Copy link
Contributor Author

barebind commented Feb 29, 2024

I have the real private key in my .env so I generate real permits when I run yarn start.

normally the permits are generated(and inserted to db) by ubiquibot so when I'm testing I inserted the generated permit(yarn start) to db manually.

@rndquu
Copy link
Member

rndquu commented Feb 29, 2024

I have the real private key in my .env so I generate real permits when I run yarn start.

normally the permits are generated(and inserted to db) by ubiquibot so when I'm testing I inserted the generated permit(yarn start) to db manually.

Yes, it's expected to work this way:

  1. The bot generates a permit in the DB
  2. Contributor claims the permit
  3. Claim tx is written to a DB

So in order to see a tx url in the permits.transaction field the permit must exist in the DB

@0x4007 0x4007 marked this pull request as draft March 3, 2024 03:55
@0x4007
Copy link
Member

0x4007 commented Mar 5, 2024

@barebind any updates?

@barebind
Copy link
Contributor Author

barebind commented Mar 5, 2024

@barebind any updates?

I've started working on #182 today which makes this one useless I suppose.
Anything to do with this one?

@0x4007
Copy link
Member

0x4007 commented Mar 5, 2024

@barebind any updates?

I've started working on #182 today which makes this one useless I suppose. Anything to do with this one?

If you think this is obsolete then you can close this pull.

@barebind
Copy link
Contributor Author

barebind commented Mar 5, 2024

If you think this is obsolete then you can close this pull.

seems like you changed this one to draft 2 days ago, any specific reason? anything that you were waiting from me?

in any case I think that we definitely cannot merge both branches as basically they are doing the same thing in different ways.

if you don't have any feedback I think it's better to close this one.

@0x4007
Copy link
Member

0x4007 commented Mar 5, 2024

if you don't have any feedback I think it's better to close this one.

This didn't work in my end-to-end test.

@barebind
Copy link
Contributor Author

barebind commented Mar 6, 2024

I'm closing this PR as it is basically same feature (and same issues) with different UI/UX with #173

@barebind barebind closed this Mar 6, 2024
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.

Already Claimed Permit Proof
3 participants