Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Added middleware examples for modifying responses#177

Closed
ggomaeng wants to merge 4 commits intowevm:mainfrom
ggomaeng:specs-middleware
Closed

Added middleware examples for modifying responses#177
ggomaeng wants to merge 4 commits intowevm:mainfrom
ggomaeng:specs-middleware

Conversation

@ggomaeng
Copy link
Copy Markdown
Contributor

An extension PR of #172

related - #51

I believe it's also worth noting in https://frog.fm/concepts/transactions and set attribution: false everywhere with a note that when MetaMask/metamask-extension#23527 is merged, this will be no longer needed.

Instead of adding something that might be deprecated in the future, I updated the docs so users can create their own middleware to customize the response to fit their needs.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
frog ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 22, 2024 7:31am
frog-frame ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 22, 2024 7:31am

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 22, 2024

@ggomaeng is attempting to deploy a commit to the wevm Team on Vercel.

A member of the Team first needs to authorize it.


app.use(async (c, next) => { // [!code focus]
await next(); // [!code focus]
const isFrame = c.res.headers.get('content-type')?.includes('html'); // [!code focus]
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If there is a better way to check if response is a frame, please update this 🙏

Copy link
Copy Markdown
Collaborator

@dalechyn dalechyn Mar 22, 2024

Choose a reason for hiding this comment

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

Maybe extracting meta tags from head and checking if fc: or frog: are present?

Copy link
Copy Markdown
Contributor Author

@ggomaeng ggomaeng Mar 22, 2024

Choose a reason for hiding this comment

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

True, but it would also require an additional conditional statement to check if content-type is not application/json in case of transaction responses when used as a global middleware.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

true, but for extending meta tags responses maybe it would make sense to add such to FrameResponse itself?

for such middlewares lots of checks have to be performed carefully which is not really dx friendly.

@ggomaeng
Copy link
Copy Markdown
Contributor Author

ggomaeng commented Mar 25, 2024

Raising this PR again, because another issue came up regarding attribution flag.

Context

0xGets from wevm discord was trying to send ETH to a contract address, however the simulation kept showing that the contract would get reverted since attribution data was added as in the call data.


I initially thought that this problem only existed in combination of calling allowance calls within Desktop Metamask, but this would always fail in sending ETH to a contract using eth_sendTransaction.

Even if Metamask merges MetaMask/metamask-extension#23527, this problem would still exist when sending ETH to contract addresses using Frog.

Maybe internally frog should omit the attribution flag when using ETH to a contract address in a .send response.

Warpcast Simulation parameters

transaction": {
    "method": "eth_sendTransaction",
    "params": {
        "to": "0xeac856237a85b70338a32b55bf44b13ef1a7811d",
        "data": "0xfc000023c0",
        "value": "5000000000000000",
        "chainId": "8453",
        "from": "0x130946d8dF113e45f44e13575012D0cFF1E53e37"
    }
},

Related discord Conversation: https://discord.com/channels/1156791276818157609/1221669227182821406

@dalechyn
Copy link
Copy Markdown
Collaborator

Raising this PR again, because another issue came up regarding attribution flag.

Context

0xGets from wevm discord was trying to send ETH to a contract address, however the simulation kept showing that the contract would get reverted since attribution data was added as in the call data.

I initially thought that this problem only existed in combination of calling allowance calls within Desktop Metamask, but this would always fail in sending ETH to a contract using eth_sendTransaction.

Even if Metamask merges MetaMask/metamask-extension#23527, this problem would still exist when sending ETH to contract addresses using Frog.

Maybe internally frog should omit the attribution flag when using ETH to a contract address in a .send response.

Warpcast Simulation parameters

transaction": {
    "method": "eth_sendTransaction",
    "params": {
        "to": "0xeac856237a85b70338a32b55bf44b13ef1a7811d",
        "data": "0xfc000023c0",
        "value": "5000000000000000",
        "chainId": "8453",
        "from": "0x130946d8dF113e45f44e13575012D0cFF1E53e37"
    }
},

Related discord Conversation: https://discord.com/channels/1156791276818157609/1221669227182821406

I believe those are a bit different problems.
The one you were addressing here initially was about making a middleware to return custom meta tags, but the issue with attribution flag is more appropriate to be solved in a separate PR (#172) imo.

Comment on lines +175 to +186
async (c, next) => { // [!code focus]
await next(); // [!code focus]
const txParams = await c.res.json(); // [!code focus]
txParams.attribution = false; // [!code focus]
c.res = new Response(JSON.stringify(txParams), { // [!code focus]
headers: { // [!code focus]
'Content-Type': 'application/json', // [!code focus]
}, // [!code focus]
}); // [!code focus]
}, // [!code focus]
(c) => {/* ... */} // [!code focus]
); // [!code focus]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

the provided example is indeed generic but probably not very DX friendly.

I'd rather see attribution flag added (#172), as this looks as more like a feature frog should support internally.

@ggomaeng
Copy link
Copy Markdown
Contributor Author

Raising this PR again, because another issue came up regarding attribution flag.

Context

0xGets from wevm discord was trying to send ETH to a contract address, however the simulation kept showing that the contract would get reverted since attribution data was added as in the call data.

I initially thought that this problem only existed in combination of calling allowance calls within Desktop Metamask, but this would always fail in sending ETH to a contract using eth_sendTransaction.

Even if Metamask merges MetaMask/metamask-extension#23527, this problem would still exist when sending ETH to contract addresses using Frog.

Maybe internally frog should omit the attribution flag when using ETH to a contract address in a .send response.

Warpcast Simulation parameters

transaction": {

"method": "eth_sendTransaction",
"params": {
    "to": "0xeac856237a85b70338a32b55bf44b13ef1a7811d",
    "data": "0xfc000023c0",
    "value": "5000000000000000",
    "chainId": "8453",
    "from": "0x130946d8dF113e45f44e13575012D0cFF1E53e37"
}

},

Related discord Conversation: https://discord.com/channels/1156791276818157609/1221669227182821406

I believe those are a bit different problems.

The one you were addressing here initially was about making a middleware to return custom meta tags, but the issue with attribution flag is more appropriate to be solved in a separate PR (#172) imo.

You're absolutely right.

Sounds good and will create a separate PR continuing #172.

@ggomaeng
Copy link
Copy Markdown
Contributor Author

Continuing this in #187. Closing this because provided examples hurt the DX.

@ggomaeng ggomaeng closed this Mar 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants