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

🐛 [BUG] - Fail on Unsubscribe #934

Closed
manuelbarzi opened this issue Dec 18, 2023 · 8 comments · Fixed by #974
Closed

🐛 [BUG] - Fail on Unsubscribe #934

manuelbarzi opened this issue Dec 18, 2023 · 8 comments · Fixed by #974
Assignees
Labels
bug Something isn't working

Comments

@manuelbarzi
Copy link

manuelbarzi commented Dec 18, 2023

Expected Behaviour

to unsubscribe the user account from channel calling - internally - to the API (for unsubscribe)

Current Behaviour

we observe that the API for unsubscribe is not taking place when we call to:

const response = await pushAPI.notification.unsubscribe(
      this.channelAddress
    );

we've been debugging a bit the protocol pushapi and we found out that a this point

 if (primaryType !== 'EIP712Domain') {
        // Validate message types.
        const type = types[primaryType];
        validateData(type, message);
    }

in file webpack-internal:///(app-pages-browser)/node_modules/viem/dist/esm/utils/typedData.jsfrom viem
the type parameter is undefined
the message looks correct (eg: {data: '{\n "channel": "0x923796dAc057E7…1bD295c36F560617e",\n "action": "Unsubscribe"\n}'})

and also we want to state the error handling doesn't work properly and we observe no error thrown on this situation, but a very weird response message

response

{status: '', message: 'struct is not iterable'}

please, let us know if there's anything else we should provide to give more light to this issue. also my colleague @federicolopezeikilis is aware about it and he detected this issue

Reproduction steps

1. Go to 'debugger'
2. Invoke function 'await pushAPI.notification.unsubscribe(
      this.channelAddress
    );'
3. See error while debugging in webpack-internal:///(app-pages-browser)/node_modules/tslib/tslib.es6.mjs

function rejected(value) {
            try {
                step(generator["throw"](value));
            } catch (e) {
                reject(e);
            }
        }

inspect it, and you will see it.

Screenshots

DESCRIPTION

Relevant Logs

TypeError: struct is not iterable
    at validateData (typedData.js:20:29)
    at validateTypedData (typedData.js:57:9)
    at signTypedData (signTypedData.js:137:75)
    at Object.signTypedData (wallet.js:42:113)
    at eval (signer.js:37:40)
    at Generator.next (<anonymous>)
    at eval (tslib.es6.mjs:155:69)
    at new Promise (<anonymous>)
    at Module.__awaiter (tslib.es6.mjs:151:10)
    at signTypedData (signer.js:28:78)
    at eval (unsubscribeV2.js:33:61)
    at Generator.next (<anonymous>)
    at fulfilled (tslib.es6.mjs:152:56)

Dapp Env

Dev (dev.push.org)

Browsers

Chrome

@manuelbarzi manuelbarzi added the bug Something isn't working label Dec 18, 2023
@Aman035
Copy link
Member

Aman035 commented Dec 18, 2023

Hey @manuelbarzi need some info regarding this

  1. The sdk version u r using ?
  2. The type of signer u r using ? ( viem or ethers )
  3. Which wallet u r using ? ( Any EOA or SCW )
  4. The channel address u r trying to unsubscribe ? ( There seems to be no channel on dev that starts with 0x923796dAc057E7...

@Aman035
Copy link
Member

Aman035 commented Dec 18, 2023

Also would recommend to use staging env, since dev is for internal team and in unstable.

@federicolopezeikilis
Copy link

First of all we are using staging env. The dev env detailed in the ticket was wrong. We are working on staging env

  1. The sdk version u r using ? 1.4.45

  2. The type of signer u r using ? ( viem or ethers ). VIEM

  3. Which wallet u r using ? ( Any EOA or SCW ). EOA

@manuelbarzi
Copy link
Author

manuelbarzi commented Dec 19, 2023

hi @Aman035
yes, the data was obfuscated by error, here's the correct data

{data: '{\n    "channel": "0x429796dAc057E7C15724196367007F…1bD295c36F560613e",\n    "action": "Unsubscribe"\n}'}

@manuelbarzi
Copy link
Author

here's a shot
Screenshot 2023-12-18 at 14 58 13

@Aman035 Aman035 self-assigned this Dec 20, 2023
@Aman035 Aman035 added this to the Push SDK V1.6 milestone Dec 20, 2023
@Aman035
Copy link
Member

Aman035 commented Dec 20, 2023

Hey @manuelbarzi again I can't find any channel that starts with 0x429796dAc057E7C15724196367007F... on our dev / stage or prod env.

Also shift to version 1.5.0 of @pushprotocol/restapi

Can u paste the fn code which u r using for unsubscribe and channel u r trying to unsubscribe ( the channel name or its url - eg - staging.push.org/channels?channel=0x35B84d6848D16415177c64D64504663b998A6ab4 )

Ideally this is the fn that u should use

import { PushAPI, CONSTANTS } from "@pushprotocol/restapi";

// where signer is ethersV5 signer or viem walletClient
const userAlice = await PushAPI.initialize(signer, { env: CONSTANTS.ENV.STAGING });

// Assumption - `channelAddress` exist on staging env
const unsubscribeResponse = await userAlice.notification.unsubscribe(
  `eip155:11155111:${channelAddress}`, // channel to unsubscribe
);

@manuelbarzi
Copy link
Author

independently of the address of the channel, @Aman035, what we are stating is that the unsubscribe method in pushAPI. notification member doesn't look like working properly. it returns an object that results very confusing:

{status: '', message: 'struct is not iterable'}

and this is because exceptions do not seem to be correctly managed inside this unsubscribe method. whatever the error it is, let's say a wrong channel, whatever, your push API should provide context and a correct error reponse. here is shot showing the same result abova
Screenshot 2023-12-27 at 18 18 30

@federicolopezeikilis
Copy link

@Aman035 I tested it again with other channel in env staging and sepolia network.

Channel address: 0x94aBa23b9Bbfe7bb62A9eB8b1215D72b5f6F33a1
Wallet address: 0xBCE85e9874AD6859D2dD4394B86142d683A2D5b7

When I called this, response.status was 204
const response = await pushAPI.notification.subscribe("eip155:11155111:0x94aBa23b9Bbfe7bb62A9eB8b1215D72b5f6F33a1");

Now when I call this, isChannelInSubscriptions is true
const subscriptions: { channel: Address; user_settings: string }[] = await pushAPI.notification.subscriptions();

const isChannelInSubscriptions = subscriptions.some(({ channel }) => channel === "0x94aBa23b9Bbfe7bb62A9eB8b1215D72b5f6F33a1"));

But when I try to unsubscribe using the following code, the response is { message: "struct is not iterable", status: ""}
const response = await pushAPI.notification.unsubscribe("eip155:11155111:0x94aBa23b9Bbfe7bb62A9eB8b1215D72b5f6F33a1");

@Aman035 Aman035 linked a pull request Jan 4, 2024 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants