Skip to content

Commit

Permalink
Upgrade taquito; fix fee, limits passing
Browse files Browse the repository at this point in the history
  • Loading branch information
serg-plusplus committed Jun 21, 2021
1 parent 4801f53 commit e5aeb37
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 71 deletions.
140 changes: 77 additions & 63 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
"nanoid": "^3.1.10"
},
"devDependencies": {
"@taquito/taquito": "^8.0.0-beta.2",
"@taquito/taquito": "^9.1.1",
"microbundle": "^0.12.2",
"typedoc": "^0.17.8",
"typedoc-plugin-markdown": "^2.3.1",
"typescript": "^3.9.6"
"typescript": "^4.3.4"
},
"peerDependencies": {
"@taquito/taquito": "^7.0.0 || ^7.0.0-beta || ^8.0.0-beta"
"@taquito/taquito": "^9.0.0"
},
"publishConfig": {
"access": "public"
Expand Down
55 changes: 51 additions & 4 deletions src/taquito-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
createSetDelegateOperation,
createTransferOperation,
WalletDelegateParams,
WalletOriginateParams,
WalletTransferParams,
WalletOriginateParams,
} from "@taquito/taquito";

import {
Expand Down Expand Up @@ -70,15 +70,24 @@ export class TempleWallet implements WalletProvider {
}

async mapTransferParamsToWalletParams(params: WalletTransferParams) {
return createTransferOperation(params);
return this.removeDefaultParams(
params,
await createTransferOperation(this.formatParameters(params))
);
}

async mapOriginateParamsToWalletParams(params: WalletOriginateParams) {
return createOriginationOperation(params as any);
return this.removeDefaultParams(
params,
await createOriginationOperation(this.formatParameters(params))
);
}

async mapDelegateParamsToWalletParams(params: WalletDelegateParams) {
return createSetDelegateOperation(params as any);
return this.removeDefaultParams(
params,
await createSetDelegateOperation(this.formatParameters(params))
);
}

async sendOperations(opParams: any[]) {
Expand All @@ -95,6 +104,38 @@ export class TempleWallet implements WalletProvider {
assertConnected(this.permission);
return requestBroadcast(signedOpBytes);
}

private formatParameters(params: any) {
if (params.fee) {
params.fee = params.fee.toString();
}
if (params.storageLimit) {
params.storageLimit = params.storageLimit.toString();
}
if (params.gasLimit) {
params.gasLimit = params.gasLimit.toString();
}
return params;
}

private removeDefaultParams(
params: WalletTransferParams | WalletOriginateParams | WalletDelegateParams,
operatedParams: any
) {
// If fee, storageLimit or gasLimit is undefined by user
// in case of beacon wallet, dont override it by
// defaults.
if (!params.fee) {
delete operatedParams.fee;
}
if (!params.storageLimit) {
delete operatedParams.storage_limit;
}
if (!params.gasLimit) {
delete operatedParams.gas_limit;
}
return operatedParams;
}
}

export class NotConnectedTempleWalletError extends TempleWalletError {
Expand All @@ -117,6 +158,8 @@ function formatOpParams(op: any) {
return {
...rest,
mutez: true, // The balance was already converted from Tez (ꜩ) to Mutez (uꜩ)
fee,
gasLimit: gas_limit,
storageLimit: storage_limit,
};

Expand All @@ -128,12 +171,16 @@ function formatOpParams(op: any) {
amount: +amount,
mutez: true,
parameter: parameters,
fee,
gasLimit: gas_limit,
storageLimit: storage_limit,
};

default:
return {
...rest,
fee,
gasLimit: gas_limit,
storageLimit: storage_limit,
};
}
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */

/* Advanced Options */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
"forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
"skipLibCheck": true
},
"include": ["src"]
}

0 comments on commit e5aeb37

Please sign in to comment.