reach-sh / reach-lang

Reach: The Safest and Smartest DApp Programming Language
https://www.reach.sh
Apache License 2.0
583 stars 167 forks source link

Pera wallet connect not working #1548

Open kieranroneill opened 1 year ago

kieranroneill commented 1 year ago

Describe the error

In the latest update, it seems Pera wallet connect no longer seems to work. Whenever a transaction is sent to be signed to Pera an error is thrown:

"TypeError: e.map is not a function"

To Reproduce

import { ALGO_MakePeraConnect as MakePeraConnect } from '@reach-sh/stdlib'; // 0.1.13-rc.0
import { PeraWalletConnect } from "@perawallet/connect"; // 1.1.0

stdlib.setWalletFallback(
  stdlib.walletFallback({
    providerEnv: 'TestNet', 
    WalletConnect: MakePeraConnect(PeraWalletConnect) 
  })
);

await stdlib.getDefaultAccount();

Expected behavior

Extra information

Looking at the code where the transactions are sent to Pera wallet here, the unsigned transactions are sent in base64 but @perawallet/connect is expecting an unsigned Transaction that is from the algosdk.

Therefore, signTxns should probably follow:

import { decodeUnsignedTransaction } from 'algosdk';

export default function ALGO_MakePeraConnect( PeraWalletConnect:any ) {
  return class PeraConnect {
    // ...
    async signTxns(txns:string[]): Promise<string[]> {
      let rawSignedTxns: Uint8Array[];

      await this.ensureSession();

      rawSignedTxns = await this.pc.signTransaction([
        txns.map((value) => {
          const decodedUnsignedTxn: Transaction = decodeUnsignedTransaction(Buffer.from(value, 'base64')); // decode the transaction

          return {
            txn: decodedUnsignedTxn,
          };
        }),
      ]);

      return rawSignedTxns.map((value) =>
        Buffer.from(value).toString('base64') // encode the signed transactions back to base64 to be returned
      );
    }
  }
};
BMscis commented 1 year ago

Does this work for reach ?

temptemp3 commented 1 year ago

Does this work for reach ?

Sure it does ; )