Compare commits

...
12 changed files with 108 additions and 33 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
**_Control panel for your VEGA tokens_**
<img width="1438" alt="Screenshot 2021-12-11 at 06 32 51" src="https://user-images.githubusercontent.com/13255539/145666935-563fc1ff-35bc-4cd9-ae6d-cf711cc23454.png">
<img width="1437" alt="Screenshot 2021-12-11 at 06 32 51" src="https://user-images.githubusercontent.com/13255539/145666935-563fc1ff-35bc-4cd9-ae6d-cf711cc23454.png">
## Features
+15
View File
@@ -1,2 +1,17 @@
import { utcToZonedTime, format as tzFormat } from 'date-fns-tz';
export const DATE_FORMAT_DETAILED = 'dd MMMM yyyy HH:mm';
export const DATE_FORMAT_LONG = 'dd MMM yyyy';
/** Format a user's local date and time with the time zone abbreviation */
export const formatDateWithLocalTimezone = (
date: Date,
formatStr = 'dd MMMM yyyy HH:mm (z)'
) => {
const userTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
const localDatetime = utcToZonedTime(date, userTimeZone);
return tzFormat(localDatetime, formatStr, {
timeZone: userTimeZone,
});
};
@@ -1,8 +1,10 @@
import { format, isFuture } from 'date-fns';
import { isFuture } from 'date-fns';
import { useTranslation } from 'react-i18next';
import { KeyValueTable, KeyValueTableRow } from '@vegaprotocol/ui-toolkit';
import { DATE_FORMAT_DETAILED } from '../../../../lib/date-formats';
import {
formatDateWithLocalTimezone,
} from '../../../../lib/date-formats';
import type { Proposals_proposals } from '../../proposals/__generated__/Proposals';
import { CurrentProposalState } from '../current-proposal-state';
@@ -29,13 +31,13 @@ export const ProposalChangeTable = ({ proposal }: ProposalChangeTableProps) => {
{isFuture(new Date(terms.closingDatetime))
? t('closesOn')
: t('closedOn')}
{format(new Date(terms.closingDatetime), DATE_FORMAT_DETAILED)}
{formatDateWithLocalTimezone(new Date(terms.closingDatetime))}
</KeyValueTableRow>
<KeyValueTableRow>
{isFuture(new Date(terms.enactmentDatetime || 0))
? t('proposedEnactment')
: t('enactedOn')}
{format(new Date(terms.enactmentDatetime || 0), DATE_FORMAT_DETAILED)}
{formatDateWithLocalTimezone(new Date(terms.enactmentDatetime || 0))}
</KeyValueTableRow>
<KeyValueTableRow>
{t('proposedBy')}
@@ -43,7 +45,7 @@ export const ProposalChangeTable = ({ proposal }: ProposalChangeTableProps) => {
</KeyValueTableRow>
<KeyValueTableRow>
{t('proposedOn')}
{format(new Date(proposal.datetime), DATE_FORMAT_DETAILED)}
{formatDateWithLocalTimezone(new Date(proposal.datetime))}
</KeyValueTableRow>
{proposal.rejectionReason ? (
<KeyValueTableRow>
@@ -95,12 +95,17 @@ export function useUserVote(
setVoteState(VoteState.Requested);
const voteMapping = {
[VoteValue.Yes]: 'VALUE_YES',
[VoteValue.No]: 'VALUE_NO',
} as const;
try {
const variables = {
pubKey: keypair.pub,
propagate: true,
voteSubmission: {
value: value,
value: voteMapping[value],
proposalId,
},
};
@@ -1,6 +1,6 @@
import { ethers } from 'ethers';
import abi from '../abis/staking_abi.json';
import { prepend0x } from '../utils';
import { calcGasBuffer, prepend0x } from '../utils';
export class StakingBridge {
public contract: ethers.Contract;
@@ -14,18 +14,37 @@ export class StakingBridge {
this.address = address;
}
stake(amount: string, vegaPublicKey: string) {
return this.contract.stake(amount, prepend0x(vegaPublicKey));
async stake(amount: string, vegaPublicKey: string) {
const spender = prepend0x(vegaPublicKey);
const res = await this.contract.estimateGas.stake(amount, spender);
const gasLimit = calcGasBuffer(res);
return this.contract.stake(amount, spender, {
gasLimit,
});
}
remove_stake(amount: string, vegaPublicKey: string) {
return this.contract.remove_stake(amount, prepend0x(vegaPublicKey));
async remove_stake(amount: string, vegaPublicKey: string) {
const spender = prepend0x(vegaPublicKey);
const res = await this.contract.estimateGas.remove_stake(amount, spender);
const gasLimit = calcGasBuffer(res);
return this.contract.remove_stake(amount, spender, {
gasLimit,
});
}
transfer_stake(amount: string, newAddress: string, vegaPublicKey: string) {
return this.contract.transfer_stake(
async transfer_stake(
amount: string,
newAddress: string,
vegaPublicKey: string
) {
const pubkey = prepend0x(vegaPublicKey);
const res = await this.contract.estimateGas.transfer_stake(
amount,
newAddress,
prepend0x(vegaPublicKey)
pubkey
);
const gasLimit = calcGasBuffer(res);
return this.contract.transfer_stake(amount, newAddress, pubkey, {
gasLimit,
});
}
staking_token() {
return this.contract.staking_token();
@@ -1,6 +1,6 @@
import { ethers } from 'ethers';
import abi from '../abis/vesting_abi.json';
import { prepend0x } from '../utils';
import { prepend0x, calcGasBuffer } from '../utils';
export class TokenVesting {
public contract: ethers.Contract;
@@ -14,11 +14,21 @@ export class TokenVesting {
this.address = address;
}
stake_tokens(amount: string, vegaPublicKey: string) {
return this.contract.stake_tokens(amount, prepend0x(vegaPublicKey));
async stake_tokens(amount: string, vegaPublicKey: string) {
const spender = prepend0x(vegaPublicKey);
const res = await this.contract.estimateGas.stake_tokens(amount, spender);
const gasLimit = calcGasBuffer(res);
return this.contract.stake_tokens(amount, spender, {
gasLimit,
});
}
remove_stake(amount: string, vegaPublicKey: string) {
return this.contract.remove_stake(amount, prepend0x(vegaPublicKey));
async remove_stake(amount: string, vegaPublicKey: string) {
const spender = prepend0x(vegaPublicKey);
const res = await this.contract.estimateGas.remove_stake(amount, spender);
const gasLimit = calcGasBuffer(res);
return this.contract.remove_stake(amount, spender, {
gasLimit,
});
}
stake_balance(address: string, vegaPublicKey: string) {
return this.contract.stake_balance(address, prepend0x(vegaPublicKey));
@@ -38,7 +48,13 @@ export class TokenVesting {
user_total_all_tranches(address: string) {
return this.contract.user_total_all_tranches(address);
}
withdraw_from_tranche(trancheId: number) {
return this.contract.withdraw_from_tranche(trancheId);
async withdraw_from_tranche(trancheId: number) {
const res = await this.contract.estimateGas.withdraw_from_tranche(
trancheId
);
const gasLimit = calcGasBuffer(res);
return this.contract.withdraw_from_tranche(trancheId, {
gasLimit,
});
}
}
+7 -2
View File
@@ -1,6 +1,7 @@
import type { BigNumber } from 'ethers';
import { ethers } from 'ethers';
import erc20Abi from '../abis/erc20_abi.json';
import { calcGasBuffer } from '../utils';
export class Token {
public contract: ethers.Contract;
@@ -23,8 +24,12 @@ export class Token {
allowance(owner: string, spender: string): Promise<BigNumber> {
return this.contract.allowance(owner, spender);
}
approve(spender: string, amount: string) {
return this.contract.approve(spender, amount);
async approve(spender: string, amount: string) {
const res = await this.contract.estimateGas.approve(spender, amount);
const gasLimit = calcGasBuffer(res);
return this.contract.approve(spender, amount, {
gasLimit,
});
}
decimals(): Promise<number> {
return this.contract.decimals();
@@ -0,0 +1,5 @@
import type { BigNumber as EthersBigNumber } from 'ethers';
export function calcGasBuffer(value: EthersBigNumber): EthersBigNumber {
return value.mul(120).div(100);
}
+1
View File
@@ -1,2 +1,3 @@
export * from './ascii-to-hex';
export * from './prepend-0x';
export * from './calc-gas-buffer';
+10 -9
View File
@@ -1,12 +1,6 @@
import type { z } from 'zod';
import type { GetKeysSchema, TransactionResponseSchema } from './connectors';
import type { IterableElement } from 'type-fest';
import type {
OrderTimeInForce,
OrderType,
Side,
VoteValue,
} from '@vegaprotocol/types';
interface BaseTransaction {
pubKey: string;
@@ -28,12 +22,19 @@ export interface UndelegateSubmissionBody extends BaseTransaction {
};
}
type OrderTimeInForce =
| 'TIME_IN_FORCE_FOK'
| 'TIME_IN_FORCE_GFA'
| 'TIME_IN_FORCE_GFN'
| 'TIME_IN_FORCE_GTC'
| 'TIME_IN_FORCE_GTT'
| 'TIME_IN_FORCE_IOC';
export interface OrderSubmissionBody extends BaseTransaction {
orderSubmission: {
marketId: string;
reference?: string;
type: OrderType;
side: Side;
type: 'TYPE_MARKET' | 'TYPE_LIMIT';
side: 'SIDE_BUY' | 'SIDE_SELL';
timeInForce: OrderTimeInForce;
size: string;
price?: string;
@@ -62,7 +63,7 @@ export interface OrderAmendmentBody extends BaseTransaction {
export interface VoteSubmissionBody extends BaseTransaction {
voteSubmission: {
value: VoteValue;
value: 'VALUE_YES' | 'VALUE_NO';
proposalId: string;
};
}
+1
View File
@@ -47,6 +47,7 @@
"classnames": "^2.3.1",
"core-js": "^3.6.5",
"date-fns": "^2.28.0",
"date-fns-tz": "^2.0.0",
"duration-js": "^4.0.0",
"env-cmd": "^10.1.0",
"ethers": "^5.6.0",
+5
View File
@@ -10909,6 +10909,11 @@ dataloader@2.1.0:
resolved "https://registry.yarnpkg.com/dataloader/-/dataloader-2.1.0.tgz#c69c538235e85e7ac6c6c444bae8ecabf5de9df7"
integrity sha512-qTcEYLen3r7ojZNgVUaRggOI+KM7jrKxXeSHhogh/TWxYMeONEMqY+hmkobiYQozsGIyg9OYVzO4ZIfoB4I0pQ==
date-fns-tz@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/date-fns-tz/-/date-fns-tz-2.0.0.tgz#1b14c386cb8bc16fc56fe333d4fc34ae1d1099d5"
integrity sha512-OAtcLdB9vxSXTWHdT8b398ARImVwQMyjfYGkKD2zaGpHseG2UPHbHjXELReErZFxWdSLph3c2zOaaTyHfOhERQ==
date-fns@^1.27.2:
version "1.30.1"
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-1.30.1.tgz#2e71bf0b119153dbb4cc4e88d9ea5acfb50dc05c"