wevm / wagmi

Reactive primitives for Ethereum apps
https://wagmi.sh
MIT License
6k stars 1.07k forks source link

bug: write?.() from useContractWrite doesn't ask to redirect to wallet app #3211

Closed meri-maki closed 10 months ago

meri-maki commented 1 year ago

Is there an existing issue for this?

Package Version

1.4.6

Current Behavior

I have a production project on react with build made 2 weeks ago I'm using wagmi hooks and web3modal for connection and mint (useContractWrite)

Few days ago we wanted to have a small update to the website, but after the new build was made, the automatic redirection to wallet app on mobile stopped working (click on button with write?.()) this redirection: IMG_4503

It's really strange because even if I copy working branch and make new build - it stops working correctly

I've tried: removing all logic and reproducing super minimal version, updating all packages to the newest, downgrading again ONLY the files from old build works

I have a test project that is similar to my prod This version is updated, with new build and the redirection doesn't work ---> https://wagmi-read-non-working.vercel.app/ This version is old, with old build and same logic and here is works ---> https://wagmi-read.vercel.app/

Expected Behavior

write() should cause a popup with 'redirect' options and it worked fine until recently

i'm not sure if it's wagmi issue or something with WalletConnect

I would really appreciate an advice bc I've been trying to fix this for 3 days now....

The repo is https://github.com/meri-maki/useSwitchNetwork/blob/main/src/MintNFT/MintNFT.jsx It stopped working after this commit https://github.com/meri-maki/useSwitchNetwork/commit/cee536cc69ccb8d42bafb6788cc10ff875588927#diff-1df931291a82be390da0d0fd4b7c8a3ee13e2b122aa1f124eb8ddde995b1168f

Steps To Reproduce

On mobile, IOS preferably To see the Expected behavior:

  1. open https://wagmi-read.vercel.app/
  2. with WalletConnect connect ZERION or TRUST wallet
  3. Click on Mint
  4. See pop up "Open in "Zerion"?"

To see the Current behavior:

  1. open https://wagmi-read-non-working.vercel.app/
  2. repeat steps from above and there won't be any popup

Link to Minimal Reproducible Example (StackBlitz, CodeSandbox, GitHub repo etc.)

https://github.com/meri-maki/useSwitchNetwork/

Anything else?

IMPORTANT NOTE: write() works, I can see the notification in my wallet

glitch-txs commented 1 year ago

can you make the example minimal? I'm not able to reproduce it

meri-maki commented 1 year ago

@glitch-txs hi! which one you are not able to reproduce?

meri-maki commented 1 year ago

@glitch-txs i minimized the non-working example at https://wagmi-read-non-working.vercel.app/ After authorization with zerion/trust, the click on Mint doesn't redirect to app even though the transaction appears in the app

glitch-txs commented 1 year ago

thanks! could you share the repo?

meri-maki commented 1 year ago

yep https://github.com/meri-maki/useSwitchNetwork/ last commit here please let me know if there is anything more i can do to resolve this

meri-maki commented 1 year ago

UPD: forcefully downgrading to "viem": "1.17.2", brought the redirection back

meri-maki commented 1 year ago

Hi team! Any news? Will this be fixed in newer versions?

htadeusiak commented 1 year ago

I'm running into a similar if not same issue where useSignMessage does not redirect to MM onClick.

@meri-maki both your "read" and "non working read" both do not open the redirect "Open in blank" for me on mobile IOS. Is the read version working for you? It fires the request, so if I manually swip over to the app its there. However, if I don't have the app open in the background I have to re-trigger the request

Downgrading did now work in my case.

meri-maki commented 1 year ago

@htadeusiak thank you for pointing out that the examples do not work (it worked though) The reason might be that vercel builds project on server while in my production project it's build locally

However the issue remains and I hope we will get a fix The older version is a temporary fix, and I would love to use newer viem but if redirect is not fixed I would need to build additional UI so the user is not lost

alienzhangyw commented 12 months ago

Same problem with MetaMask since it upgraded a new version in July. User has to manually switch to wallet app and switch back to browser after signed.

remibeaufils commented 12 months ago

@htadeusiak thank you for pointing out that the examples do not work (it worked though) The reason might be that vercel builds project on server while in my production project it's build locally

However the issue remains and I hope we will get a fix The older version is a temporary fix, and I would love to use newer viem but if redirect is not fixed I would need to build additional UI so the user is not lost

@meri-maki could you kindly tell me with which older versions this works for you?

I also have the problem, using these versions:

"@web3modal/wagmi": "3.3.2", "viem": "1.19.1", "wagmi": "1.4.6",

