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

Add walletconnect provider #114

Conversation

devceline
Copy link
Contributor

@devceline devceline commented Sep 28, 2023

Changes

  • Add walletconnectProvider
  • Tested by hitting the /api/test endpoint - it is kept in there for testing convenience, will be reverted once everything is confirmed to work
  • Updated dev dev for @types/node to prevent build error

@zzuziak zzuziak requested a review from ChaituVR October 3, 2023 07:17
@ChaituVR
Copy link
Member

ChaituVR commented Oct 4, 2023

Hey @devceline @Cali93 Are there any docs on how I can test this? :)

@devceline
Copy link
Contributor Author

Hey @devceline @Cali93 Are there any docs on how I can test this? :)

Hi - yes of course. As mentioned in the description I personally tested it by modifying the /api/test endpoint to use our provider directly.

preliminary setup for that is:

  • Either enable notify in your current WalletConnect Cloud project or create a different project and make sure to enable notify under "APIs". From there you can get the project secret.
  • Make sure to upload the did.json and wc-notify-config to the URL configured in the project above under https://your.domain/.well-known/
  • Using the variables in env.example, copy the ones prefixed with WALLETCONNECT into your .env file. Modifying the project id and project secret from the info retrieved in step 1
  • From there - you can connect to https://app.web3inbox.com/ and subscribe to your project from https://app.web3inbox.com/notifications/new-app
  • After you are subscribed and the env vars are configured - run dev in snapshot-hooks & hit the /api/test endpoint.

After that, you should see a notification in https://app.web3inbox.com in your subscription.

If you do not get one, double check that the notification type in the wc-notify-config.json exists in the getNotificationType function.

If you have any questions please feel free to reach out.

@ChaituVR
Copy link
Member

ChaituVR commented Oct 6, 2023

Hi @devceline thanks for the reply, i have seen the WC cloud projects but that needs verification. Is there some way to test with out touching https://your.domain/.well-known/ or snapshot.org directly

@chris13524
Copy link
Contributor

@ChaituVR you can deploy a testing domain to host the .well-known for a new testing WalletConnect Cloud project, e.g. snapshot-wc-notify-test.vercel.app. It doesn't have to be tied to the snapshot.org domain until you move to prod.

@ChaituVR
Copy link
Member

Hey guys, how can i see my test app here https://app.web3inbox.com/notifications/new-app ?

@devceline
Copy link
Contributor Author

Hey guys, how can i see my test app here https://app.web3inbox.com/notifications/new-app ?

Hey! We'll send you a full video on this tomorrow. However, for now

You can follow the following instructions to see your app there.

On https://app.web3inbox.com/notifications/new-app, go to the settings page by clicking the cog on the sidebar

image

Then clicking the "Notifications" tab
image

And toggle "Display all"

image

Then navigate back to https://app.web3inbox.com/notifications/new-app and you should see your app there.

@ChaituVR
Copy link
Member

Hi @devceline I could get my app on this list. here is my app https://cloud.walletconnect.com/app/project?uuid=1b17f525-1b76-40d7-86e4-66821b538885 should i have to publish it?

@chris13524
Copy link
Contributor

@ChaituVR you don't need to publish your app to test it, just enable Notify API in Cloud and also toggle the switch in app.web3inbox.com from Celine's post above.

@ChaituVR
Copy link
Member

I did that @chris13524 but sadly i don't see it. I see other test ones but not mine. Maybe i miss some step ,😥

@ChaituVR
Copy link
Member

Or is there some other way i can test this ? maybe i can build a small front end like here https://docs.walletconnect.com/api/notify/usage

@devceline
Copy link
Contributor Author

Or is there some other way i can test this ? maybe i can build a small front end like here https://docs.walletconnect.com/api/notify/usage

Just checked your project, looks like Notify is disabled, can you go ahead and tick that toggle for Notify API?

image

@chris13524
Copy link
Contributor

@ChaituVR I don't think Ngrok will work for hosting the did.json because Ngrok requires the user to press a button in order to view the site (which a JS fetch will not be able to do). So you will probably need to host the did.json on another platform such as Cloudflare Pages or Vercel. Key is hitting that switch and getting a green toast, and it doesn't look like that was setup yet.

@ChaituVR
Copy link
Member

ChaituVR commented Oct 25, 2023

Weird it actually shows that i have enabled it, ngrok works without any "press a button"
Untitled 2

@ChaituVR
Copy link
Member

Oh i retried disabling and enabling it again and i see my app on the list now 🥳
Untitled 3

@ChaituVR
Copy link
Member

I get this as response when i try to trigger test endpoint

[WalletConnect] there are 1 addresses that are not subscribed through WalletConnect
[WalletConnect] could not get matching notification body for event proposal/created
Failed to deserialize the JSON body into the target type: missing field `notification` at line 1 column 15

@ChaituVR
Copy link
Member

Tried adding proposal/created to notifications of my test app, but i always see these somehow
Untitled 3

@devceline
Copy link
Contributor Author

Tried adding proposal/created to notifications of my test app, but i always see these somehow Untitled 3

Ah yes, there was a spec change over the past week. Now notification types need to be passed by ID. I checked your config and got the ID for proposal_update and pushed that up.

Also realized I didn't document this above but like other providers that take a list of subscribers, the WalletConnect Notify provider does as well.

You should pass your address on line 32 in src/api.

We can remove this and just use notify server's list of subscribers directly, of course, but I thought targeting an address would be easier to test with.

@ChaituVR
Copy link
Member

ChaituVR commented Nov 1, 2023

whatever way i try, I always get this error
[WalletConnect] there are 1 addresses that are not subscribed through WalletConnect

😢

Anyway, what are the next steps to proceed?

