diff --git a/src/components/contract/ContractActions.vue b/src/components/contract/ContractActions.vue index 912b7a82..7c9917d3 100644 --- a/src/components/contract/ContractActions.vue +++ b/src/components/contract/ContractActions.vue @@ -7,7 +7,7 @@ export default defineComponent({ name: 'ContractActions', components: { ViewTransaction }, setup() { - const memo = ref>({}); + const actionData = ref>({}); const permission = ref(''); const accountStore = useAccountStore(); const actor = ref(''); @@ -25,31 +25,45 @@ export default defineComponent({ ); async function signAction() { + const actDataObj = actionDataToObject(); await accountStore.sendAction({ name: action.value, actor: actor.value, permission: permission.value, - data: memo.value, + data: actDataObj, }); openTransaction.value = true; } - function formatMemo() { - for (let key in memo.value) { + function actionDataToObject() { + const obj: {[key: string]: unknown} = {}; + for (let key in actionData.value) { + const field = fields.value.find(val => val.name === key); + let value = actionData.value[key]; + if (typeof value === 'string' && field.type.endsWith('[]')) { + value = JSON.parse(value); + } + obj[key] = value; + } + return obj; + } + + function formatActionData() { + for (let key in actionData.value) { const field = fields.value.find(val => val.name === key); if (field.type === 'bool') { - memo.value[key] = memo.value[key] === 'true' || - memo.value[key] === '1' || - memo.value[key] === 'True' || - memo.value[key] === 'T' || - memo.value[key] === 't'; + actionData.value[key] = actionData.value[key] === 'true' || + actionData.value[key] === '1' || + actionData.value[key] === 'True' || + actionData.value[key] === 'T' || + actionData.value[key] === 't'; } } } watch(actions, () => { action.value = actions.value[0]; - memo.value = {}; + actionData.value = {}; }); onMounted(() => { @@ -61,14 +75,14 @@ export default defineComponent({ action, actions, fields, - memo, + memo: actionData, signAction, actor, permission, openTransaction, transactionId, transactionError, - formatMemo, + formatMemo: formatActionData, }; }, }); diff --git a/yarn.lock b/yarn.lock index 0199b981..a463fc3b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2680,10 +2680,10 @@ "@wharfkit/token" "^1.1.2" tslib "^2.1.0" -"@wharfkit/antelope@1.0.10": - version "1.0.10" - resolved "https://registry.yarnpkg.com/@wharfkit/antelope/-/antelope-1.0.10.tgz#5c63d6b67a4b62038575cd86ef47edaa8d1f57dd" - integrity sha512-12m4nD6+ZZl+mwzySuFkeiJCOrbXQT6mqg9amr1l/JtRewRdxeN9QTsEoPjE5MCTXbJc84X51KCT71ysglse0Q== +"@wharfkit/antelope@1.0.13": + version "1.0.13" + resolved "https://registry.yarnpkg.com/@wharfkit/antelope/-/antelope-1.0.13.tgz#216b28da9d9a91ece9db273447f4419aa770657f" + integrity sha512-f4O5O8+6Bd5BHpMUHTmlWQmlhX5xYb4AfzT2NJweyqIPqQOstm+aInF42AtUhSALDa8fvoY80YZoqwM0L8TUyw== dependencies: bn.js "^4.11.9" brorand "^1.1.0"