Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
13e374a6bb | ||
|
|
bed411040c | ||
|
|
d0173f15b2 | ||
|
|
106b040977 | ||
|
|
bf84b04a30 |
@@ -4,12 +4,11 @@ import {
|
||||
navigation,
|
||||
} from '../../support/common.functions';
|
||||
import {
|
||||
convertUnixTimestampToDateformat,
|
||||
createRawProposal,
|
||||
createTenDigitUnixTimeStampForSpecifiedDays,
|
||||
enterUniqueFreeFormProposalBody,
|
||||
generateFreeFormProposalTitle,
|
||||
getGovernanceProposalDateFormatForSpecifiedDays,
|
||||
getDateFormatForSpecifiedDays,
|
||||
getProposalIdFromList,
|
||||
getProposalInformationFromTable,
|
||||
getSubmittedProposalFromProposalList,
|
||||
@@ -23,6 +22,7 @@ import { ensureSpecifiedUnstakedTokensAreAssociated } from '../../../../governan
|
||||
import { ethereumWalletConnect } from '../../../../governance-e2e/src/support/wallet-eth.functions';
|
||||
import { vegaWalletSetSpecifiedApprovalAmount } from '../../../../governance-e2e/src/support/wallet-teardown.functions';
|
||||
import type { testFreeformProposal } from '../../support/common-interfaces';
|
||||
import { formatDateWithLocalTimezone } from '@vegaprotocol/utils';
|
||||
|
||||
const proposalVoteProgressForPercentage =
|
||||
'[data-testid="vote-progress-indicator-percentage-for"]';
|
||||
@@ -99,20 +99,22 @@ describe(
|
||||
getSubmittedProposalFromProposalList(proposalTitle).within(() =>
|
||||
cy.get(viewProposalButton).click()
|
||||
);
|
||||
convertUnixTimestampToDateformat(proposalTimeStamp).then(
|
||||
(closingDate) => {
|
||||
getProposalInformationFromTable('Closes on')
|
||||
.contains(closingDate)
|
||||
.should('be.visible');
|
||||
}
|
||||
);
|
||||
getGovernanceProposalDateFormatForSpecifiedDays(0).then(
|
||||
(proposalDate) => {
|
||||
getProposalInformationFromTable('Proposed on')
|
||||
.contains(proposalDate)
|
||||
.should('be.visible');
|
||||
}
|
||||
);
|
||||
cy.wrap(
|
||||
formatDateWithLocalTimezone(new Date(proposalTimeStamp * 1000))
|
||||
).then((closingDate) => {
|
||||
getProposalInformationFromTable('Closes on')
|
||||
.contains(closingDate)
|
||||
.should('be.visible');
|
||||
});
|
||||
cy.wrap(
|
||||
formatDateWithLocalTimezone(
|
||||
new Date(createTenDigitUnixTimeStampForSpecifiedDays(0) * 1000)
|
||||
)
|
||||
).then((proposalDate) => {
|
||||
getProposalInformationFromTable('Proposed on')
|
||||
.contains(proposalDate)
|
||||
.should('be.visible');
|
||||
});
|
||||
});
|
||||
|
||||
it('Newly created proposal details - shows default status set to fail', function () {
|
||||
@@ -155,18 +157,16 @@ describe(
|
||||
cy.getByTestId('vote-buttons').contains('against').should('be.visible');
|
||||
cy.getByTestId('vote-buttons').contains('for').should('be.visible');
|
||||
voteForProposal('for');
|
||||
getGovernanceProposalDateFormatForSpecifiedDays(0, 'shortMonth').then(
|
||||
(votedDate) => {
|
||||
// 3001-VOTE-051
|
||||
// 3001-VOTE-093
|
||||
cy.contains('You voted:')
|
||||
.siblings()
|
||||
.contains('For')
|
||||
.siblings()
|
||||
.contains(votedDate)
|
||||
.should('be.visible');
|
||||
}
|
||||
);
|
||||
getDateFormatForSpecifiedDays(0).then((votedDate) => {
|
||||
// 3001-VOTE-051
|
||||
// 3001-VOTE-093
|
||||
cy.contains('You voted:')
|
||||
.siblings()
|
||||
.contains('For')
|
||||
.siblings()
|
||||
.contains(votedDate)
|
||||
.should('be.visible');
|
||||
});
|
||||
cy.get(proposalVoteProgressForPercentage) // 3001-VOTE-072
|
||||
.contains('100.00%')
|
||||
.and('be.visible');
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { format } from 'date-fns';
|
||||
import { closeDialog, navigateTo, navigation } from './common.functions';
|
||||
import { ensureSpecifiedUnstakedTokensAreAssociated } from './staking.functions';
|
||||
|
||||
@@ -15,35 +16,6 @@ const newProposalSubmitButton = '[data-testid="proposal-submit"]';
|
||||
const epochTimeout = Cypress.env('epochTimeout');
|
||||
const proposalTimeout = { timeout: 14000 };
|
||||
|
||||
export function convertUnixTimestampToDateformat(
|
||||
unixTimestamp: number,
|
||||
monthTextLength = 'longMonth'
|
||||
) {
|
||||
const dateSupplied = new Date(unixTimestamp * 1000);
|
||||
const year = dateSupplied.getFullYear();
|
||||
const months = [
|
||||
'January',
|
||||
'February',
|
||||
'March',
|
||||
'April',
|
||||
'May',
|
||||
'June',
|
||||
'July',
|
||||
'August',
|
||||
'September',
|
||||
'October',
|
||||
'November',
|
||||
'December',
|
||||
];
|
||||
const month = months[dateSupplied.getMonth()];
|
||||
const shortMonth = months[dateSupplied.getMonth()].substring(0, 3),
|
||||
date = dateSupplied.getDate();
|
||||
|
||||
if (monthTextLength === 'longMonth') {
|
||||
return cy.wrap(`${date} ${month} ${year}`);
|
||||
} else return cy.wrap(`${date} ${shortMonth} ${year}`);
|
||||
}
|
||||
|
||||
export function createTenDigitUnixTimeStampForSpecifiedDays(
|
||||
durationDays: number
|
||||
) {
|
||||
@@ -52,6 +24,13 @@ export function createTenDigitUnixTimeStampForSpecifiedDays(
|
||||
return (timestamp = Math.floor(timestamp / 1000));
|
||||
}
|
||||
|
||||
export function getDateFormatForSpecifiedDays(days: number) {
|
||||
const date = new Date(
|
||||
createTenDigitUnixTimeStampForSpecifiedDays(days) * 1000
|
||||
);
|
||||
return cy.wrap(format(date, 'dd MMM yyyy'));
|
||||
}
|
||||
|
||||
export function enterRawProposalBody(timestamp: number) {
|
||||
cy.fixture('/proposals/raw.json').then((rawProposal) => {
|
||||
rawProposal.terms.closingTimestamp = timestamp;
|
||||
@@ -104,16 +83,6 @@ export function getProposalIdFromList(proposalTitle: string) {
|
||||
});
|
||||
}
|
||||
|
||||
export function getGovernanceProposalDateFormatForSpecifiedDays(
|
||||
days: number,
|
||||
shortOrLong?: string
|
||||
) {
|
||||
return convertUnixTimestampToDateformat(
|
||||
createTenDigitUnixTimeStampForSpecifiedDays(days),
|
||||
shortOrLong
|
||||
);
|
||||
}
|
||||
|
||||
export function getProposalInformationFromTable(heading: string) {
|
||||
return cy.get(proposalInformationTableRows).contains(heading).siblings();
|
||||
}
|
||||
|
||||
@@ -21,10 +21,10 @@ export const useGetUserBalances = (account: string | undefined) => {
|
||||
token.allowance(account, config.staking_bridge_contract.address),
|
||||
]);
|
||||
|
||||
const balance = toBigNum(b, decimals);
|
||||
const walletBalance = toBigNum(w, decimals);
|
||||
const lien = toBigNum(stats.lien, decimals);
|
||||
const allowance = toBigNum(a, decimals);
|
||||
const balance = toBigNum(b.toString(), decimals);
|
||||
const walletBalance = toBigNum(w.toString(), decimals);
|
||||
const lien = toBigNum(stats.lien.toString(), decimals);
|
||||
const allowance = toBigNum(a.toString(), decimals);
|
||||
|
||||
return {
|
||||
balanceFormatted: balance,
|
||||
|
||||
@@ -21,8 +21,14 @@ export function useRefreshAssociatedBalances() {
|
||||
]);
|
||||
|
||||
updateBalances({
|
||||
walletAssociatedBalance: toBigNum(walletAssociatedBalance, decimals),
|
||||
vestingAssociatedBalance: toBigNum(vestingAssociatedBalance, decimals),
|
||||
walletAssociatedBalance: toBigNum(
|
||||
walletAssociatedBalance.toString(),
|
||||
decimals
|
||||
),
|
||||
vestingAssociatedBalance: toBigNum(
|
||||
vestingAssociatedBalance.toString(),
|
||||
decimals
|
||||
),
|
||||
});
|
||||
},
|
||||
[staking, vesting, updateBalances, decimals]
|
||||
|
||||
@@ -31,12 +31,18 @@ export const useRefreshBalances = (address: string) => {
|
||||
pubKey ? vesting.stake_balance(address, pubKey) : null,
|
||||
]);
|
||||
|
||||
const balance = toBigNum(b, decimals);
|
||||
const walletBalance = toBigNum(w, decimals);
|
||||
const lien = toBigNum(stats.lien, decimals);
|
||||
const allowance = toBigNum(a, decimals);
|
||||
const walletAssociatedBalance = toBigNum(walletStakeBalance, decimals);
|
||||
const vestingAssociatedBalance = toBigNum(vestingStakeBalance, decimals);
|
||||
const balance = toBigNum(b.toString(), decimals);
|
||||
const walletBalance = toBigNum(w.toString(), decimals);
|
||||
const lien = toBigNum(stats.lien.toString(), decimals);
|
||||
const allowance = toBigNum(a.toString(), decimals);
|
||||
const walletAssociatedBalance = toBigNum(
|
||||
walletStakeBalance ? walletStakeBalance.toString() : 0,
|
||||
decimals
|
||||
);
|
||||
const vestingAssociatedBalance = toBigNum(
|
||||
vestingStakeBalance ? vestingStakeBalance.toString() : 0,
|
||||
decimals
|
||||
);
|
||||
|
||||
updateBalances({
|
||||
balanceFormatted: balance,
|
||||
|
||||
@@ -34,8 +34,9 @@ export const useUserTrancheBalances = (address: string | undefined) => {
|
||||
vesting.get_vested_for_tranche(address, tId),
|
||||
]);
|
||||
|
||||
const total = toBigNum(t, decimals);
|
||||
const vested = toBigNum(v, decimals);
|
||||
// Convert t and v EthersBigNumbers to regular BigNumbers
|
||||
const total = toBigNum(t.toString(), decimals);
|
||||
const vested = toBigNum(v.toString(), decimals);
|
||||
|
||||
return {
|
||||
id: tId,
|
||||
|
||||
@@ -54,7 +54,7 @@ export const WalletAssociate = ({
|
||||
address,
|
||||
ethereumConfig.staking_bridge_contract.address
|
||||
);
|
||||
const allowance = toBigNum(a, decimals);
|
||||
const allowance = toBigNum(a.toString(), decimals);
|
||||
setAllowance(allowance);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
"tranche_end": "2023-05-20T00:00:00.000Z",
|
||||
"total_added": "19242.125",
|
||||
"total_removed": "1523.8177488329475",
|
||||
"locked_amount": "7371.31511443865825548625",
|
||||
"locked_amount": "7048.7719635898923554",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "188",
|
||||
@@ -4861,7 +4861,7 @@
|
||||
"tranche_end": "2023-12-05T00:00:00.000Z",
|
||||
"total_added": "86666.297",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "49979.7329096604869903443",
|
||||
"locked_amount": "49860.3304086439895572664",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "86666.297",
|
||||
@@ -4927,7 +4927,7 @@
|
||||
"tranche_end": "2023-06-01T00:00:00.000Z",
|
||||
"total_added": "2500",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "322.698698870573775",
|
||||
"locked_amount": "315.79113883801385",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "2500",
|
||||
@@ -4960,7 +4960,7 @@
|
||||
"tranche_end": "2023-11-01T00:00:00.000Z",
|
||||
"total_added": "15000.000000000000015",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "14387.9727128623185143879727128623185",
|
||||
"locked_amount": "14346.9778457125605143469778457125605",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "1.5e-14",
|
||||
@@ -5048,7 +5048,7 @@
|
||||
"tranche_end": "2023-09-01T00:00:00.000Z",
|
||||
"total_added": "17500",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "10984.33773022342925",
|
||||
"locked_amount": "10936.51038521537825",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "12500",
|
||||
@@ -5315,7 +5315,7 @@
|
||||
"tranche_end": "2023-08-01T00:00:00.000Z",
|
||||
"total_added": "37500",
|
||||
"total_removed": "18077.0118744",
|
||||
"locked_amount": "17505.34501611418125",
|
||||
"locked_amount": "17401.159165899324375",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "7500",
|
||||
@@ -5734,7 +5734,7 @@
|
||||
"tranche_end": "2023-12-05T00:00:00.000Z",
|
||||
"total_added": "129999.45",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "49934.132692071551825937",
|
||||
"locked_amount": "49814.839130813438918838",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "129999.45",
|
||||
@@ -5767,7 +5767,7 @@
|
||||
"tranche_end": "2024-04-01T00:00:00.000Z",
|
||||
"total_added": "54144.7663",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "48596.0321414648663214997",
|
||||
"locked_amount": "48521.63924888864092183046",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "54144.7663",
|
||||
@@ -5800,7 +5800,7 @@
|
||||
"tranche_end": "2023-09-03T00:00:00.000Z",
|
||||
"total_added": "62600",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "20150.76253805175029",
|
||||
"locked_amount": "20064.516825215627982",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "10000",
|
||||
@@ -5993,7 +5993,7 @@
|
||||
"tranche_end": "2023-09-17T00:00:00.000Z",
|
||||
"total_added": "5000",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "1801.26664764079125",
|
||||
"locked_amount": "1794.3780124302383",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "5000",
|
||||
@@ -7062,7 +7062,7 @@
|
||||
"tranche_end": "2023-06-02T00:00:00.000Z",
|
||||
"total_added": "1939928.38",
|
||||
"total_removed": "1709370.7872515768348",
|
||||
"locked_amount": "130174.32462609789781957",
|
||||
"locked_amount": "127501.632837213895787904",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "1852091.69",
|
||||
@@ -40934,7 +40934,7 @@
|
||||
"tranche_end": "2023-06-05T00:00:00.000Z",
|
||||
"total_added": "3732368.4671",
|
||||
"total_removed": "715655.108029600523393",
|
||||
"locked_amount": "224533.9397934779571663606186",
|
||||
"locked_amount": "220426.943046411634396105333",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "1998.95815",
|
||||
@@ -42327,7 +42327,7 @@
|
||||
"tranche_end": "2023-12-05T00:00:00.000Z",
|
||||
"total_added": "15870102.715470999700000001",
|
||||
"total_removed": "871680.07831804700259352",
|
||||
"locked_amount": "6095870.51969169065811272227952994009813466",
|
||||
"locked_amount": "6081307.37292098829210815160177023943687484",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "16249.93",
|
||||
@@ -59070,7 +59070,7 @@
|
||||
"tranche_end": "2023-06-05T00:00:00.000Z",
|
||||
"total_added": "472355.6199999996",
|
||||
"total_removed": "44479.0535455583416",
|
||||
"locked_amount": "35578.671272696564429696212379508",
|
||||
"locked_amount": "34927.90913982811608735474530694",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "3000",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { VegaWalletContext } from '@vegaprotocol/wallet';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { act, render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { generateMarket, generateMarketData } from '../../test-helpers';
|
||||
import { DealTicket } from './deal-ticket';
|
||||
@@ -40,12 +40,21 @@ describe('DealTicket', () => {
|
||||
});
|
||||
|
||||
it('should display ticket defaults', () => {
|
||||
render(generateJsx());
|
||||
const { container } = render(generateJsx());
|
||||
|
||||
// Assert defaults are used
|
||||
expect(
|
||||
screen.getByTestId(`order-type-${Schema.OrderType.TYPE_MARKET}`)
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByTestId(`order-type-${Schema.OrderType.TYPE_LIMIT}`)
|
||||
).toBeInTheDocument();
|
||||
|
||||
const oderTypeLimitToggle = container.querySelector(
|
||||
`[data-testid="order-type-${Schema.OrderType.TYPE_LIMIT}"] input[type="radio"]`
|
||||
);
|
||||
expect(oderTypeLimitToggle).toBeChecked();
|
||||
|
||||
expect(
|
||||
screen.queryByTestId('order-side-SIDE_BUY')?.querySelector('input')
|
||||
).toBeChecked();
|
||||
@@ -54,8 +63,15 @@ describe('DealTicket', () => {
|
||||
).not.toBeChecked();
|
||||
expect(screen.getByTestId('order-size')).toHaveDisplayValue('0');
|
||||
expect(screen.getByTestId('order-tif')).toHaveValue(
|
||||
Schema.OrderTimeInForce.TIME_IN_FORCE_IOC
|
||||
Schema.OrderTimeInForce.TIME_IN_FORCE_GTC
|
||||
);
|
||||
});
|
||||
|
||||
it('should display last price for market type order', () => {
|
||||
render(generateJsx());
|
||||
act(() => {
|
||||
screen.getByTestId(`order-type-${Schema.OrderType.TYPE_MARKET}`).click();
|
||||
});
|
||||
// Assert last price is shown
|
||||
expect(screen.getByTestId('last-price')).toHaveTextContent(
|
||||
// eslint-disable-next-line
|
||||
@@ -206,7 +222,11 @@ describe('DealTicket', () => {
|
||||
it('handles TIF select box dependent on order type', async () => {
|
||||
render(generateJsx());
|
||||
|
||||
// Only FOK and IOC should be present by default (type market order)
|
||||
act(() => {
|
||||
screen.getByTestId(`order-type-${Schema.OrderType.TYPE_MARKET}`).click();
|
||||
});
|
||||
|
||||
// Only FOK and IOC should be present for type market order
|
||||
expect(
|
||||
Array.from(screen.getByTestId('order-tif').children).map(
|
||||
(o) => o.textContent
|
||||
|
||||
@@ -20,8 +20,8 @@ interface TypeSelectorProps {
|
||||
}
|
||||
|
||||
const toggles = [
|
||||
{ label: t('Market'), value: Schema.OrderType.TYPE_MARKET },
|
||||
{ label: t('Limit'), value: Schema.OrderType.TYPE_LIMIT },
|
||||
{ label: t('Market'), value: Schema.OrderType.TYPE_MARKET },
|
||||
];
|
||||
|
||||
export const TypeSelector = ({
|
||||
|
||||
@@ -109,9 +109,9 @@ export const useOrder = (marketId: string) => {
|
||||
|
||||
export const getDefaultOrder = (marketId: string): OrderObj => ({
|
||||
marketId,
|
||||
type: OrderType.TYPE_MARKET,
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
side: Side.SIDE_BUY,
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_IOC,
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
size: '0',
|
||||
price: '0',
|
||||
expiresAt: undefined,
|
||||
|
||||
@@ -11,7 +11,9 @@
|
||||
"@vegaprotocol/data-provider",
|
||||
"graphql",
|
||||
"graphql-tag",
|
||||
"graphql-ws"
|
||||
"graphql-ws",
|
||||
"ethers",
|
||||
"@ethersproject"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { ethers } from 'ethers';
|
||||
import abi from '../abis/staking_abi.json';
|
||||
import { calcGasBuffer, prepend0x } from '../utils';
|
||||
import type { BigNumber as EthersBigNum } from 'ethers';
|
||||
|
||||
export class StakingBridge {
|
||||
public contract: ethers.Contract;
|
||||
@@ -51,7 +52,7 @@ export class StakingBridge {
|
||||
staking_token() {
|
||||
return this.contract.staking_token();
|
||||
}
|
||||
stake_balance(target: string, vegaPublicKey: string) {
|
||||
stake_balance(target: string, vegaPublicKey: string): Promise<EthersBigNum> {
|
||||
return this.contract.stake_balance(target, prepend0x(vegaPublicKey));
|
||||
}
|
||||
total_staked() {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { ethers } from 'ethers';
|
||||
import abi from '../abis/vesting_abi.json';
|
||||
import { calcGasBuffer, prepend0x } from '../utils';
|
||||
import type { BigNumber as EthersBigNum } from 'ethers';
|
||||
|
||||
export class TokenVesting {
|
||||
public contract: ethers.Contract;
|
||||
@@ -29,13 +30,15 @@ export class TokenVesting {
|
||||
gasLimit,
|
||||
});
|
||||
}
|
||||
stake_balance(address: string, vegaPublicKey: string) {
|
||||
stake_balance(address: string, vegaPublicKey: string): Promise<EthersBigNum> {
|
||||
return this.contract.stake_balance(address, prepend0x(vegaPublicKey));
|
||||
}
|
||||
total_staked() {
|
||||
return this.contract.total_staked();
|
||||
}
|
||||
user_stats(address: string) {
|
||||
user_stats(
|
||||
address: string
|
||||
): Promise<{ lien: EthersBigNum; total_in_all_tranches: EthersBigNum }> {
|
||||
return this.contract.user_stats(address);
|
||||
}
|
||||
get_tranche_balance(address: string, trancheId: number) {
|
||||
@@ -44,7 +47,7 @@ export class TokenVesting {
|
||||
get_vested_for_tranche(address: string, trancheId: number) {
|
||||
return this.contract.get_vested_for_tranche(address, trancheId);
|
||||
}
|
||||
user_total_all_tranches(address: string) {
|
||||
user_total_all_tranches(address: string): Promise<EthersBigNum> {
|
||||
return this.contract.user_total_all_tranches(address);
|
||||
}
|
||||
async withdraw_from_tranche(trancheId: number) {
|
||||
|
||||
@@ -11,7 +11,9 @@
|
||||
"@vegaprotocol/data-provider",
|
||||
"graphql",
|
||||
"graphql-tag",
|
||||
"graphql-ws"
|
||||
"graphql-ws",
|
||||
"ethers",
|
||||
"@ethersproject"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { BigNumber } from 'bignumber.js';
|
||||
import { BigNumber as EthersBigNumber } from 'ethers';
|
||||
import isNil from 'lodash/isNil';
|
||||
import memoize from 'lodash/memoize';
|
||||
|
||||
@@ -15,16 +14,14 @@ export function toDecimal(numberOfDecimals: number) {
|
||||
}
|
||||
|
||||
export function toBigNum(
|
||||
rawValue: string | number | EthersBigNumber,
|
||||
rawValue: string | number,
|
||||
decimals: number
|
||||
): BigNumber {
|
||||
return new BigNumber(
|
||||
rawValue instanceof EthersBigNumber ? rawValue.toString() : rawValue || 0
|
||||
).dividedBy(Math.pow(10, decimals));
|
||||
return new BigNumber(rawValue || 0).dividedBy(Math.pow(10, decimals));
|
||||
}
|
||||
|
||||
export function addDecimal(
|
||||
value: string | number | EthersBigNumber,
|
||||
value: string | number,
|
||||
decimals: number,
|
||||
decimalPrecision = decimals
|
||||
): string {
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { ethereumAddress, vegaPublicKey } from './common';
|
||||
|
||||
it('ethereumAddress', () => {
|
||||
const errorMessage = 'Invalid Ethereum address';
|
||||
|
||||
const validAddress = '0x72c22822A19D20DE7e426fB84aa047399Ddd8853';
|
||||
expect(ethereumAddress(validAddress)).toEqual(true);
|
||||
|
||||
const invalidChars = '0xzzc22822A19D20DE7e426fB84aa047399Ddd8853';
|
||||
expect(ethereumAddress(invalidChars)).toEqual(errorMessage);
|
||||
|
||||
const tooManyChars = '0x72c22822A19D20DE7e426fB84aa047399Ddd88531111111';
|
||||
expect(ethereumAddress(tooManyChars)).toEqual(errorMessage);
|
||||
|
||||
const no0x = '1x72c22822A19D20DE7e426fB84aa047399Ddd8853';
|
||||
expect(ethereumAddress(no0x)).toEqual(errorMessage);
|
||||
});
|
||||
|
||||
it('vegaPublicKey', () => {
|
||||
const errorMessage = 'Invalid Vega key';
|
||||
|
||||
const validKey =
|
||||
'70d14a321e02e71992fd115563df765000ccc4775cbe71a0e2f9ff5a3b9dc680';
|
||||
expect(vegaPublicKey(validKey)).toEqual(true);
|
||||
|
||||
const invalidChars =
|
||||
'zzz14a321e02e71992fd115563df765000ccc4775cbe71a0e2f9ff5a3b9dc680';
|
||||
expect(vegaPublicKey(invalidChars)).toEqual(errorMessage);
|
||||
|
||||
const tooManyChars =
|
||||
'70d14a321e02e71992fd115563df765000ccc4775cbe71a0e2f9ff5a3b9dc680111111';
|
||||
expect(vegaPublicKey(tooManyChars)).toEqual(errorMessage);
|
||||
});
|
||||
@@ -1,5 +1,4 @@
|
||||
import BigNumber from 'bignumber.js';
|
||||
import { ethers } from 'ethers';
|
||||
import { t } from '@vegaprotocol/i18n';
|
||||
|
||||
export const required = (value: string) => {
|
||||
@@ -10,14 +9,14 @@ export const required = (value: string) => {
|
||||
};
|
||||
|
||||
export const ethereumAddress = (value: string) => {
|
||||
if (!ethers.utils.isAddress(value)) {
|
||||
if (!/^0x[0-9a-fA-F]{40}$/i.test(value)) {
|
||||
return t('Invalid Ethereum address');
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
export const vegaPublicKey = (value: string) => {
|
||||
if (value.length !== 64 || !/^[A-Fa-f0-9]*$/i.test(value)) {
|
||||
if (!/^[A-Fa-f0-9]{64}$/i.test(value)) {
|
||||
return t('Invalid Vega key');
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user