diff --git a/apps/blog/playwright/tests/e2e/profilePage.spec.ts b/apps/blog/playwright/tests/e2e/profilePage.spec.ts index a70187ac98767663730e633d6e02e003c46dc349..572853e65c21ad15be7c2a29704d424f9df4ad9d 100644 --- a/apps/blog/playwright/tests/e2e/profilePage.spec.ts +++ b/apps/blog/playwright/tests/e2e/profilePage.spec.ts @@ -64,8 +64,8 @@ test.describe('Profile page of @gtg', () => { data: { id: 0, jsonrpc: '2.0', - method: 'condenser_api.get_follow_count', - params: ['gtg'] + method: 'follow_api.get_follow_count', + params: { account: 'gtg' } }, headers: { Accept: 'application/json, text/plain, */*' diff --git a/apps/blog/playwright/tests/e2e/witnessesPage.spec.ts b/apps/blog/playwright/tests/e2e/witnessesPage.spec.ts index 59eee808012a039be2f2f93d48b28b6b2dc34027..b2ee317535ee502975b973d21b9809d232d582d0 100644 --- a/apps/blog/playwright/tests/e2e/witnessesPage.spec.ts +++ b/apps/blog/playwright/tests/e2e/witnessesPage.spec.ts @@ -70,7 +70,7 @@ test.describe.skip('Witnesses page tests', () => { await homePage.moveToNavWitnessesPage(); // First witness's info from API - const firstWitnessInfoAPI = (await apiHelper.getListWitnessesByVoteAPI('', 5)).result[0]; // blocktrades expected + const firstWitnessInfoAPI = (await apiHelper.getListWitnessesByVoteAPI('', 5)).result.witnesses[0]; // blocktrades expected const nameFirstWitnessAPI = await firstWitnessInfoAPI.owner; const lastConfirmedBlockNumberOfFirstWitnessAPI = await firstWitnessInfoAPI.last_confirmed_block_num; const runningVersionOfFirstWitnessAPI = await firstWitnessInfoAPI.running_version; diff --git a/apps/blog/playwright/tests/support/apiHelper.ts b/apps/blog/playwright/tests/support/apiHelper.ts index 7e868f302443174cef59b1e5baa5cf1e69ad5862..387afeb368130b38afb1f35388d43c0892a1d82a 100644 --- a/apps/blog/playwright/tests/support/apiHelper.ts +++ b/apps/blog/playwright/tests/support/apiHelper.ts @@ -27,15 +27,15 @@ export class ApiHelper { } // Get Follow count info as json from API response - async getFollowCountAPI(username: string) { + async getFollowCountAPI(account: string) { const url = process.env.REACT_APP_API_ENDPOINT; const responseGetFollowCount = await this.page.request.post(`${url}/`, { data: { id: 0, jsonrpc: '2.0', - method: 'condenser_api.get_follow_count', - params: [`${username}`] + method: 'follow_api.get_follow_count', + params: { account } }, headers: { Accept: 'application/json, text/plain, */*' @@ -111,8 +111,8 @@ export class ApiHelper { data: { id: 0, jsonrpc: '2.0', - method: 'condenser_api.get_witnesses_by_vote', - params: [`${startName}`, `${limit}`] + method: 'database_api.list_witnesses', + params: { start: [0, startName], limit, order: 'by_vote_name' } }, headers: { Accept: 'application/json, text/plain, */*' @@ -130,8 +130,8 @@ export class ApiHelper { data: { id: 0, jsonrpc: '2.0', - method: 'condenser_api.get_dynamic_global_properties', - params: [] + method: 'database_api.get_dynamic_global_properties', + params: {} }, headers: { Accept: 'application/json, text/plain, */*' diff --git a/apps/blog/playwright/tests/testnet_e2e/followUser.spec.ts b/apps/blog/playwright/tests/testnet_e2e/followUser.spec.ts index 5cb381a90c44ab2561a5144ada583f579877d632..1cd025ab8cf701d629581d98c345acc7da7e6817 100644 --- a/apps/blog/playwright/tests/testnet_e2e/followUser.spec.ts +++ b/apps/blog/playwright/tests/testnet_e2e/followUser.spec.ts @@ -5,7 +5,7 @@ import { ProfilePage } from '../support/pages/profilePage'; import { PostPage } from '../support/pages/postPage'; // Unskip these tests after fixing -// - "condenser_api.get_follow_count" will return correct value for following_count, +// - "follow_api.get_follow_count" will return correct value for following_count, // - and Optimistic UI will work correctly test.describe.skip('Follow user - tests', () => { let profileUserMenu: ProfileUserMenu; diff --git a/apps/wallet/components/financial-report.tsx b/apps/wallet/components/financial-report.tsx index 591b6a8e2832eeea893225eac1b0bbd39ab06761..cf7bafa9aca118a60c1d748332150e527a56b746 100644 --- a/apps/wallet/components/financial-report.tsx +++ b/apps/wallet/components/financial-report.tsx @@ -65,17 +65,18 @@ const convertHistoryToCSV = (transactions: AccountHistory[]) => { transactions.forEach((transaction) => { console.log(transaction); + const opData = transaction[1].op[1]; const formatted = [ transaction[1].timestamp, transaction[1].op[0], - transaction[1].op[1].amount, - transaction[1].op[1].from, - transaction[1].op[1].to, - transaction[1].op[1].memo, - transaction[1].op[1].account, - transaction[1].op[1].reward_hive, - transaction[1].op[1].reward_hbd, - transaction[1].op[1].reward_hive + opData.amount, + opData.from, + opData.to, + opData.memo, + opData.account, + opData.reward_hive, + opData.reward_hbd, + opData.reward_hive // 'payout_must_be_claimed', // 'permlink', // 'vesting_payout', @@ -106,7 +107,7 @@ const downloadCSV = (csv: string) => { const generateReport = async (username: string, financialPeriod: FinancialReportPeriod) => { const transactions = await getAccountHistory(username, -1, 1000); const filtered = transactions.filter((transaction) => { - const opType = transaction[1].op!.at(0); + const opType = transaction[1].op![0]; if (!!opType) { return ( opTypes.includes(opType as OpType) && diff --git a/apps/wallet/components/hooks/use-trade-history.ts b/apps/wallet/components/hooks/use-trade-history.ts index a0b791736bde50bce8aef67696373ba628e7ee7a..1c6c0f7907993f323a26b9d3f02d2dec627c5ec8 100644 --- a/apps/wallet/components/hooks/use-trade-history.ts +++ b/apps/wallet/components/hooks/use-trade-history.ts @@ -11,8 +11,8 @@ export const useTradeHistory = (config?: useTradeHistoryOptions) => { select: (data) => { return data.map((e) => ({ ...e, - hbd: convertStringToBig(e.current_pays.includes('HBD') ? e.current_pays : e.open_pays), - hive: convertStringToBig(e.current_pays.includes('HIVE') ? e.current_pays : e.open_pays) + hbd: convertStringToBig(e.current_pays.nai === '@@000000013' ? e.current_pays : e.open_pays), + hive: convertStringToBig(e.current_pays.nai === '@@000000021' ? e.current_pays : e.open_pays) })); } }); diff --git a/apps/wallet/components/market-table.tsx b/apps/wallet/components/market-table.tsx index 785b9439eeef93eb386082675add8f45be88091d..0fbae00acccf907590377fff6c6118ee2ad86882 100644 --- a/apps/wallet/components/market-table.tsx +++ b/apps/wallet/components/market-table.tsx @@ -4,6 +4,8 @@ import { useState } from 'react'; import { dateToRelative } from '@ui/lib/parse-date'; import Big from 'big.js'; import { useTranslation } from 'next-i18next'; +import { NaiAsset } from '@hiveio/wax'; +import { HIVE_NAI_STRING, HBD_NAI_STRING } from '@transaction/lib/utils'; export interface OrdersItem { total: number; @@ -11,8 +13,8 @@ export interface OrdersItem { hbd: number; hive: number; order_price: { - base: string; - quote: string; + base: NaiAsset; + quote: NaiAsset; }; real_price: string; } @@ -20,8 +22,8 @@ type TradeHistory = { hbd: Big; hive: Big; date: string; - current_pays: string; - open_pays: string; + current_pays: NaiAsset; + open_pays: NaiAsset; }; const PAGE_SIZE = 10; export function MarketTable({ @@ -150,8 +152,8 @@ export function HistoryTable({ data, params, label }: { data: any[]; params: str {dateToRelative(e.date, t)} {e.hbd.div(e.hive).toFixed(6)} diff --git a/apps/wallet/components/open-orders.tsx b/apps/wallet/components/open-orders.tsx index b2fe9f059f97c6a31af34d504a04a89f69932c46..3b7010ae3cb98db92f067e85f913fe81a200f1a4 100644 --- a/apps/wallet/components/open-orders.tsx +++ b/apps/wallet/components/open-orders.tsx @@ -1,5 +1,5 @@ import clsx from 'clsx'; -import { IOpenOrdersData } from '@transaction/lib/extended-hive.chain'; +import { IOpenOrdersData } from '@transaction/lib/extended-hive.chain'; import { useTranslation } from 'next-i18next'; import { Button, Dialog, DialogContent, DialogFooter, DialogTrigger } from '@ui/components'; import { dateToFormatted } from '@ui/lib/parse-date'; @@ -68,10 +68,10 @@ const OpenOrders: React.FC = ({ user, orders, loading }) => { {orders && orders.length ? ( (sortAsc ? orders : orders.toReversed()).map((order: IOpenOrdersData) => { const currency = [ - order.sell_price.base.split(' ')[0], - order.sell_price.quote.split(' ')[0] + order.sell_price.base.amount, + order.sell_price.quote.amount ]; - if (order.sell_price.base.includes('HBD')) currency.reverse(); + if (order.sell_price.base.nai === '@@000000013') currency.reverse(); return ( @@ -79,7 +79,7 @@ const OpenOrders: React.FC = ({ user, orders, loading }) => { {dateToFormatted(order.created, 'YYYY-MM-DD HH:mm:ss')} - {order.sell_price.base.includes('HIVE') + {order.sell_price.base.nai === '@@000000021' ? t('market_page.sell') : t('market_page.buy')} @@ -88,7 +88,7 @@ const OpenOrders: React.FC = ({ user, orders, loading }) => { {currency[1]} {( - (1 - order.for_sale / 1000 / parseFloat(order.sell_price.base.split(' ')[0])) * + (1 - order.for_sale / 1000 / parseFloat(order.sell_price.base.amount)) * 100 ).toFixed(2)} % diff --git a/apps/wallet/components/trade-hive.tsx b/apps/wallet/components/trade-hive.tsx index 09c282469a7bb000afe9075e6465c830358dfa1a..f0a027699cbe1a1c0de0e0af64236489c6ecec7c 100644 --- a/apps/wallet/components/trade-hive.tsx +++ b/apps/wallet/components/trade-hive.tsx @@ -12,11 +12,12 @@ import { useUser } from '@smart-signer/lib/auth/use-user'; import { getOpenOrder } from '../lib/hive'; import OpenOrders from './open-orders'; import { useQuery } from '@tanstack/react-query'; +import { NaiAsset } from '@hiveio/wax'; interface Market { - hbd_volume: string; + hbd_volume: NaiAsset; highest_bid: Big; - hive_volume: string; + hive_volume: NaiAsset; latest: string; lowest_ask: Big; percent_change: string; diff --git a/apps/wallet/components/witnesses-list-item.tsx b/apps/wallet/components/witnesses-list-item.tsx index 76cf12e026ce4ff0340f3b38af79ddd860d5e1e0..d885f6d1dc0e8377a01e1eab303f9e7966da11d4 100644 --- a/apps/wallet/components/witnesses-list-item.tsx +++ b/apps/wallet/components/witnesses-list-item.tsx @@ -271,7 +271,7 @@ function WitnessListItem({
- ${parseFloat(data.hbd_exchange_rate.base)} + ${parseFloat(data.hbd_exchange_rate.base.amount)}
diff --git a/apps/wallet/lib/hive.ts b/apps/wallet/lib/hive.ts index 1c02eef7442a63a330360fb0164e003bdd44e89d..08c105d664e502a9a51fb9df661222bc152104f0 100644 --- a/apps/wallet/lib/hive.ts +++ b/apps/wallet/lib/hive.ts @@ -18,7 +18,6 @@ import { AccountHistory, AccountRewardsHistory, IDelegatedVestingShare, - OwnerHistory, IRecentTradesData, IOrdersDataItem, IOpenOrdersData, @@ -27,6 +26,8 @@ import { IWitness, IDirectDelegation, IGetOperationsByAccountResponse, + ITradesData, + IOwnerHistory, } from '@transaction/lib/extended-hive.chain'; import { commonVariables } from '@ui/lib/common-variables'; @@ -40,7 +41,7 @@ export type ProposalData = Omit & { }; export const getWitnessesByVote = async (from: string, limit: number): Promise => { - return chain.api.condenser_api.get_witnesses_by_vote([from, limit]); + return (await chain.api.database_api.list_witnesses({ start: [9223372036854775807n.toString(), from], limit, order: 'by_vote_name' })).witnesses; }; export const findRcAccounts = async (username: string): Promise<{ rc_accounts: RcAccount[] }> => { @@ -83,7 +84,7 @@ export const getVestingDelegations = async ( from: string = '', limit: number = 50 ): Promise => { - return chain.api.condenser_api.get_vesting_delegations([username, from, limit]); + return (await chain.api.database_api.list_vesting_delegations({ start: [username, from], limit, order: 'by_delegation' })).delegations; }; const op = operationOrders; @@ -105,17 +106,21 @@ const wallet_operations_bitmask = [ op.claim_reward_balance ]; +const wallet_operations_filter = makeBitMaskFilter(wallet_operations_bitmask); + export const getAccountHistory = async ( username: string, start: number = -1, limit: number = 20 ): Promise => { - return chain.api.condenser_api.get_account_history([ - username, - start, + const response = await chain.api.account_history_api.get_account_history({ + account: username, + start: start.toString(), limit, - ...wallet_operations_bitmask - ]) as Promise; + operation_filter_low: wallet_operations_filter[0], + operation_filter_high: wallet_operations_filter[1] + }); + return response.history; }; export const getAccountOperations = async ( @@ -171,12 +176,15 @@ export const getAccountRewardsHistory = async ( start: number = -1, limit: number = 20 ): Promise => { - return chain.api.condenser_api.get_account_history([ - username, - start, + const response = await chain.api.account_history_api.get_account_history({ + account: username, + start: start.toString(), limit, - ...wallet_rewards_history_bitmask - ]) as Promise; + operation_filter_low: wallet_rewards_history_bitmask[0], + operation_filter_high: wallet_rewards_history_bitmask[1] + }); + + return response.history as unknown as Promise; }; export const getProposalVotes = async ( @@ -196,15 +204,15 @@ export const getUserVotes = async (voter: string, limit: number = 1000): Promise }; export const getMarketStatistics = async (): Promise => { - return chain.api.condenser_api.get_ticker([]); + return chain.api.market_history_api.get_ticker({}); }; export const getOrderBook = async (limit: number = 500): Promise => { - return chain.api.condenser_api.get_order_book([limit]); + return chain.api.market_history_api.get_order_book({ limit }); }; export const getOpenOrder = async (user: string): Promise => { - return chain.api.condenser_api.get_open_orders([user]); + return (await chain.api.database_api.list_limit_orders({ start: [user, 0], limit: 100, order: 'by_account' })).orders; }; type GetTradeHistoryData = { @@ -213,22 +221,22 @@ type GetTradeHistoryData = { }; }; -export const getTradeHistory = async (limit: number = 1000): Promise => { +export const getTradeHistory = async (limit: number = 1000): Promise => { let todayEarlier = moment(Date.now()).subtract(10, 'h').format().split('+')[0]; let todayNow = moment(Date.now()).format().split('+')[0]; - return chain.api.condenser_api.get_trade_history([todayEarlier, todayNow, limit]); + return (await chain.api.market_history_api.get_trade_history({ start: todayEarlier, end: todayNow, limit })).trades; }; export const getRecentTrades = async (limit: number = 1000): Promise => { - return chain.api.condenser_api.get_recent_trades([limit]); + return (await chain.api.market_history_api.get_recent_trades({ limit })).trades; }; export const getSavingsWithdrawals = async (account: string): Promise => { return chain.api.database_api.find_savings_withdrawals({ account: account }); }; -export const getOwnerHistory = async (account: string): Promise => { - return chain.api.condenser_api.get_owner_history([account]); +export const getOwnerHistory = async (account: string): Promise => { + return (await chain.api.database_api.list_owner_histories({ start: [account, '1970-01-01T00:00:00'], limit: 100 })).owner_auths; }; export const getDynamicGlobalPropertiesData = async (): Promise => { diff --git a/apps/wallet/lib/utils.ts b/apps/wallet/lib/utils.ts index 96cb9e13ed034169afe49869b1c265effdcabf59..80c03ef09cebea8e2a7a80951d087ddeed439964 100644 --- a/apps/wallet/lib/utils.ts +++ b/apps/wallet/lib/utils.ts @@ -252,16 +252,23 @@ export function createListWithSuggestions( export const prepareRC = (rc: string): string => { return `${numberWithCommas(convertStringToBig(rc).div(1000000000).toFixed(1))}bil`; }; -export function convertToFormattedHivePower(vests: NaiAsset | undefined, totalVestingFund: string | undefined, totalVestingShares: string | undefined, hiveChain: HiveChain): string { + +export function convertToFormattedHivePower(vests: NaiAsset | undefined, totalVestingFund: NaiAsset | undefined, totalVestingShares: NaiAsset | undefined, hiveChain: HiveChain): string { let operationHp = hiveChain?.hiveSatoshis(0); - if (vests) { - // TODO: Replace with better NAI conversion - // operationHp = hiveChain?.vestsToHp(vests, totalVestingFund!, totalVestingShares!); - const totalVestingFundNai = hiveChain!.hiveCoins(Number((totalVestingFund || "0").replace(" HIVE", ""))); - const totalVestingSharesNai = hiveChain!.vestsCoins(Number((totalVestingShares || "0").replace(" VESTS", ""))); - operationHp = hiveChain?.vestsToHp(vests, totalVestingFundNai, totalVestingSharesNai); - } - return hiveChain.formatter.format(operationHp).replace("HIVE", "HIVE POWER"); + + if (vests) + operationHp = hiveChain?.vestsToHp(vests, totalVestingFund!, totalVestingShares!); + + return operationHp.amount; +} + +export function convertVestsToHp(vestsAmount: string, totalVestingFund: NaiAsset | undefined, totalVestingShares: NaiAsset | undefined, hiveChain: HiveChain): string { + if (!totalVestingFund || !totalVestingShares) return "0.00"; + + const vests = hiveChain.vestsSatoshis(vestsAmount); + const operationHp = hiveChain.vestsToHp(vests, totalVestingFund, totalVestingShares); + + return operationHp.amount; } export function filterSmallerThanOne(asset?: NaiAsset) { diff --git a/apps/wallet/pages/[param]/delegations.tsx b/apps/wallet/pages/[param]/delegations.tsx index 16c9135e7b6d27124889c36c61c6c65e0a6c4029..dc0795912189d030f63ad5d9034df6b29bbad041 100644 --- a/apps/wallet/pages/[param]/delegations.tsx +++ b/apps/wallet/pages/[param]/delegations.tsx @@ -14,12 +14,8 @@ import Head from 'next/head'; import TimeAgo from '@ui/components/time-ago'; import { IDynamicGlobalProperties } from '@transaction/lib/extended-hive.chain'; import RCTable from '@/wallet/feature/delegations/rc-table'; - -const convertVestsToSteem = (vests: number, dynamicData: IDynamicGlobalProperties) => { - const totalFund = parseFloat(dynamicData.total_vesting_fund_hive); - const totalShares = parseFloat(dynamicData.total_vesting_shares); - return ((vests * totalFund) / totalShares).toFixed(2); -}; +import { hiveChainService } from '@transaction/lib/hive-chain-service'; +import { convertVestsToHp } from '@/wallet/lib/utils'; function DelegationsPage({ username, metadata }: InferGetServerSidePropsType) { const { t } = useTranslation('common_wallet'); @@ -32,10 +28,12 @@ function DelegationsPage({ username, metadata }: InferGetServerSidePropsType; } - if (!vestingData || !dynamicData) { + if (!vestingData || !dynamicData || !hiveChain) { return

{t('global.something_went_wrong')}

; } return ( @@ -62,7 +60,7 @@ function DelegationsPage({ username, metadata }: InferGetServerSidePropsType {numberWithCommas( - convertVestsToSteem(parseFloat(element.vesting_shares), dynamicData) + convertVestsToHp(element.vesting_shares.amount, dynamicData.total_vesting_fund_hive, dynamicData.total_vesting_shares, hiveChain) )}{' '} HP diff --git a/apps/wallet/playwright/tests/e2e/wallet.spec.ts b/apps/wallet/playwright/tests/e2e/wallet.spec.ts index 4e03d32624fcb460e426e1fb271e3fb4841395b8..53c0e11f8d80ab712086184f2a901af89e9a867b 100644 --- a/apps/wallet/playwright/tests/e2e/wallet.spec.ts +++ b/apps/wallet/playwright/tests/e2e/wallet.spec.ts @@ -223,7 +223,7 @@ test.describe("Wallet page of @gtg tests", () => { if (await walletPage.walletAccountHistoryRow.first().isVisible()){ await walletPage.page.waitForSelector(await walletPage.walletAccountHistoryRow["_selector"]); - await expect(accountHistoryUI.length).toBe(accountHistoryResult.result.length); + await expect(accountHistoryUI.length).toBe(accountHistoryResult.result.history.length); } else { await expect(await walletPage.walletAccountHistoryNoTransactionMsg).toContainText('No transactions found'); } @@ -246,7 +246,7 @@ test.describe("Wallet page of @gtg tests", () => { let accountHistoryResult = null; if (await accountHistoryResultAPI.result != null) - accountHistoryResult = await accountHistoryResultAPI.result.reverse(); + accountHistoryResult = await accountHistoryResultAPI.result.history.reverse(); // console.log('Account history result:\n', await accountHistoryResult); @@ -303,7 +303,7 @@ test.describe("Wallet page of @gtg tests", () => { await walletPage.page.waitForSelector(await walletPage.walletDelegationItem["_selector"]); const vestingDelegationAPI = await apiHelper.getVestingDelegationsAPI("blocktrades", "", 50); - const vestingDelegationAPILength = await vestingDelegationAPI.result.length; + const vestingDelegationAPILength = await vestingDelegationAPI.result.delegations.length; // console.log('vesting delegation api response ', await vestingDelegationAPI, await vestingDelegationAPILength); expect((await walletPage.walletDelegationItem.all()).length).toBe(vestingDelegationAPILength); diff --git a/apps/wallet/playwright/tests/e2e/witnesses.spec.ts b/apps/wallet/playwright/tests/e2e/witnesses.spec.ts index 44a491edbe6c5289252176e3b8cb6b78d5005e06..7fa4c7e7a42f25ba5f01717fc815e8f0da2eecbf 100644 --- a/apps/wallet/playwright/tests/e2e/witnesses.spec.ts +++ b/apps/wallet/playwright/tests/e2e/witnesses.spec.ts @@ -54,14 +54,14 @@ test.describe('Witnesses page tests', () => { for (let i = 0; i < 250; i++) { if (i >= 0 && i < 101) { - witnessByVoteAPIArray.push(await resWitnessesByVote.result[i].owner); + witnessByVoteAPIArray.push(await resWitnessesByVote.result.witnesses[i].owner); } if (i >= 101 && i < 250) { witnessLastBlockAgeInSecs = - (headBlock - (await resWitnessesByVote.result[i].last_confirmed_block_num)) * 3; + (headBlock - (await resWitnessesByVote.result.witnesses[i].last_confirmed_block_num)) * 3; if (witnessLastBlockAgeInSecs < LAST_BLOCK_AGE_THRESHOLD_IN_SEC) { - witnessByVoteAPIArray.push(await resWitnessesByVote.result[i].owner); + witnessByVoteAPIArray.push(await resWitnessesByVote.result.witnesses[i].owner); } } } @@ -136,20 +136,20 @@ test.describe('Witnesses page tests', () => { await witnessesPage.goToWitnessesPage(); const resWitnessesByVoteAPI = await apiHelper.getListWitnessesByVoteAPI('', 250); - const lastConfirmedBlockNum = await resWitnessesByVoteAPI.result[0].last_confirmed_block_num.toString(); + const lastConfirmedBlockNum = await resWitnessesByVoteAPI.result.witnesses[0].last_confirmed_block_num.toString(); // Validate last confirmed block number expect(await witnessesPage.witnessLastBlockNumber.first()).toBeVisible(); // Below assertion is too unstable // expect(await witnessesPage.witnessLastBlockNumber.first().textContent()).toContain(await lastConfirmedBlockNum); - const witnessCreatedAPI = await resWitnessesByVoteAPI.result[0].created; + const witnessCreatedAPI = await resWitnessesByVoteAPI.result.witnesses[0].created; // Validate Witness's age expect(await witnessesPage.witnessCreated.first().textContent()).toContain( moment().from(witnessCreatedAPI, true) ); // Validate Witness external site - const firstWitnessUrl = await resWitnessesByVoteAPI.result[0].url; + const firstWitnessUrl = await resWitnessesByVoteAPI.result.witnesses[0].url; await expect(witnessesPage.witnessExternalSiteLink.locator('a').first()).toHaveAttribute( 'href', firstWitnessUrl @@ -157,13 +157,10 @@ test.describe('Witnesses page tests', () => { // Validate Witness votes received const resDynamicGlobalProperties = await apiHelper.getDynamicGlobalPropertiesAPI(); - const totalVesting = await resDynamicGlobalProperties.result.total_vesting_fund_hive.replace( - / HIVE/g, - '' - ); - const totalShares = await resDynamicGlobalProperties.result.total_vesting_shares.replace(/ VESTS/g, ''); - const witnessVotesAPI = await resWitnessesByVoteAPI.result[0].votes; - const vestsToHp: Big = Big(Big(totalVesting).times(Big(witnessVotesAPI).div(Big(totalShares)))).div( + const totalVesting = await resDynamicGlobalProperties.result.total_vesting_fund_hive.amount; + const totalShares = await resDynamicGlobalProperties.result.total_vesting_shares.amount; + const witnessVotesAPI = await resWitnessesByVoteAPI.result.witnesses[0].votes; + const vestsToHp: Big = Big(totalVesting).times(Big(witnessVotesAPI).div(totalShares)).div( 1000000 ); expect(await witnessesPage.witnessVotesReceived.first().textContent()).toBe( @@ -171,10 +168,7 @@ test.describe('Witnesses page tests', () => { ); // Validate Witness price feed - const firstWitnessPriceFeed = await resWitnessesByVoteAPI.result[0].hbd_exchange_rate.base.replace( - / HBD/g, - '' - ); + const firstWitnessPriceFeed = await resWitnessesByVoteAPI.result.witnesses[0].hbd_exchange_rate.base.amount; expect('$' + firstWitnessPriceFeed).toContain(await witnessesPage.witnessPriceFeed.first().textContent()); }); diff --git a/apps/wallet/playwright/tests/support/apiHelper.ts b/apps/wallet/playwright/tests/support/apiHelper.ts index 130362f4e9b9c90e4c38a75d324093ab48286324..43c0acb28371f3972204e179fdb81ef88a9c1988 100644 --- a/apps/wallet/playwright/tests/support/apiHelper.ts +++ b/apps/wallet/playwright/tests/support/apiHelper.ts @@ -27,15 +27,15 @@ export class ApiHelper { } // Get Follow count info as json from API response - async getFollowCountAPI(username: string) { + async getFollowCountAPI(account: string) { const url = process.env.REACT_APP_API_ENDPOINT; const responseGetFollowCount = await this.page.request.post(`${url}/`, { data: { id: 0, jsonrpc: "2.0", - method: "condenser_api.get_follow_count", - params: [`${username}`], + method: "follow_api.get_follow_count", + params: { account }, }, headers: { Accept: "application/json, text/plain, */*", @@ -117,8 +117,8 @@ export class ApiHelper { data: { id: 0, jsonrpc: "2.0", - method: "condenser_api.get_witnesses_by_vote", - params: [`${startName}`, `${limit}`], + method: "database_api.list_witnesses", + params: { start: [9223372036854775807n.toString(), startName], limit, order: 'by_vote_name' }, }, headers: { Accept: "application/json, text/plain, */*", @@ -136,8 +136,8 @@ export class ApiHelper { data: { id: 0, jsonrpc: "2.0", - method: "condenser_api.get_dynamic_global_properties", - params: [], + method: "database_api.get_dynamic_global_properties", + params: {}, }, headers: { Accept: "application/json, text/plain, */*", @@ -264,8 +264,13 @@ export class ApiHelper { data: { id: 0, jsonrpc: "2.0", - method: "condenser_api.get_account_history", - params: [account, start, limit, "199284866418737180"], // last parameter: ...wallet_operations_bitmask + method: "account_history_api.get_account_history", + params: { + account: account, + start: start.toString(), + limit: limit, + operation_filter_low: "199284866418737180" // wallet_operations_bitmask converted to string + }, }, headers: { Accept: "application/json, text/plain, */*", @@ -283,8 +288,8 @@ export class ApiHelper { data: { id: 0, jsonrpc: "2.0", - method: "condenser_api.get_vesting_delegations", - params: [account, start_account, limit], + method: "database_api.list_vesting_delegations", + params: { start: [account, start_account], limit, order: 'by_delegation' }, }, headers: { Accept: "application/json, text/plain, */*", diff --git a/packages/transaction/lib/extended-hive.chain.ts b/packages/transaction/lib/extended-hive.chain.ts index 1304499877bc7a342b24b955091b775445af1a52..be6804efed4851bb2378125479de45603fe35e7a 100644 --- a/packages/transaction/lib/extended-hive.chain.ts +++ b/packages/transaction/lib/extended-hive.chain.ts @@ -164,9 +164,9 @@ export interface JsonMetadata { export type FollowListType = 'follow_blacklist' | 'follow_muted' | 'blacklisted' | 'muted'; export interface IMarketStatistics { - hbd_volume: string; + hbd_volume: NaiAsset; highest_bid: string; - hive_volume: string; + hive_volume: NaiAsset; latest: string; lowest_ask: string; percent_change: string; @@ -177,22 +177,38 @@ export interface IWitness { id: number; total_missed: number; url: string; + votes: number; + virtual_last_update: string; + virtual_position: string; + virtual_scheduled_time: string; + last_aslot: number; + last_confirmed_block_num: number; + pow_worker: number; + signing_key: string; props: { - account_creation_fee: string; - account_subsidy_budget: number; + account_creation_fee: NaiAsset; maximum_block_size: number; + hbd_interest_rate: number; + account_subsidy_budget: number; + account_subsidy_decay: number; }; hbd_exchange_rate: { - base: string; - quote: string; + base: NaiAsset; + quote: NaiAsset; }; - available_witness_account_subsidies: number; + last_hbd_exchange_update: string; + last_work: string; running_version: string; + hardfork_version_vote: string; + hardfork_time_vote: string; + available_witness_account_subsidies: number; owner: string; - signing_key: string; - last_hbd_exchange_update: string; - votes: number; - last_confirmed_block_num: number; +} + +export interface ITradesData { + date: string; + current_pays: NaiAsset; + open_pays: NaiAsset; } export interface IOrdersDataItem { @@ -200,8 +216,8 @@ export interface IOrdersDataItem { hbd: number; hive: number; order_price: { - base: string; - quote: string; + base: NaiAsset; + quote: NaiAsset; }; real_price: string; } @@ -219,29 +235,29 @@ export interface IOpenOrdersData { orderid: number; for_sale: number; sell_price: { - base: string; - quote: string; + base: NaiAsset; + quote: NaiAsset; }; - real_price: string; - rewarded: boolean; + real_price?: string; + rewarded?: boolean; } export interface IRecentTradesData { date: string; - current_pays: string; - open_pays: string; + current_pays: NaiAsset; + open_pays: NaiAsset; } -export type OwnerHistory = { +export interface IOwnerHistory { account: string; id: number; last_valid_time: string; previous_owner_authority: { - account_auths: unknown[]; + account_auths: string[]; key_auths: [string, number][]; weight_threshold: number; }; -}[]; +}; export interface IGetProposalsParams { start: Array; @@ -435,7 +451,7 @@ export interface IDelegatedVestingShare { delegatee: string; delegator: string; min_delegation_time: string; - vesting_shares: string; + vesting_shares: NaiAsset; } export type OpType = @@ -596,13 +612,13 @@ export interface IProposalVote { export interface IDynamicGlobalProperties { hbd_print_rate: number; - total_vesting_fund_hive: string; - total_vesting_shares: string; + total_vesting_fund_hive: NaiAsset; + total_vesting_shares: NaiAsset; hbd_interest_rate: number; head_block_number: number; head_block_id: string; vesting_reward_percent: number; - virtual_supply: string; + virtual_supply: NaiAsset; } export interface IAccountReputations { @@ -890,7 +906,7 @@ export type ExtendedNodeApi = { get_open_orders: TWaxApiRequest; get_trade_history: TWaxApiRequest<(string | number)[], IOrdersDataItem[]>; get_recent_trades: TWaxApiRequest; - get_owner_history: TWaxApiRequest; + get_owner_history: TWaxApiRequest; get_follow_count: TWaxApiRequest; get_content: TWaxApiRequest; get_market_history_buckets: TWaxApiRequest; @@ -946,10 +962,26 @@ export type ExtendedNodeApi = { }, { votes: IVoteListItem[] } >; + list_witnesses: TWaxApiRequest<{ start: string[]; limit: number; order: string }, { witnesses: IWitness[] }>; + list_vesting_delegations: TWaxApiRequest<{ start: [string, string]; limit: number; order: string }, { delegations: IDelegatedVestingShare[] }>; + list_limit_orders: TWaxApiRequest<{ start: [string, number], limit: number, order: string }, { orders: IOpenOrdersData[] }>; + list_owner_histories: TWaxApiRequest<{ start: [string, string], limit: number }, { owner_auths: IOwnerHistory[] }>; }; + account_history_api: { + get_account_history: TWaxApiRequest<{ account: string, start: string, limit: number, include_reversible?: boolean, operation_filter_low?: number, operation_filter_high?: number }, { history: AccountHistory[] }>; + }; + market_history_api: { + get_ticker: TWaxApiRequest<{}, IMarketStatistics>; + get_order_book: TWaxApiRequest<{ limit: number }, IOrdersData>; + get_trade_history: TWaxApiRequest<{ start: string, end: string, limit: number }, { trades: ITradesData[] }>; + get_recent_trades: TWaxApiRequest<{ limit: number }, { trades: IRecentTradesData[] }>; + } network_broadcast_api: { broadcast_transaction: TWaxApiRequest; }; + follow_api: { + get_follow_count: TWaxApiRequest<{ account: string }, AccountFollowStats> + } 'search-api': { find_text: TWaxApiRequest; }; diff --git a/packages/transaction/lib/hive.ts b/packages/transaction/lib/hive.ts index 7fd1b472e518f8e39fc4830f2818e761eb602faf..aa485ce2efc0effe8c434b5f1b384d8704efb0c1 100644 --- a/packages/transaction/lib/hive.ts +++ b/packages/transaction/lib/hive.ts @@ -20,7 +20,7 @@ const logger = getLogger('app'); const chain = await hiveChainService.getHiveChain(); export const getDynamicGlobalProperties = async (): Promise => { - return chain.api.condenser_api.get_dynamic_global_properties([]).then((r: any) => { + return chain.api.database_api.get_dynamic_global_properties({}).then((r: any) => { return { total_vesting_fund_hive: r.total_vesting_fund_hive || r.total_vesting_fund_steem, total_vesting_shares: r.total_vesting_shares, @@ -127,8 +127,8 @@ export const getFeedHistory = async (): Promise => { return chain.api.database_api.get_feed_history(); }; -export const getFollowCount = async (username: string): Promise => { - return chain.api.condenser_api.get_follow_count([username]); +export const getFollowCount = async (account: string): Promise => { + return chain.api.follow_api.get_follow_count({ account }); }; export interface IDynamicProps { diff --git a/packages/ui/lib/utils.ts b/packages/ui/lib/utils.ts index 42cddc200a1d1deb0cb2832a5afb54fab35f9955..10ac7473e53dd21daddb6b4421fb285e75f4f6e6 100644 --- a/packages/ui/lib/utils.ts +++ b/packages/ui/lib/utils.ts @@ -102,8 +102,8 @@ export const numberWithCommas = (x: string) => x.replace(/\B(?=(\d{3})+(?!\d))/g export function convertToHP( vests: Big, - totalVestingShares: string, - totalVestingFundHive: string, + totalVestingShares: NaiAsset, + totalVestingFundHive: NaiAsset, div: number = 1 ) { const total_vests = convertStringToBig(totalVestingShares);