diff --git a/CHANGELOG.md b/CHANGELOG.md index 9dec251a..21868914 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how ## [7.0.1] - [Bugfix for Safari - removed negative lookbehind regex #67](https://github.com/ElrondNetwork/elrond-sdk-erdjs/pull/67) +- [Bugfix on WalletConnect signTransactions single Tx case #69](https://github.com/ElrondNetwork/elrond-sdk-erdjs/pull/69) ## [7.0.0] - [Contract wrapper](https://github.com/ElrondNetwork/elrond-sdk-erdjs/pull/9) diff --git a/src/dapp/walletConnectProvider.ts b/src/dapp/walletConnectProvider.ts index 15f75677..38c4abf0 100644 --- a/src/dapp/walletConnectProvider.ts +++ b/src/dapp/walletConnectProvider.ts @@ -182,18 +182,30 @@ export class WalletConnectProvider implements IDappProvider { const address = await this.getAddress(); const params = transactions.map((transaction) => this.prepareWalletConnectMessage(transaction, address)); - const signatures = await this.walletConnector.sendCustomRequest({ + const signatures: { signature: string }[] | { signature: string } = await this.walletConnector.sendCustomRequest({ method: "erd_batch_sign", params }); - if (!signatures || (transactions.length !== signatures.length)) { + if (!signatures) { Logger.error("signTransactions: Wallet Connect could not sign the transactions"); throw new Error("Wallet Connect could not sign the transactions"); } - transactions.map((transaction, key: number) => - transaction.applySignature(new Signature(signatures[key].signature), new Address(address)) - ); + if (Array.isArray(signatures)) { + if (transactions.length !== signatures.length) { + Logger.error("signTransactions: Wallet Connect could not sign the transactions. Invalid signatures."); + throw new Error("Wallet Connect could not sign the transactions. Invalid signatures."); + } + + transactions.map((transaction, key: number) => + transaction.applySignature(new Signature(signatures[key].signature), new Address(address)) + ); + + return transactions; + } + + transactions[0].applySignature(new Signature(signatures.signature), new Address(address)); + return transactions; }