Skip to content

Commit

Permalink
Provide how much balance was transferred to the transfer account id w…
Browse files Browse the repository at this point in the history
…hen deleting an account (#589)

Signed-off-by: Martin Dobrev <[email protected]>
Signed-off-by: Yordan Iliev <[email protected]>
Co-authored-by: Yordan Iliev <[email protected]>
  • Loading branch information
RAMTO and yiliev0 authored Jul 2, 2024
1 parent 44399f2 commit c1cc65a
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 16 deletions.
5 changes: 5 additions & 0 deletions automation/pages/DetailsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class DetailsPage extends BasePage {
accountUpdateDetailsIdSelector = 'p-account-details-id';
accountDeleteDetailsDeletedAccountIdSelector = 'p-account-delete-details-account-id';
accountDeleteDetailsTransferIdSelector = 'p-account-delete-details-transfer-account-id';
accountDeleteDetailsTransferAmountSelector = 'p-account-delete-details-transfer-amount';
transferDetailsFromAccountSelector = 'p-transfer-from-account-details';
transferDetailsFromAmountSelector = 'p-transfer-from-amount-details';
transferDetailsToAccountSelector = 'p-transfer-to-account-details';
Expand Down Expand Up @@ -136,6 +137,10 @@ class DetailsPage extends BasePage {
return await this.getTextByTestId(this.accountDeleteDetailsTransferIdSelector);
}

async getAccountDeleteDetailsTransferAmount() {
return await this.getTextByTestId(this.accountDeleteDetailsTransferAmountSelector);
}

async getTransferDetailsFromAccount() {
return await this.getTextByTestId(this.transferDetailsFromAccountSelector);
}
Expand Down
7 changes: 5 additions & 2 deletions automation/tests/workflowTests.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,11 @@ test.describe('Workflow tests', () => {
const getDeletedAccountId = await detailsPage.getDeletedAccountId();
expect(getDeletedAccountId).toBe(accountFromList);

const getAccountDetailsKey = await detailsPage.getAccountDeleteDetailsTransferId();
expect(getAccountDetailsKey).toBeTruthy();
const getTransferAccountId = await detailsPage.getAccountDeleteDetailsTransferId();
expect(getTransferAccountId).toBeTruthy();

const getTransferAmount = await detailsPage.getAccountDeleteDetailsTransferAmount();
expect(getTransferAmount).toBeTruthy();
},
);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { onBeforeMount, onBeforeUnmount, ref } from 'vue';
import { onBeforeMount, onBeforeUnmount, ref, nextTick, watch } from 'vue';

Check warning on line 2 in front-end/src/renderer/pages/TransactionDetails/compontents/AccountDetails.vue

View workflow job for this annotation

GitHub Actions / Build front-end

'nextTick' is defined but never used

Check warning on line 2 in front-end/src/renderer/pages/TransactionDetails/compontents/AccountDetails.vue

View workflow job for this annotation

GitHub Actions / Build front-end

'nextTick' is defined but never used
import {
AccountCreateTransaction,
Expand Down Expand Up @@ -79,16 +79,7 @@ async function fetchTransactionInfo(payer: string, seconds: string, nanos: strin
}
}
/* Hooks */
onBeforeMount(async () => {
if (
!(
props.transaction instanceof AccountCreateTransaction ||
props.transaction instanceof AccountUpdateTransaction
)
) {
throw new Error('Transaction is not Account Create or Update Transaction');
}
async function checkAndFetchTransactionInfo() {
if (!isUserLoggedIn(user.personal)) throw new Error('User not logged in');
const isExecutedOrganizationTransaction = Boolean(
Expand Down Expand Up @@ -123,12 +114,31 @@ onBeforeMount(async () => {
},
});
}
}
/* Hooks */
onBeforeMount(async () => {
if (
!(
props.transaction instanceof AccountCreateTransaction ||
props.transaction instanceof AccountUpdateTransaction
)
) {
throw new Error('Transaction is not Account Create or Update Transaction');
}
await checkAndFetchTransactionInfo();
});
onBeforeUnmount(() => {
controller.value?.abort();
});
/* Watchers */
watch([() => props.transaction, () => props.organizationTransaction], async () => {
setTimeout(async () => await checkAndFetchTransactionInfo(), 3000);
});
/* Misc */
const detailItemLabelClass = 'text-micro text-semi-bold text-dark-blue';
const detailItemValueClass = 'text-small overflow-hidden mt-1';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,95 @@
<script setup lang="ts">
import { onBeforeMount } from 'vue';
import { onBeforeMount, onBeforeUnmount, ref, watch } from 'vue';
import { Transaction, AccountDeleteTransaction } from '@hashgraph/sdk';
import { Transaction, AccountDeleteTransaction, Hbar, HbarUnit } from '@hashgraph/sdk';
import { ITransactionFull, TransactionStatus } from '@main/shared/interfaces';
import useNetworkStore from '@renderer/stores/storeNetwork';
import { getTransactionInfo } from '@renderer/services/mirrorNodeDataService';
import { stringifyHbar } from '@renderer/utils';
/* Props */
const props = defineProps<{
transaction: Transaction;
organizationTransaction: ITransactionFull | null;
}>();
/* Stores */
const network = useNetworkStore();
/* State */
const controller = ref<AbortController | null>(null);
const transferredAmount = ref<Hbar | undefined>(new Hbar(0));
/* Functions */
async function fetchTransactionInfo(payer: string, seconds: string, nanos: string) {
try {
const { transactions } = await getTransactionInfo(
`${payer}-${seconds}-${nanos}`,
network.mirrorNodeBaseURL,
controller.value || undefined,
);
if (transactions.length > 0 && props.transaction instanceof AccountDeleteTransaction) {
const deletedAccountId = props.transaction.accountId?.toString();
const amount =
transactions[0].transfers?.find(
transfer => transfer.account?.toString() === deletedAccountId,
)?.amount || 0;
transferredAmount.value = Hbar.from(Math.abs(amount), HbarUnit.Tinybar);
}
} catch (error) {
/* Ignore if transaction not available in mirror node */
}
}
async function checkAndFetchTransactionInfo() {
const isExecutedOrganizationTransaction = Boolean(
props.organizationTransaction?.status &&
[TransactionStatus.EXECUTED, TransactionStatus.FAILED].includes(
props.organizationTransaction.status,
),
);
if (
(isExecutedOrganizationTransaction || !props.organizationTransaction) &&
props.transaction instanceof AccountDeleteTransaction
) {
controller.value = new AbortController();
const payer = props.transaction.transactionId?.accountId?.toString();
const seconds = props.transaction.transactionId?.validStart?.seconds?.toString();
const nanos = props.transaction.transactionId?.validStart?.nanos?.toString();
if (payer && seconds && nanos) {
if (!props.organizationTransaction) {
setTimeout(async () => await fetchTransactionInfo(payer, seconds, nanos), 1500);
} else {
await fetchTransactionInfo(payer, seconds, nanos);
}
}
}
}
/* Hooks */
onBeforeMount(() => {
onBeforeMount(async () => {
if (!(props.transaction instanceof AccountDeleteTransaction)) {
throw new Error('Transaction is not Account Delete Transaction');
}
await checkAndFetchTransactionInfo();
});
onBeforeUnmount(() => {
controller.value?.abort();
});
/* Watchers */
watch([() => props.transaction, () => props.organizationTransaction], async () => {
setTimeout(async () => await checkAndFetchTransactionInfo(), 3000);
});
/* Misc */
Expand All @@ -37,5 +114,13 @@ const commonColClass = 'col-6 col-lg-5 col-xl-4 col-xxl-3 overflow-hidden py-3';
{{ transaction.transferAccountId.toString() }}
</p>
</div>

<!-- Transfered amount -->
<div v-if="transferredAmount?.toBigNumber().gt(0)" :class="commonColClass">
<h4 :class="detailItemLabelClass">Transferred Amount</h4>
<p :class="detailItemValueClass" data-testid="p-account-delete-details-transfer-amount">
{{ stringifyHbar((transferredAmount as Hbar) || new Hbar(0)) }}
</p>
</div>
</div>
</template>

0 comments on commit c1cc65a

Please sign in to comment.