diff --git a/packages/e2e-tests/package-lock.json b/packages/e2e-tests/package-lock.json index 1f4622e086..a7d90bf5fe 100644 --- a/packages/e2e-tests/package-lock.json +++ b/packages/e2e-tests/package-lock.json @@ -9,6 +9,7 @@ "version": "0.1.0", "license": "ISC", "dependencies": { + "axios": "^1.6.8", "balanced-match": "^1.0.2", "brace-expansion": "^1.1.11", "concat-map": "^0.0.1", @@ -194,14 +195,12 @@ "node_modules/asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", - "dev": true + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, "node_modules/axios": { "version": "1.6.8", "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz", "integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==", - "dev": true, "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", @@ -507,7 +506,6 @@ "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "dev": true, "dependencies": { "delayed-stream": "~1.0.0" }, @@ -749,7 +747,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "dev": true, "engines": { "node": ">=0.4.0" } @@ -1119,7 +1116,6 @@ "version": "1.15.6", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", - "dev": true, "funding": [ { "type": "individual", @@ -1139,7 +1135,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", - "dev": true, "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", @@ -1918,7 +1913,6 @@ "version": "1.52.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", - "dev": true, "engines": { "node": ">= 0.6" } @@ -1927,7 +1921,6 @@ "version": "2.1.35", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", - "dev": true, "dependencies": { "mime-db": "1.52.0" }, @@ -2493,8 +2486,7 @@ "node_modules/proxy-from-env": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", - "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", - "dev": true + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" }, "node_modules/pump": { "version": "3.0.0", diff --git a/packages/e2e-tests/package.json b/packages/e2e-tests/package.json index f34ba53c36..92a17cff9c 100644 --- a/packages/e2e-tests/package.json +++ b/packages/e2e-tests/package.json @@ -49,6 +49,7 @@ "simple-node-logger": "^21.8.12" }, "dependencies": { + "axios": "^1.6.8", "balanced-match": "^1.0.2", "brace-expansion": "^1.1.11", "concat-map": "^0.0.1", diff --git a/packages/e2e-tests/pages/walletCommonBase.page.js b/packages/e2e-tests/pages/walletCommonBase.page.js index 62f8d7a10d..0df24a676b 100644 --- a/packages/e2e-tests/pages/walletCommonBase.page.js +++ b/packages/e2e-tests/pages/walletCommonBase.page.js @@ -46,6 +46,10 @@ class WalletCommonBase extends BasePage { locator: 'topBar:selectedWallet-availableBalance-text', method: 'id', }; + walletFiatBalanceTextLocator = { + locator: 'topBar:selectedWallet-availableFiatBalance-text', + method: 'id', + }; // change wallet modal window changeWalletDialogLocator = { locator: 'changeWalletDialog-dialogWindow-modalWindow', @@ -112,16 +116,25 @@ class WalletCommonBase extends BasePage { // functions async getSelectedWalletInfo() { this.logger.info(`WalletCommonBase::getSelectedWalletInfo is called`); + await this.waitForElement(this.walletNameAndPlateNumberTextLocator); const rawNameAndPlateText = await this.getText(this.walletNameAndPlateNumberTextLocator); + const [walletName, walletPlate] = rawNameAndPlateText.split('\n'); + await this.waitForElement(this.walletBalanceTextLocator); const rawBalanceText = await this.getText(this.walletBalanceTextLocator); - const [walletName, walletPlate] = rawNameAndPlateText.split('\n'); const adaBalance = Number(rawBalanceText.split(' ')[0]); + + const rawFiatBalanceText = await this.getText(this.walletFiatBalanceTextLocator); + const [fiatBalanceStr, fiatCurrency] = rawFiatBalanceText.split(' '); + const fiatBalance = fiatBalanceStr === '-' ? 0 : Number(fiatBalanceStr); + const walletInfo = { name: walletName, plate: walletPlate, balance: adaBalance, + fiatBalance, + fiatCurrency, }; this.logger.info( `WalletCommonBase::getSelectedWalletInfo::walletInfo is ${JSON.stringify(walletInfo)}` diff --git a/packages/e2e-tests/test/19_changingFiat.test.js b/packages/e2e-tests/test/19_changingFiat.test.js new file mode 100644 index 0000000000..8fa2a8718c --- /dev/null +++ b/packages/e2e-tests/test/19_changingFiat.test.js @@ -0,0 +1,79 @@ +import BasePage from '../pages/basepage.js'; +import { customAfterEach } from '../utils/customHooks.js'; +import TransactionsSubTab from '../pages/wallet/walletTab/walletTransactions.page.js'; +import { testWallet1 } from '../utils/testWallets.js'; +import { expect } from 'chai'; +import { getTestLogger, roundUpCurrency } from '../utils/utils.js'; +import { oneMinute } from '../helpers/timeConstants.js'; +import { restoreWallet } from '../helpers/restoreWalletHelper.js'; +import SettingsTab from '../pages/wallet/settingsTab/settingsTab.page.js'; +import driversPoolsManager from '../utils/driversPool.js'; +import GeneralSubTab from '../pages/wallet/settingsTab/generalSubTab.page.js'; +import axios from 'axios'; + +const reqResponse = await axios.get('https://iohk-mainnet.yoroiwallet.com/api/price/ADA/current'); +const prices = reqResponse.data.ticker.prices; + +describe('Changing fiat currencies', function () { + this.timeout(2 * oneMinute); + let webdriver = null; + let logger = null; + + before(function (done) { + webdriver = driversPoolsManager.getDriverFromPool(); + logger = getTestLogger(this.test.parent.title); + done(); + }); + + const testData = ['BRL', 'ETH', 'BTC', 'KRW', 'CNY', 'EUR', 'JPY', 'USD', 'ADA']; + + it('Restore a 15-word wallet', async function () { + await restoreWallet(webdriver, logger, testWallet1); + const transactionsPage = new TransactionsSubTab(webdriver, logger); + const txPageIsDisplayed = await transactionsPage.isDisplayed(); + expect(txPageIsDisplayed, 'The transactions page is not displayed').to.be.true; + }); + + for (const testDatum of testData) { + describe(`Changing fiat currency to ${testDatum}`, function () { + it('Open General settings', async function () { + const transactionsPage = new TransactionsSubTab(webdriver, logger); + await transactionsPage.goToSettingsTab(); + const settingsPage = new SettingsTab(webdriver, logger); + await settingsPage.goToGeneralSubMenu(); + }); + + it('Select currency', async function () { + const generalSubTab = new GeneralSubTab(webdriver, logger); + await generalSubTab.selectFiat(testDatum); + }); + + it('Check the selected currency is applied', async function () { + const generalSubTab = new GeneralSubTab(webdriver, logger); + await generalSubTab.goToWalletTab(); + const walletInfo = await generalSubTab.getSelectedWalletInfo(); + if (testDatum === 'ADA') { + expect(walletInfo.fiatBalance, 'Fiat balance is different').to.equal(0); + } else { + expect(walletInfo.fiatCurrency, 'Fiat currency is different').to.equal(testDatum); + const expectedFiatValue = roundUpCurrency( + prices[testDatum] * walletInfo.balance, + testDatum + ); + expect(walletInfo.fiatBalance, 'Fiat balance is different').to.equal(expectedFiatValue); + } + }); + }); + } + + afterEach(function (done) { + customAfterEach(this, webdriver, logger); + done(); + }); + + after(function (done) { + const basePage = new BasePage(webdriver, logger); + basePage.closeBrowser(); + done(); + }); +}); diff --git a/packages/e2e-tests/utils/utils.js b/packages/e2e-tests/utils/utils.js index 6ec20eb4c0..213aa19e9f 100644 --- a/packages/e2e-tests/utils/utils.js +++ b/packages/e2e-tests/utils/utils.js @@ -235,3 +235,12 @@ export const convertPrettyTimeToNormal = prettyTime => { } return `${hours}:${minutes}:00`; }; + +export const roundUpCurrency = (value, fiatCurrency) => { + const cryptoFiats = ['ETH', 'BTC']; + if (cryptoFiats.includes(fiatCurrency)) { + return Number(parseFloat(value).toFixed(6)); + } else { + return Number(parseFloat(value).toFixed(2)); + } +}; diff --git a/packages/yoroi-extension/app/components/common/AmountDisplay.js b/packages/yoroi-extension/app/components/common/AmountDisplay.js index 2a116a1044..e8f3b2a3f5 100644 --- a/packages/yoroi-extension/app/components/common/AmountDisplay.js +++ b/packages/yoroi-extension/app/components/common/AmountDisplay.js @@ -91,7 +91,7 @@ export default class AmountDisplay extends Component { )} {showFiat === true && ( -
+
{fiatDisplay || '-'} {currency || 'USD'}
)}