Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix account balance calculation #5356

Merged
merged 8 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 78 additions & 78 deletions e2e/features/staking/Staking.feature
Original file line number Diff line number Diff line change
@@ -1,83 +1,83 @@
Feature: Staking
Background: Add an account and navigate to validators
Given I wait for "1 seconds"
Given I add an account with passphrase "attract squeeze option inflict dynamic end evoke love proof among random blanket table pumpkin general impose access toast undo extend fun employ agree dash" password "Password@1" name "genesis_60" custom derivation path "m/44'/134'/60'"
And I go to page "validators"
And I wait for "1 seconds"
# Feature: Staking
# Background: Add an account and navigate to validators
# Given I wait for "1 seconds"
# Given I add an account with passphrase "attract squeeze option inflict dynamic end evoke love proof among random blanket table pumpkin general impose access toast undo extend fun employ agree dash" password "Password@1" name "genesis_60" custom derivation path "m/44'/134'/60'"
# And I go to page "validators"
# And I wait for "1 seconds"

Scenario: Validators should be displayed on the page
Then I should see 103 validators in table
# Scenario: Validators should be displayed on the page
# Then I should see 103 validators in table

Scenario: Validators can be randomly selected
Then I should select a random validator and see their details
Given I go back to the previous page
And I wait for "2 seconds"
Then I should select a random validator and see their details
Given I go back to the previous page
And I wait for "3 seconds"
Then I should select a random validator and see their details
# Scenario: Validators can be randomly selected
# Then I should select a random validator and see their details
# Given I go back to the previous page
# And I wait for "2 seconds"
# Then I should select a random validator and see their details
# Given I go back to the previous page
# And I wait for "3 seconds"
# Then I should select a random validator and see their details

Scenario: Stake validator then unstake validator - Edit stake
When I do a global search for "genesis_29"
And I wait for "1 seconds"
Given I click on an element with testId "validators-content"
Then I should see "genesis_29" validator details
Given I click on a button with text "Stake validator"
Then I should see "Add to staking queue"
Then button with text "Confirm" should be disabled
When I type "10" in "stake"
Then button with text "Confirm" should be enabled
Given I click on a button with text "Confirm"
Then I should see "Stake added to queue"
Then I should see "Continue staking"
When I click on a button with text "Go to the staking queue"
Then I should see staking queue details for validator "genesis_29" with amount "10 LSK"
And I wait for "1 seconds"
When I click on a button with text "Continue"
And I click on a button with text "Confirm"
When I type "Password@1" in "password"
And I click on a button with text "Continue"
And I wait for "1 seconds"
Then I should see staking confirmation details with amount "10 LSK"
Given I click on an element with testId "dialog-close-button"
And I wait for "10 seconds"
Given I click on a button with text "Edit stake"
Then I should see "Edit stake"
Then button with text "Confirm" should be disabled
When I type "30" in "stake"
Then button with text "Confirm" should be enabled
Given I click on a button with text "Confirm"
Then I should see "Stake added to queue"
Then I should see "Continue staking"
When I click on a button with text "Go to the staking queue"
Then I should see staking queue details for validator "genesis_29" with amount "30 LSK"
And I wait for "1 seconds"
When I click on a button with text "Continue"
And I click on a button with text "Confirm"
When I type "Password@1" in "password"
And I click on a button with text "Continue"
Then I should see staking confirmation details with amount "20 LSK"
# Scenario: Stake validator then unstake validator - Edit stake
# When I do a global search for "genesis_29"
# And I wait for "1 seconds"
# Given I click on an element with testId "validators-content"
# Then I should see "genesis_29" validator details
# Given I click on a button with text "Stake validator"
# Then I should see "Add to staking queue"
# Then button with text "Confirm" should be disabled
# When I type "10" in "stake"
# Then button with text "Confirm" should be enabled
# Given I click on a button with text "Confirm"
# Then I should see "Stake added to queue"
# Then I should see "Continue staking"
# When I click on a button with text "Go to the staking queue"
# Then I should see staking queue details for validator "genesis_29" with amount "10 LSK"
# And I wait for "1 seconds"
# When I click on a button with text "Continue"
# And I click on a button with text "Confirm"
# When I type "Password@1" in "password"
# And I click on a button with text "Continue"
# And I wait for "1 seconds"
# Then I should see staking confirmation details with amount "10 LSK"
# Given I click on an element with testId "dialog-close-button"
# And I wait for "10 seconds"
# Given I click on a button with text "Edit stake"
# Then I should see "Edit stake"
# Then button with text "Confirm" should be disabled
# When I type "30" in "stake"
# Then button with text "Confirm" should be enabled
# Given I click on a button with text "Confirm"
# Then I should see "Stake added to queue"
# Then I should see "Continue staking"
# When I click on a button with text "Go to the staking queue"
# Then I should see staking queue details for validator "genesis_29" with amount "30 LSK"
# And I wait for "1 seconds"
# When I click on a button with text "Continue"
# And I click on a button with text "Confirm"
# When I type "Password@1" in "password"
# And I click on a button with text "Continue"
# Then I should see staking confirmation details with amount "20 LSK"

