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

Error fetching trade #627

Open
HarlamovEvgeniy opened this issue Jan 26, 2024 · 25 comments
Open

Error fetching trade #627

HarlamovEvgeniy opened this issue Jan 26, 2024 · 25 comments
Labels
bug Something isn't working

Comments

@HarlamovEvgeniy
Copy link

Bug Description
The problem occurs on the widget screen. The endless error "Error fetching trade"

image

Versions:
Vite: 4.5.1
React: 18.2.0
TypeScript: 5.3.3
@uniswap/widgets: 2.59.0
...

Expected Behavior
A clear and concise description of what you expected to happen.

@HarlamovEvgeniy HarlamovEvgeniy added the bug Something isn't working label Jan 26, 2024
@HarlamovEvgeniy
Copy link
Author

HarlamovEvgeniy commented Jan 26, 2024

My vite.config.ts

import react from '@vitejs/plugin-react'
import { fileURLToPath } from 'url'
import { defineConfig } from 'vite'
import { createHtmlPlugin } from 'vite-plugin-html'
import svgLoader from 'vite-svg-loader'
import { chunkSplitPlugin } from 'vite-plugin-chunk-split';
import { nodePolyfills } from "vite-plugin-node-polyfills"
import path from "path";

export default defineConfig({
  plugins: [
    react(),
    createHtmlPlugin({
      minify: true,
      entry: '/src/main.tsx',
      template: '/index.html',
    }),
    svgLoader(),
    chunkSplitPlugin({
      strategy: 'unbundle',
    }),
    nodePolyfills()
  ],
  server: {
    port: 3000,
    open: true,
  },
  optimizeDeps: {
    esbuildOptions: {
      define: {
        global: 'globalThis'
      }
    }
  },
  resolve: {
    alias: {
      "@": fileURLToPath(new URL('./src', import.meta.url)),
      jsbi: path.resolve(__dirname, "./node_modules/jsbi/dist/jsbi-cjs.js"),
      process: "process/browser",
      buffer: "buffer",
      crypto: "crypto-browserify",
      stream: "stream-browserify",
      assert: "assert",
      http: "stream-http",
      https: "https-browserify",
      os: "os-browserify",
      url: "url",
      util: "util",
    }
  },
  build: {
    outDir: path.join(__dirname, "build"),
    sourcemap: false,
    minify: true,
    commonjsOptions: {
      transformMixedEsModules: true,
    }
  },
})

@Asharp19
Copy link

Asharp19 commented Jan 29, 2024

Same issue with me not sure if its a Vite thing. Got to launch a frontend for my token was thinking could add a widget before liquidity pool is set since short on time.
I guess will have to take the sdk-v3 route for quotes and swapping

@Antonio100898
Copy link

Same

@SerovMihail
Copy link

We are facing the same issue with the same configuration. Any solution?

@HarlamovEvgeniy
Copy link
Author

The only solution that helped me was to implement my widget using the SDK-v3

@Antonio100898
Copy link

Antonio100898 commented Feb 1, 2024 via email

@HarlamovEvgeniy
Copy link
Author

Any solution?

@Chi111
Copy link

Chi111 commented Feb 3, 2024

Same!
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.8.0",
"@uniswap/widgets": "2.59.0",
"@metamask/detect-provider": "2.0.0",
"ethers": "5.7.2",

@Chi111
Copy link

Chi111 commented Feb 3, 2024

The only solution that helped me was to implement my widget using the SDK-v3

Can You Give Me a demo? My project is still wrong

@HarlamovEvgeniy
Copy link
Author

Can You Give Me a demo? My project is still wrong

I can't share it because the reason is in the smart-order-router library, and I couldn't make my own implementation:(

@dziobakwszafie
Copy link

Any update for that? I;m facing the same problem with Next.js

@Wunsz
Copy link

Wunsz commented Feb 6, 2024

My summary of the issue so far is as follows:

This issue occurs at least on the following browsers:

  • Chrome 121.0.6167.139 (Official Build) (64-bit)
  • Firefox 122.0 (64-bit)

This issue occurs in all the latest bundlers:

  • Vite (Rollup)
  • CRA (Webpack5)
  • NextJS (Webpack5)

The core issue is in this package: https://github.com/foliojs/brotli.js which is a dependency of @uniswap/smart-order-router package. There is an old issue raised for that so it's unclear why this resurfaced here just now:
foliojs/brotli.js#20

The workaround we found so far (dirty one) is to monkey patch the window object and tell it that the Browser.T function exists:

window.Browser = {
    T: () => {}
}

@fabdarice
Copy link

Following

@smartbart1
Copy link

same

@LilNait-S
Copy link

Any update for that? I;m facing the same problem with Next.js

The same issue but with @uniswap/smart-order-router

@lisabeyy
Copy link

Same issue and bunches of error when installing the widget, this definitely not working with nextjs 14 and the given workaround

@russell0430
Copy link

same issue with nextjs@14

@Dariocoding
Copy link

same issue with nextjs@14 x2

@Dariocoding
Copy link

¿What should i do? Shit

@Wunsz
Copy link

Wunsz commented Mar 22, 2024

What works for us is:

  1. Specify "use client"; at the top of the file where you use the SwapWidget component
  2. Before the component is defined, we add:
if (typeof window !== "undefined") {
// @ts-ignore
  window.Browser = {
    T: () => {
    }
  };
}
  1. Add this to your next.js config:
/** @type {import('next').NextConfig} */
// 👇️ assumes you use Webpack 5
module.exports = {
  webpack: (config) => {
    config.resolve.fallback = {
      fs: false,
      path: false,
      Browser: false,
    };

    return config;
  },
  externals: ["pino-pretty"],
};

Sample component code:

"use client";

import React from "react";
import { SwapWidget } from "@uniswap/widgets";


if (typeof window !== "undefined") {
    // @ts-ignore
      window.Browser = {
        T: () => {
        }
      };
    }
    

const SwapComponent = () => <SwapWidget />;

export default SwapComponent;

And that actually made it work some time ago but you will now hit:
image

For now you can try my fork here:
https://www.npmjs.com/package/@wunsz-4soft/uniswap-widgets

But I do not guarantee anything, especially its maintenance.

@linxux
Copy link

linxux commented May 3, 2024

Same issue on the version - 2.59.0.
And the @Wunsz 's workaround is not working for me.

    "@uniswap/widgets": "^2.59.0",
    "react": "^18.3.1",
    "react-dom": "^18.3.1",
    "react-redux": "^9.1.2",
    "react-scripts": "5.0.1",
    "typescript": "^4.4.2",
    "web-vitals": "^2.1.0"

@limian1858
Copy link

same

@GolfredoPerezFernandez
Copy link

what should we do!

@hieppd79
Copy link

any solution for nextjs14 guys?

@dziobakwszafie
Copy link

dziobakwszafie commented Jun 26, 2024

any solution for nextjs14 guys?

nope, that library is a big piece of you know what, recommend to do it on your own, will be still faster then fixing all the bugs in there

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

No branches or pull requests