project-serum / swap-ui

React Component for Swapping on the Serum DEX
Apache License 2.0
113 stars 115 forks source link

Type mismatch with `sol-wallet-adapter` and `anchor/dist/provider`. #71

Open lieuzhenghong opened 3 years ago

lieuzhenghong commented 3 years ago

Not sure where to put this, but trying to build the example page with sol-wallet-adapter 0.2.5 and anchor 0.11.1 gives a type mismatch.

Argument of type 'import("..../node_modules/@project-serum/sol-wallet-adapter/dist/cjs/index").default' is not assignable to parameter of type 'import(".../node_modules/@project-serum/anchor/dist/provider").Wallet'.
  Types of property 'publicKey' are incompatible.
    Type 'PublicKey | null' is not assignable to type 'PublicKey'.
      Type 'null' is not assignable to type 'PublicKey'.  TS2345

    139 |     onTransaction: (tx: TransactionSignature | undefined, err?: Error) => void
    140 |   ) {
  > 141 |     super(connection, wallet, opts);
        |                       ^
    142 |     this.onTransaction = onTransaction;
    143 |   }
    144 |

I believe this migration to Typescript in sol-wallet-adapter was the one that broke it: here.

We can see the export interface Wallet in anchor/ts/provider.ts still uses PublicKey instead of PublicKey | null here.

armaniferrante commented 3 years ago

Not sure where to put this, but trying to build the example page with sol-wallet-adapter 0.2.5 and anchor 0.11.1 gives a type mismatch.

Argument of type 'import("..../node_modules/@project-serum/sol-wallet-adapter/dist/cjs/index").default' is not assignable to parameter of type 'import(".../node_modules/@project-serum/anchor/dist/provider").Wallet'.
  Types of property 'publicKey' are incompatible.
    Type 'PublicKey | null' is not assignable to type 'PublicKey'.
      Type 'null' is not assignable to type 'PublicKey'.  TS2345

    139 |     onTransaction: (tx: TransactionSignature | undefined, err?: Error) => void
    140 |   ) {
  > 141 |     super(connection, wallet, opts);
        |                       ^
    142 |     this.onTransaction = onTransaction;
    143 |   }
    144 |

I believe this migration to Typescript in sol-wallet-adapter was the one that broke it: here.

We can see the export interface Wallet in anchor/ts/provider.ts still uses PublicKey instead of PublicKey | null here.

As a workaround, you can use // @ts-ignore.

thevenice commented 3 years ago

I am Facing the same issue here, any working solutions ?

TheXienator commented 2 years ago

I have the same issue here as well I fixed it by doing:

    const { publicKey, wallet, signTransaction, signAllTransactions } = useWallet();
    if (!wallet || !publicKey || !signTransaction || !signAllTransactions) {
      return;
    }
    const signerWallet = {
      publicKey: publicKey,
      signTransaction: signTransaction,
      signAllTransactions: signAllTransactions,
    };

    const provider = new Provider(connection, signerWallet, {
      preflightCommitment: "recent",
    });