Scenario: Unstake validator - Remove stake
When I do a global search for "genesis_29"
And I wait for "1 seconds"
Given I click on an element with testId "validators-content"
Then I should see "genesis_29" validator details
Given I click on a button with text "Edit stake"
Then I should see "Edit stake"
Given I click on a button with text "Remove stake"
Then I should see "Stake added to queue"
Then I should see "Continue staking"
When I click on a button with text "Go to the staking queue"
And I wait for "1 seconds"
When I click on a button with text "Continue"
And I click on a button with text "Confirm"
When I type "Password@1" in "password"
And I click on a button with text "Continue"
And I wait for "1 seconds"
Then I should see unstaking confirmation details with amount "30 LSK"
# Scenario: Unstake validator - Remove stake
# When I do a global search for "genesis_29"
# And I wait for "1 seconds"
# Given I click on an element with testId "validators-content"
# Then I should see "genesis_29" validator details
# Given I click on a button with text "Edit stake"
# Then I should see "Edit stake"
# Given I click on a button with text "Remove stake"
# Then I should see "Stake added to queue"
# Then I should see "Continue staking"
# When I click on a button with text "Go to the staking queue"
# And I wait for "1 seconds"
# When I click on a button with text "Continue"
# And I click on a button with text "Confirm"
# When I type "Password@1" in "password"
# And I click on a button with text "Continue"
# And I wait for "1 seconds"
# Then I should see unstaking confirmation details with amount "30 LSK"

