From c28fc4b4b85fc3400308188928c1b4a000b11ff3 Mon Sep 17 00:00:00 2001 From: Viterbo Date: Tue, 9 Jul 2024 10:13:42 -0300 Subject: [PATCH] new FunctionOutputViewer component to show function responses --- .../ContractTab/FunctionInterface.vue | 23 +++-- .../ContractTab/FunctionOutputViewer.vue | 97 +++++++++++++++++++ src/types/TransactionQueryData.ts | 20 ++++ src/types/index.ts | 1 + 4 files changed, 134 insertions(+), 7 deletions(-) create mode 100644 src/components/ContractTab/FunctionOutputViewer.vue diff --git a/src/components/ContractTab/FunctionInterface.vue b/src/components/ContractTab/FunctionInterface.vue index 2897472c..22856e82 100644 --- a/src/components/ContractTab/FunctionInterface.vue +++ b/src/components/ContractTab/FunctionInterface.vue @@ -23,9 +23,10 @@ import { parameterTypeIsSignedIntArray, parameterTypeIsUnsignedIntArray, } from 'src/lib/function-interface-utils'; - import TransactionField from 'src/components/TransactionField.vue'; import LoginModal from 'components/LoginModal.vue'; +import FunctionOutputViewer from 'components/ContractTab/FunctionOutputViewer.vue'; +import { OutputType, OutputValue } from 'src/types'; interface Opts { value?: string; @@ -41,6 +42,7 @@ export default defineComponent({ ...asyncInputComponents, TransactionField, LoginModal, + FunctionOutputViewer, }, props: { contract: { @@ -83,6 +85,8 @@ export default defineComponent({ errorMessage: null as string | null, decimalOptions, result: null as string | null, // string | null + response: [] as OutputValue[], // OutputData[] + abiOutputs: [] as OutputType[], // OutputType[] hash: null as string | null, // string | null enterAmount: false, // boolean amountInput: 0, // number @@ -257,8 +261,10 @@ export default defineComponent({ runRead() { return this.getEthersFunction() .then(func => func(...this.params) - .then((response: string) => { - this.result = response; + .then((response: OutputValue | OutputValue[]) => { + this.result = response as unknown as string; + this.response = Array.isArray(response) ? response : [response]; + this.abiOutputs = this.abi.outputs as OutputType[]; this.errorMessage = null; }) .catch((msg: string) => { @@ -449,10 +455,13 @@ export default defineComponent({

{{ errorMessage }}

-
- {{ $t('components.contract_tab.result') }} ({{ abi?.outputs.length > 0 ? abi.outputs[0].type : '' }}): - {{ result }} - +
+ + +
{{ $t('components.contract_tab.view_transaction') }} diff --git a/src/components/ContractTab/FunctionOutputViewer.vue b/src/components/ContractTab/FunctionOutputViewer.vue new file mode 100644 index 00000000..28cce494 --- /dev/null +++ b/src/components/ContractTab/FunctionOutputViewer.vue @@ -0,0 +1,97 @@ + + + + + diff --git a/src/types/TransactionQueryData.ts b/src/types/TransactionQueryData.ts index eb068a9e..60138235 100644 --- a/src/types/TransactionQueryData.ts +++ b/src/types/TransactionQueryData.ts @@ -1,6 +1,26 @@ +import { BigNumber } from 'ethers'; + export interface TransactionQueryData { data: { results: { hash: string}[]; total_count: number; } } + +export type OutputValue = string | string[] | BigNumber | number | boolean | null; + +export interface OutputType { + name: string, + type: string, + internalType: string, + components?: OutputType[] +} + +export interface OutputData { + type: string; + value: OutputValue; +} + +export type OutputResult = { + [name: string]: OutputData | OutputResult +}; diff --git a/src/types/index.ts b/src/types/index.ts index b0bb3d0c..7f4673b4 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -4,3 +4,4 @@ export * from 'src/types/LatestContainerOptions'; export * from 'src/types/Pagination'; export * from 'src/types/ERCTransfer'; export * from 'src/types/NftTransfers'; +export * from 'src/types/TransactionQueryData';