I tried using following older versions and the redirect doesn't work either:

"@web3modal/wagmi": "3.1.0", "viem": "1.17.2", "wagmi": "1.4.5",
meri-maki commented 12 months ago

@remibeaufils for me it works with "viem": "1.17.2", "wagmi": "1.4.5", "@web3modal/wagmi": "^3.1.0",

I use viem as a separate chunk and this chunk hasn't changed in weeks, if i remove it and build project again, redirect tops working

"use strict";(this.myApptooncoinweb=this.myApptooncoinweb||[]).push([[28],{6553:(e,a,t)=>{t.d(a,{normalize:()=>s});var r=t(912);function s(e){return(0,r.Q6)(e)}},4571:(e,a,t)=>{t.d(a,{offchainLookup:()=>g,offchainLookupSignature:()=>w});var r=t(3218),s=t(1159),n=t(9146),o=t(4745);class c extends n.G{constructor({callbackSelector:e,cause:a,data:t,extraData:r,sender:s,urls:n}){super(a.shortMessage||"An error occurred while fetching for an offchain result.",{cause:a,metaMessages:[...a.metaMessages||[],a.metaMessages?.length?"":[],"Offchain Gateway Call:",n&&["  Gateway URL(s):",...n.map((e=>`    ${(0,o.Gr)(e)}`))],`  Sender: ${s}`,`  Data: ${t}`,`  Callback selector: ${e}`,`  Extra data: ${r}`].flat()}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"OffchainLookupError"})}}class d extends n.G{constructor({result:e,url:a}){super("Offchain gateway response is malformed. Response data must be a hex value.",{metaMessages:[`Gateway URL: ${(0,o.Gr)(a)}`,`Response: ${(0,s.P)(e)}`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"OffchainLookupResponseMalformedError"})}}class l extends n.G{constructor({sender:e,to:a}){super("Reverted sender address does not match target contract address (`to`).",{metaMessages:[`Contract address: ${a}`,`OffchainLookup sender address: ${e}`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"OffchainLookupSenderMismatchError"})}}var u=t(6929),i=t(4796),f=t(632),p=t(230),h=t(3408),b=t(7644),m=t(9450);const w="0x556f1830",y={name:"OffchainLookup",type:"error",inputs:[{name:"sender",type:"address"},{name:"urls",type:"string[]"},{name:"callData",type:"bytes"},{name:"callbackFunction",type:"bytes4"},{name:"extraData",type:"bytes"}]};async function g(e,{blockNumber:a,blockTag:t,data:n,to:o}){const{args:w}=(0,i.p)({data:n,abi:[y]}),[g,k,O,x,G]=w;try{if(!function(e,a){if(!(0,h.U)(e))throw new p.b({address:e});if(!(0,h.U)(a))throw new p.b({address:a});return e.toLowerCase()===a.toLowerCase()}(o,g))throw new l({sender:g,to:o});const n=await async function({data:e,sender:a,urls:t}){let r=new Error("An unknown error occurred.");for(let n=0;n<t.length;n++){const o=t[n],c=o.includes("{sender}")||o.includes("{data}")?"GET":"POST",l="POST"===c?{data:e,sender:a}:void 0;try{const t=await fetch(o.replace("{sender}",a).replace("{data}",e),{body:JSON.stringify(l),method:c});let n;if(n=t.headers.get("Content-Type")?.startsWith("application/json")?(await t.json()).data:await t.text(),!t.ok){r=new u.Gg({body:l,details:(0,s.P)(n.error)||t.statusText,headers:t.headers,status:t.status,url:o});continue}if(!(0,m.v)(n)){r=new d({result:n,url:o});continue}return n}catch(e){r=new u.Gg({body:l,details:e.message,url:o})}}throw r}({data:O,sender:g,urls:k}),{data:c}=await(0,r.R)(e,{blockNumber:a,blockTag:t,data:(0,b.zo)([x,(0,f.E)([{type:"bytes"},{type:"bytes"}],[n,G])]),to:o});return c}catch(e){throw new c({callbackSelector:x,cause:e,data:n,extraData:G,sender:g,urls:k})}}}}]);
//# sourceMappingURL=viem.92d3b5f9.js.map

There might be something in there that make the redirection magic happen :)

tmm commented 10 months ago

This is likely an upstream issue. Check out Wagmi v2 to see if it's still present.

github-actions[bot] commented 10 months ago

This issue has been locked since it has been closed for more than 14 days.

If you found a concrete bug or regression related to it, please open a new bug report with a reproduction against the latest wagmi version. If you have any other comments you can create a new discussion.