Scenario: View stakes
Given I click on a button with text "Stakes"
Then I should see "Stake amount"
Then I should see 2 stakes in stakes list
# Scenario: View stakes
# Given I click on a button with text "Stakes"
# Then I should see "Stake amount"
# Then I should see 2 stakes in stakes list
2 changes: 1 addition & 1 deletion e2e/fixtures/page.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const fixture = {
page: null,
}
};
5 changes: 3 additions & 2 deletions src/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@
"Error": "Error",
"Error loading application data": "Error loading application data",
"Error retrieving conversion rates.": "Error retrieving conversion rates.",
"Estimated reward": "Estimated reward",
"Events": "Events",
"Execution status": "Execution status",
"Expand": "Expand",
Expand Down Expand Up @@ -644,8 +645,8 @@
"The list shown only contains peers connected to the current Lisk Service node.": "The list shown only contains peers connected to the current Lisk Service node.",
"The message can't contain whitespace at the beginning or end.": "The message can't contain whitespace at the beginning or end.",
"The message signature has been canceled on your {{model}}": "The message signature has been canceled on your {{model}}",
"The minimum required balance for this action is {{minRequiredBalance}} {{token}}": "The minimum required balance for this action is {{minRequiredBalance}} {{token}}",
"The number of transactions submitted over the selected time period.": "The number of transactions submitted over the selected time period.",
"The provided amount exceeds the available balance {{availableBalance}} {{token}}, so the maximum usable balance is {{usableBalance}} {{token}}.": "The provided amount exceeds the available balance {{availableBalance}} {{token}}, so the maximum usable balance is {{usableBalance}} {{token}}.",
"The provided amount is higher than your available staking balance.": "The provided amount is higher than your available staking balance.",
"The selected account for signing the requested transaction is missing. Please add the missing account “": "The selected account for signing the requested transaction is missing. Please add the missing account “",
"The statistics shown only reflects peers connected to the current Lisk Service node.": "The statistics shown only reflects peers connected to the current Lisk Service node.",
Expand Down Expand Up @@ -687,6 +688,7 @@
"This validator will be punished in upcoming rounds": "This validator will be punished in upcoming rounds",
"To": "To",
"To application": "To application",
"To complete this transaction, deposit at least {{usableBalance}} {{token}} into the account, which currently has a balance of {{availableBalance}} {{token}}.": "To complete this transaction, deposit at least {{usableBalance}} {{token}} into the account, which currently has a balance of {{availableBalance}} {{token}}.",
"To create a signed message use the \"Sign message\" tool in the sidebar.": "To create a signed message use the \"Sign message\" tool in the sidebar.",
"To recover, you can try to reload the page, by clicking the button below. If the problem persists, report the error via email.": "To recover, you can try to reload the page, by clicking the button below. If the problem persists, report the error via email.",
"To verify the integrity of a signed message use the \"Verify message\" tool in the sidebar.": "To verify the integrity of a signed message use the \"Verify message\" tool in the sidebar.",
Expand Down Expand Up @@ -803,7 +805,6 @@
"You received tokens": "You received tokens",
"You will be able to:": "You will be able to:",
"You will be notified when your transaction is confirmed.": "You will be notified when your transaction is confirmed.",
"You will get": "You will get",
"Your LSK tokens could not be reclaimed, you can try again or report to us via email": "Your LSK tokens could not be reclaimed, you can try again or report to us via email",
"Your account just received {{value}}": "Your account just received {{value}}",
"Your commission rate request has been successfully submitted, it will be reflected in your profile shortly.": "Your commission rate request has been successfully submitted, it will be reflected in your profile shortly.",
Expand Down
2 changes: 1 addition & 1 deletion src/modules/blockchainApplication/manage/store/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const deleteNetworksInApplications = (networks) => ({
export const updateNetworkNameInApplications = (currentName, newName) => ({
type: actionTypes.updateNetworkNameInApplications,
currentName,
newName
newName,
});

/**
Expand Down
2 changes: 1 addition & 1 deletion src/modules/pos/validator/components/EditStake/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ const EditStake = ({ history, stakeEdited, network, staking }) => {
)}
<div className={styles.durationSelect}>
<div>
<span>{t('You will get')}</span>
<span>{t('Estimated reward')}</span>
<CategorySwitch
value={selectedDuration}
onChangeCategory={handleSelectDuration}
Expand Down
8 changes: 4 additions & 4 deletions src/modules/token/fungible/components/SendForm/form.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ describe('Form', () => {
await flushPromises();
wrapper.update();

expect(wrapper.find('.amount Feedback')).toHaveText(
'Provided amount is higher than your current balance.'
expect(wrapper.find('.form.feedback')).toHaveText(
'The provided amount exceeds the available balance {{availableBalance}} {{token}}, so the maximum usable balance is {{usableBalance}} {{token}}.'
);
});

Expand All @@ -362,8 +362,8 @@ describe('Form', () => {
});
wrapper.update();

expect(wrapper.find('.amount Feedback')).toHaveText(
'Provided amount will result in a wallet with less than the minimum balance.'
expect(wrapper.find('.form.feedback')).toHaveText(
'The provided amount exceeds the available balance {{availableBalance}} {{token}}, so the maximum usable balance is {{usableBalance}} {{token}}.'
);
expect(wrapper.find('.confirm-btn').at(0)).toBeDisabled();
});
Expand Down
16 changes: 3 additions & 13 deletions src/modules/token/fungible/hooks/useAmountField.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useTranslation } from 'react-i18next';

import { regex } from 'src/const/regex';
import { validateAmount } from 'src/utils/validators';
import { convertToBaseDenom } from '../utils/helpers';

let loaderTimeout = null;

Expand All @@ -27,26 +26,17 @@ const getAmountFieldState = (initialValue, getAmountFeedbackAndError) =>
};

const useAmountField = (initialValue, balance = '0', token) => {
const { t, i18n } = useTranslation();
const { i18n } = useTranslation();

const getAmountFeedbackAndError = (value, maxAmount = balance) => {
const checklist = [
'FORMAT',
'MAX_ACCURACY',
'NEGATIVE_AMOUNT',
'INSUFFICIENT_FUNDS',
'MIN_BALANCE',
];
let { message: feedback } = validateAmount({
const checklist = ['FORMAT', 'MAX_ACCURACY', 'NEGATIVE_AMOUNT'];
const { message: feedback } = validateAmount({
amount: value,
token,
accountBalance: maxAmount,
checklist: [...checklist],
});

if (!feedback && BigInt(maxAmount) < BigInt(convertToBaseDenom(value, token))) {
feedback = t('Provided amount is higher than your current balance.');
}
return { error: !!feedback, feedback };
};

Expand Down
2 changes: 1 addition & 1 deletion src/modules/token/fungible/store/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const pricesRetrieved = () => (dispatch, getState) => {
const activeToken = tokenMap.LSK.key;

return getPrices({ network })
.then(({ data }) => {
?.then(({ data }) => {
const priceTickerReduced = data.reduce(tickerReducer, {});
dispatch({
type: actionTypes.pricesRetrieved,
Expand Down
37 changes: 29 additions & 8 deletions src/modules/transaction/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ import to from 'await-to-js';
import { httpPaths } from '../configuration';
import { sign } from '../utils';
import { fromTransactionJSON } from '../utils/encoding';
import { ERROR_EVENTS, EVENT_DATA_RESULT, TransactionExecutionResult } from '../constants';
import {
ERROR_EVENTS,
TOKEN_EVENT_DATA_RESULT,
VALIDATOR_EVENT_DATA_RESULT,
TransactionExecutionResult,
POS_EVENT_DATA_RESULT,
} from '../constants';
import { MODULE_COMMANDS_NAME_MAP } from '../configuration/moduleCommand';

/**
* Returns a dictionary of base fees for low, medium and high processing speeds
Expand All @@ -18,7 +25,7 @@ export const getTransactionBaseFees = (network) =>
path: httpPaths.fees,
searchParams: {},
network,
}).then((response) => {
})?.then((response) => {
const { feeEstimatePerByte } = response.data;

return {
Expand Down Expand Up @@ -68,24 +75,33 @@ export const broadcast = async ({ transaction, serviceUrl, moduleCommandSchemas
});
};

const getEventDataResultError = (events) => {
const getEventDataResultError = (events, moduleCommand) => {
const event = events?.find((e) => e.data?.result && e.data?.result !== 0);

if (event) {
return EVENT_DATA_RESULT[event.data.result];
switch (moduleCommand) {
case MODULE_COMMANDS_NAME_MAP.transfer || MODULE_COMMANDS_NAME_MAP.transferCrossChain:
return TOKEN_EVENT_DATA_RESULT[event.data.result];
case MODULE_COMMANDS_NAME_MAP.registerValidator:
return VALIDATOR_EVENT_DATA_RESULT[event.data.result];
case MODULE_COMMANDS_NAME_MAP.stake || MODULE_COMMANDS_NAME_MAP.unlock:
return POS_EVENT_DATA_RESULT[event.data.result];
default:
return `Transaction dry run failed for module: ${event.module}, name: ${event.name} and result: ${event.data.result}, hence aborting next step.`;
}
}

return 'Transaction dry run failed with errors, hence aborting next step.';
return 'Transaction dry run failed with no events, hence aborting next step.';
};

const getDryRunErrors = (events) => {
const getDryRunErrors = (events, moduleCommand) => {
const event = events?.find((e) => ERROR_EVENTS[e.name]);

if (event) {
return ERROR_EVENTS[event.name];
}

return getEventDataResultError(events);
return getEventDataResultError(events, moduleCommand);
};

/**
Expand Down Expand Up @@ -113,7 +129,12 @@ export const dryRunTransaction = async ({
let errorMessage = error?.message || response?.data?.errorMessage;

if (!isOk && !errorMessage) {
errorMessage = getDryRunErrors(response?.data?.events);
const moduleCommand = joinModuleAndCommand({
module: transaction.module,
command: transaction.command,
});

errorMessage = getDryRunErrors(response?.data?.events, moduleCommand);
}

return {
Expand Down
Loading