Skip to content

Commit

Permalink
fix: personal group transactions (#1477)
Browse files Browse the repository at this point in the history
Signed-off-by: Svetoslav Borislavov <[email protected]>
Signed-off-by: Yordan Iliev <[email protected]>
Co-authored-by: Yordan Iliev <[email protected]>
  • Loading branch information
SvetBorislavov and yiliev0 authored Jan 23, 2025
1 parent a9ab092 commit 963eedf
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 50 deletions.
24 changes: 6 additions & 18 deletions automation/pages/GroupPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class GroupPage extends BasePage {

//Indexes
transactionTypeIndexSelector = 'span-transaction-type-';
transactionTimestampIndexSelector = 'span-transaction-timestamp-';
transactionTimestampIndexSelector = 'div-transaction-id-';
transactionDeleteButtonIndexSelector = 'button-transaction-delete-';
transactionDuplicateButtonIndexSelector = 'button-transaction-duplicate-';
transactionEditButtonIndexSelector = 'button-transaction-edit-';
Expand Down Expand Up @@ -294,28 +294,16 @@ class GroupPage extends BasePage {
console.log(`Attempt ${attempt}/${retries} to click "Sign All" button.`);

try {
// Attempt to click the button
await this.click(selector);
await new Promise(resolve => setTimeout(resolve, 2000));
const isButtonVisible = await this.isElementVisible(selector, null, 3000);

// Wait for it to disappear (tweak timeouts as needed)
await this.waitForElementToDisappear(selector, 10000, 30000);
if (!isButtonVisible) {
return;
}

// If no error was thrown, we succeeded — break out
console.log(
`Successfully clicked "Sign All" button and it disappeared on attempt #${attempt}.`,
);
return; // or break;
} catch (error) {
console.error(`Attempt #${attempt} to click "Sign All" button failed: ${error.message}`);

if (attempt < retries) {
console.log(`Retrying in ${retryDelay}ms...`);
await new Promise(resolve => setTimeout(resolve, retryDelay));
} else {
throw new Error(
`Failed to click "Sign All" button and wait for it to disappear after ${retries} attempts.`,
);
}
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions automation/tests/groupTransactionTests.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ test.describe('Group transaction tests', () => {

test('Verify user can execute group transaction', async () => {
await groupPage.addSingleTransactionToGroup();
const txId = await groupPage.getTransactionTimestamp(0);

await groupPage.clickOnSignAndExecuteButton();
const txId = await groupPage.getTransactionTimestamp(0);
await groupPage.clickOnConfirmGroupTransactionButton();

const transactionDetails = await transactionPage.mirrorGetTransactionResponse(txId);
Expand All @@ -231,11 +231,10 @@ test.describe('Group transaction tests', () => {
await groupPage.clickTransactionDuplicateButton(0);
await groupPage.clickTransactionDuplicateButton(0);

await groupPage.clickOnSignAndExecuteButton();
const txId = await groupPage.getTransactionTimestamp(0);
const secondTxId = await groupPage.getTransactionTimestamp(1);
const thirdTxId = await groupPage.getTransactionTimestamp(2);

await groupPage.clickOnSignAndExecuteButton();
await groupPage.clickOnConfirmGroupTransactionButton();

const transactionDetails = await transactionPage.mirrorGetTransactionResponse(txId);
Expand Down Expand Up @@ -267,10 +266,9 @@ test.describe('Group transaction tests', () => {
await groupPage.addSingleTransactionToGroup();
await groupPage.addSingleTransactionToGroup(1, true);

await groupPage.clickOnSignAndExecuteButton();
const txId = await groupPage.getTransactionTimestamp(0);
const secondTxId = await groupPage.getTransactionTimestamp(1);

await groupPage.clickOnSignAndExecuteButton();
await groupPage.clickOnConfirmGroupTransactionButton();

const transactionDetails = await transactionPage.mirrorGetTransactionResponse(txId);
Expand All @@ -292,8 +290,8 @@ test.describe('Group transaction tests', () => {

test('Verify transaction and linked group items and transaction group exists in db', async () => {
await groupPage.addSingleTransactionToGroup();
const txId = await groupPage.getTransactionTimestamp(0);
await groupPage.clickOnSignAndExecuteButton();
const txId = await groupPage.getTransactionTimestamp(0);
await groupPage.clickOnConfirmGroupTransactionButton();
expect(await groupPage.doTransactionGroupsExist(txId)).toBe(true);
});
Expand Down
4 changes: 2 additions & 2 deletions automation/tests/organizationGroupTests.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ test.describe('Organization Group Tx tests', () => {
test('Verify user can execute group transaction in organization', async () => {
test.slow();
await groupPage.addOrgAllowanceTransactionToGroup(2, complexKeyAccountId, '10');
const txId = await groupPage.getTransactionTimestamp(0);
const secondTxId = await groupPage.getTransactionTimestamp(1);

await groupPage.clickOnSignAndExecuteButton();
const txId = await groupPage.getTransactionTimestamp(0);
const secondTxId = await groupPage.getTransactionTimestamp(1);
await groupPage.clickOnConfirmGroupTransactionButton();
await groupPage.clickOnSignAllButton();
await loginPage.waitForToastToDisappear();
Expand Down
2 changes: 2 additions & 0 deletions front-end/src/renderer/components/EmptyTransactions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const isTransactionSelectionModalShown = ref(false);
<template v-if="['create-group', 'transactions-tab'].includes(mode)">
<div class="mt-3">
<AppButton
type="button"
class="text-main text-pink"
:size="'small'"
@click="isTransactionSelectionModalShown = true"
Expand All @@ -63,6 +64,7 @@ const isTransactionSelectionModalShown = ref(false);
<template v-if="['transactions-tab'].includes(mode)">
<div class="mt-2">
<AppButton
type="button"
class="text-main text-pink"
:size="'small'"
@click="router.push('/create-transaction-group')"
Expand Down
17 changes: 7 additions & 10 deletions front-end/src/renderer/components/GroupActionModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import { ref } from 'vue';
import { onBeforeRouteLeave, useRouter, useRoute } from 'vue-router';
import useTransactionGroupStore from '@renderer/stores/storeTransactionGroup';
import { redirectToPrevious } from '@renderer/utils';
import AppButton from '@renderer/components/ui/AppButton.vue';
import AppModal from '@renderer/components/ui/AppModal.vue';
Expand All @@ -15,9 +11,6 @@ const props = defineProps<{
skip?: boolean;
}>();
/* Stores */
const transactionGroup = useTransactionGroupStore();
/* Composables */
const router = useRouter();
const route = useRoute();
Expand All @@ -37,9 +30,13 @@ function handleEditItem() {
emit('editItem');
}
function handleDiscard() {
transactionGroup.clearGroup();
redirectToPrevious(router, '/transactions');
async function handleDiscard() {
const previousPath = router.previousPath;
if (previousPath !== '/create-transaction-group') {
await router.push('/create-transaction-group');
} else {
}
await router.push(previousPath || '/transactions');
}
function handleGroupAction() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import {
isLoggedInOrganization,
isUserLoggedIn,
getErrorMessage,
assertIsLoggedInOrganization,
} from '@renderer/utils';
import AppButton from '@renderer/components/ui/AppButton.vue';
Expand All @@ -60,6 +59,11 @@ const props = defineProps<{
watchExecutedModalShown?: (shown: boolean) => void;
}>();
/* Emits */
defineEmits<{
(event: 'abort'): void;
}>();
/* Stores */
const user = useUserStore();
const network = useNetworkStore();
Expand Down Expand Up @@ -121,7 +125,6 @@ async function signAfterConfirm() {
}
assertUserLoggedIn(user.personal);
assertIsLoggedInOrganization(user.selectedOrganization);
/* Verifies the user has entered his password */
const personalPassword = getPassword(signAfterConfirm, {
Expand Down Expand Up @@ -436,7 +439,10 @@ defineExpose({
<template #header>
<div class="d-flex flex-column w-100">
<div>
<i class="bi bi-x-lg cursor-pointer" @click="isConfirmShown = false"></i>
<i
class="bi bi-x-lg cursor-pointer"
@click="((isConfirmShown = false), $emit('abort'))"
></i>
</div>
<div class="text-center">
<i class="bi bi-arrow-left-right large-icon"></i>
Expand All @@ -447,13 +453,13 @@ defineExpose({
</template>
<template #default>
<div
v-for="groupItem in transactionGroup.groupItems"
v-for="(groupItem, index) in transactionGroup.groupItems"
:key="groupItem.transactionBytes.toString()"
class="px-5"
>
<div class="d-flex p-4 transaction-group-row justify-content-between">
<div>{{ getTransactionType(groupItem.transactionBytes) }}</div>
<div>
<div :data-testid="'div-transaction-id-' + index">
{{
groupItem.description != ''
? groupItem.description
Expand All @@ -470,7 +476,10 @@ defineExpose({
<hr class="separator m-5" />

<div class="flex-between-centered gap-4 w-100 px-5 pb-5">
<AppButton type="button" color="borderless" @click="isConfirmShown = false"
<AppButton
type="button"
color="borderless"
@click="((isConfirmShown = false), $emit('abort'))"
>Cancel</AppButton
>
<AppButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const transactionGroupProcessor = ref<typeof TransactionGroupProcessor | null>(n
const file = ref<HTMLInputElement | null>(null);
const wantToDeleteModalShown = ref(false);
const showAreYouSure = ref(false);
const updateValidStarts = ref(true);
const groupEmpty = computed(() => transactionGroup.groupItems.length == 0);
Expand Down Expand Up @@ -160,6 +161,7 @@ async function handleSignSubmit() {
}
try {
updateValidStarts.value = false;
transactionGroup.updateTransactionValidStarts(transactionGroup.groupValidStart);
const ownerKeys = new Array<PublicKey>();
for (const key of user.keyPairs) {
Expand All @@ -169,6 +171,7 @@ async function handleSignSubmit() {
await transactionGroupProcessor.value?.process(requiredKey);
} catch (error) {
updateValidStarts.value = true;
toast.error(getErrorMessage(error, 'Failed to create transaction'));
}
}
Expand Down Expand Up @@ -300,6 +303,9 @@ async function handleOnFileChanged(e: Event) {
function updateGroupValidStart(newDate: Date) {
transactionGroup.groupValidStart = newDate;
if (updateValidStarts.value) {
transactionGroup.updateTransactionValidStarts(transactionGroup.groupValidStart);
}
}
/* Functions */
Expand Down Expand Up @@ -527,6 +533,7 @@ onBeforeRouteLeave(async to => {
:on-close-success-modal-click="handleClose"
:on-executed="handleExecuted"
:on-submitted="handleSubmit"
@abort="updateValidStarts = true"
>
<template #successHeading>Transaction Group Executed Successfully</template>
</TransactionGroupProcessor>
Expand Down
19 changes: 11 additions & 8 deletions front-end/src/renderer/stores/storeTransactionGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,24 +239,27 @@ const useTransactionGroupStore = defineStore('transactionGroup', () => {
}

function updateTransactionValidStarts(newGroupValidStart: Date) {
groupItems.value = groupItems.value.map((item, index) => {
groupItems.value.forEach((groupItem, index) => {
const now = new Date();
if (item.validStart < now) {
if (groupItem.validStart < now) {
const updatedValidStart = findUniqueValidStart(
item.payerAccountId,
groupItem.payerAccountId,
newGroupValidStart.getTime() + index,
);
const transaction = Transaction.fromBytes(item.transactionBytes);
transaction.setTransactionId(createTransactionId(item.payerAccountId, updatedValidStart));
const transaction = Transaction.fromBytes(groupItem.transactionBytes);
transaction.setTransactionId(
createTransactionId(groupItem.payerAccountId, updatedValidStart),
);

return {
...item,
groupItems.value[index] = {
...groupItem,
transactionBytes: transaction.toBytes(),
validStart: updatedValidStart,
};
}
return item;
});
groupItems.value = [...groupItems.value];

setModified();
}

Expand Down

0 comments on commit 963eedf

Please sign in to comment.