Skip to content

Commit

Permalink
Merge pull request #157 from ElrondNetwork/wallet-provider-options
Browse files Browse the repository at this point in the history
Wallet Provider: add "options" on tx sign return value
  • Loading branch information
andreibancioiu authored Mar 18, 2022
2 parents 0b8407c + 5f3f03a commit 283fc4f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
## Unreleased
- TBD

## [9.2.2]
- [Wallet Provider: add "options" on tx sign return value](https://github.com/ElrondNetwork/elrond-sdk-erdjs/pull/157)

## [9.2.1]
- [Fix / simplify some imports](https://github.com/ElrondNetwork/elrond-sdk-erdjs/pull/148)
- [Handle strings in binary codec](https://github.com/ElrondNetwork/elrond-sdk-erdjs/pull/153)
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@elrondnetwork/erdjs",
"version": "9.2.1",
"version": "9.2.2",
"description": "Smart Contracts interaction framework",
"main": "out/index.js",
"types": "out/index.d.js",
Expand Down
15 changes: 10 additions & 5 deletions src/dapp/walletProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import {
} from "./constants";
import { Transaction } from "../transaction";
import { SignableMessage } from "../signableMessage";
import {ErrInvalidTxSignReturnValue, ErrNotImplemented} from "../errors";
import {Signature} from "../signature";
import { ErrInvalidTxSignReturnValue, ErrNotImplemented } from "../errors";
import { Signature } from "../signature";
import { Nonce } from "../nonce";
import { Balance } from "../balance";
import { Address } from "../address";
import { ChainID, GasLimit, GasPrice, TransactionVersion } from "../networkParams";
import { ChainID, GasLimit, GasPrice, TransactionOptions, TransactionVersion } from "../networkParams";
import { TransactionPayload } from "../transactionPayload";

interface TransactionMessage {
Expand All @@ -25,6 +25,7 @@ interface TransactionMessage {
gasLimit?: number;
data?: string;
nonce?: number;
options?: number;
}

export class WalletProvider implements IDappProvider {
Expand Down Expand Up @@ -81,7 +82,7 @@ export class WalletProvider implements IDappProvider {
resolve(true);
}, 10);
});

return window.location.href;
}

Expand Down Expand Up @@ -187,6 +188,7 @@ export class WalletProvider implements IDappProvider {
}

static getTxSignReturnValue(urlParams: any): Transaction[] {
// "options" property is optional (it isn't always received from the Web Wallet)
const expectedProps = ["nonce", "value", "receiver", "sender", "gasPrice",
"gasLimit", "data", "chainID", "version", "signature"];

Expand Down Expand Up @@ -214,7 +216,10 @@ export class WalletProvider implements IDappProvider {
data: new TransactionPayload(<string>urlParams["data"][i]),
chainID: new ChainID(<string>urlParams["chainID"][i]),
version: new TransactionVersion(parseInt(<string>urlParams["version"][i])),

// Handle the optional "options" property.
...(urlParams["options"] && urlParams["options"][i] ? {
options: new TransactionOptions(parseInt(<string>urlParams["options"][i]))
} : {})
});
tx.applySignature(new Signature(<string>urlParams["signature"][i]), Address.fromString(<string>urlParams["sender"][i]));
transactions.push(tx);
Expand Down

0 comments on commit 283fc4f

Please sign in to comment.