@devceline
Copy link
Contributor Author

whatever way i try, I always get this error [WalletConnect] there are 1 addresses that are not subscribed through WalletConnect

😢

Anyway, what are the next steps to proceed?

Well - can you tell me what address you're putting in line 32 of src/api? Did you subscribe with this address on web3inbox? Any extra details to help us debug would be awesome 🙏

Next steps would be choosing whether or not you'd want to maintain a list of subscribers on your database or go with the discord provider approach and just depend on external data. In this case, external data is notify servers' list of subscribers.

Once we have that squared away I can update the PR to match, but if you can't test this maybe we should arrange a meeting to actually tackle the issue.

@ChaituVR
Copy link
Member

Well - can you tell me what address you're putting in line 32 of src/api? Did you subscribe with this address on web3inbox? Any extra details to help us debug would be awesome 🙏

I tried passing multiple addresses, for example 0x24F15402C6Bb870554489b2fd2049A85d75B982f, i tried metamask, mobile and trust wallet using walletconnect, maybe they are not supported yet?

Next steps would be choosing whether or not you'd want to maintain a list of subscribers on your database or go with the discord provider approach and just depend on external data. In this case, external data is notify servers' list of subscribers.

@bonustrack Could you help me with this plz?

@chris13524
Copy link
Contributor

@ChaituVR the address needs to be a CAIP-10 account ID. Try prefixing the address with eip165:1: for example eip155:1:0x24F15402C6Bb870554489b2fd2049A85d75B982f

@ChaituVR
Copy link
Member

ChaituVR commented Nov 11, 2023

Hi @chris13524 thank you!

Is there some issue with
https://app.web3inbox.com/ i am getting these errors from yesterday
image

Also tried in incognito

@chris13524
Copy link
Contributor

@ChaituVR this looks like a temporary network error, and we don't commonly see this. Could you perhaps try again?

src/providers/walletconnectNotify.ts Outdated Show resolved Hide resolved
src/providers/walletconnectNotify.ts Outdated Show resolved Hide resolved
Comment on lines +46 to +49
} catch (e) {
capture('[WalletConnect] failed to fetch subscribers');
return [];
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we catching and suppressing this error? If we can't get subscribers then the functions that call this should fail as well, not proceed with an empty list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the other providers like discord and xmtp don't throw and just end up being a noop so I did the same here

const notifyUrl = `${WALLETCONNECT_NOTIFY_SERVER_URL}/${WALLETCONNECT_PROJECT_ID}/notify`;

const body = {
accounts,
Copy link
Contributor

Choose a reason for hiding this comment

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

accounts has a max length of 500, so we need to call /notify in a loop.

Also has a rate limit of 2 per second so you may need to add some artificial timing e.g. with date math and await new Promise(resolve => setTimeout(resolve, time))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll refactor to fix this

Copy link
Member

@bonustrack bonustrack left a comment

Choose a reason for hiding this comment

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

Can you run the lint:fix command too?

src/helpers/utils.ts Outdated Show resolved Hide resolved
src/providers/walletconnectNotify.ts Outdated Show resolved Hide resolved
src/providers/walletconnectNotify.ts Outdated Show resolved Hide resolved

// Cross Reference subscribers from Snapshot to the ones in Notify
export async function getSubscriberFromDb(space: string) {
const subs: string[] = await getSubscribers(space);
Copy link
Member

Choose a reason for hiding this comment

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

You don't need to run this query, you should instead use the "subscribers" variable from the send function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Awesome - updating to use subscribers.

src/providers/walletconnectNotify.ts Show resolved Hide resolved
Comment on lines +39 to +40
case 'proposal/end':
return `A proposal has closed for ${space.name}`;
Copy link
Member

Choose a reason for hiding this comment

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

I talked to team about this, better we should be jusing just 'proposal/start' instead of created/end

// That should be defined in the wc-notify-config.json
function getNotificationType(event) {
if (event.includes('proposal/')) {
return 'ed2fd071-65e1-440d-95c5-7d58884eae43';
Copy link
Member

Choose a reason for hiding this comment

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

I think this one is for new app

Suggested change
return 'ed2fd071-65e1-440d-95c5-7d58884eae43';
return 'f3c55113-06fb-47c7-87da-28ee21b9114a';

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes - please feel free to adjust the notification types per your cloud configuration

src/providers/walletconnectNotify.ts Show resolved Hide resolved
Comment on lines +144 to +145
const url = new URL(proposal.link);
url.searchParams.append('app', 'walletconnect');
Copy link
Member

Choose a reason for hiding this comment

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

This is resulting in https://snapshot.org/?app=walletconnect#/thanku.eth/proposal/0x8c2a67398c9912f7c2ba15a68caf94388ea98a88074079103d48e3eae83e2ea7 I think it is better to add string at the end of URL

Copy link
Member

Choose a reason for hiding this comment

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

Maybe this is fine

Copy link
Contributor

@chris13524 chris13524 Jan 15, 2024

Choose a reason for hiding this comment

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

What's the purpose of ?app=walletconnect @devceline ?

Reason for new URL was to properly parse and construct the string to properly use query params. If we appended at end of the URL it also wouldn't be a valid query param as it would actually be part of the fragment. What would the string at the end of the URL be used for?

Copy link
Member

Choose a reason for hiding this comment

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

What would the string at the end of the URL be used for?

It is used by snapshot to know that someone voted from web3inbox, changed it to web3inbox in the other PR, hope it is fine

}

// Transform proposal event into notification format.
async function formatMessage(event, proposal) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
async function formatMessage(event, proposal) {
function formatMessage(event, proposal) {

@devceline
Copy link
Contributor Author

Closed in favor of #162

@devceline devceline closed this Jan 16, 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.

5 participants