Skip to content

Commit

Permalink
refactor: check transaction type in result of contract call
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk authored and thepiwo committed May 10, 2023
1 parent 4a4081c commit 51bda26
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
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.

20 changes: 8 additions & 12 deletions src/stores/contractStore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineStore } from "pinia";
import { Contract, toAe } from "@aeternity/aepp-sdk";
import { Contract, toAe, Encoded, Tag } from "@aeternity/aepp-sdk";
import { Ref, ref } from "vue";
import { useSdkStore } from "./sdkStore";
import {
Expand All @@ -11,7 +11,6 @@ import {
Result,
} from "../utils/utils";
import "../utils/toJsonExtensions";
import { Encoded } from "@aeternity/aepp-sdk/es/utils/encoder";

export const useContractStore = defineStore("contract", () => {
const compileData: Ref<{ contractCode: string }> = ref({
Expand Down Expand Up @@ -165,14 +164,11 @@ export const useContractStore = defineStore("contract", () => {
contractInstance
?.$call(callStaticData.value.func, args, options)
.then((result) => {
if (result.tx.tag !== Tag.ContractCallTx) throw new Error('Unexpected transaction');
callStaticResult.value.setFinal(
`Dry-Run Gas Estimate: ${
result?.result?.gasUsed
// @ts-ignore
}, Fee Estimate: ${toAe(result?.tx?.fee)} ae (${
// @ts-ignore
result?.tx?.fee
} aetto)`,
}, Fee Estimate: ${toAe(result.tx.fee)} ae (${result.tx.fee} aetto)`,
JSON.stringify(result?.decodedResult)
);
})
Expand All @@ -192,12 +188,12 @@ export const useContractStore = defineStore("contract", () => {
contractInstance
?.$call(callData.value.func, args, options)
.then((result) => {
if (
result.tx.tag !== Tag.SignedTx || result.tx.encodedTx.tag !== Tag.ContractCallTx
) throw new Error('Unexpected transaction');
const { fee } = result.tx.encodedTx;
callResult.value.setFinal(
`Gas Used: ${result?.result?.gasUsed}, Fee: ${toAe(
// @ts-ignore
result?.tx?.encodedTx?.fee
// @ts-ignore
)} ae (${result?.tx?.encodedTx?.fee} aetto)`,
`Gas Used: ${result?.result?.gasUsed}, Fee: ${toAe(fee)} ae (${fee} aetto)`,
JSON.stringify(result?.decodedResult)
);
})
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"module": "es6",
"moduleResolution": "Node",
"strict": true,
"strictFunctionTypes": false,
"jsx": "preserve",
"resolveJsonModule": true,
"isolatedModules": false,
Expand Down

0 comments on commit 51bda26

Please sign in to comment.