Compare commits

..

2 Commits

Author SHA1 Message Date
Matthew Russell
a4bc1cf95d
chore: remove dependency on utils and ethers from wallet 2024-03-08 21:38:45 +00:00
Matthew Russell
2d98205028
chore: remove ethers dep from wallet 2024-03-08 21:27:39 +00:00
18 changed files with 46 additions and 176 deletions

View File

@ -4,5 +4,6 @@ tmp/*
.dockerignore .dockerignore
dockerfiles dockerfiles
node_modules node_modules
.git
.github .github
.vscode .vscode

View File

@ -38,7 +38,6 @@ import { differenceInHours, format, formatDistanceToNowStrict } from 'date-fns';
import { DATE_FORMAT_DETAILED } from '../../../../lib/date-formats'; import { DATE_FORMAT_DETAILED } from '../../../../lib/date-formats';
import { MarketName } from '../proposal/market-name'; import { MarketName } from '../proposal/market-name';
import { Indicator } from '../proposal/indicator'; import { Indicator } from '../proposal/indicator';
import { type ProposalNode } from '../proposal/proposal-utils';
const ProposalTypeTags = ({ const ProposalTypeTags = ({
proposal, proposal,
@ -541,12 +540,10 @@ const BatchProposalStateText = ({
export const ProposalHeader = ({ export const ProposalHeader = ({
proposal, proposal,
restData,
isListItem = true, isListItem = true,
voteState, voteState,
}: { }: {
proposal: Proposal | BatchProposal; proposal: Proposal | BatchProposal;
restData?: ProposalNode | null;
isListItem?: boolean; isListItem?: boolean;
voteState?: VoteState | null; voteState?: VoteState | null;
}) => { }) => {
@ -598,7 +595,7 @@ export const ProposalHeader = ({
)} )}
</div> </div>
<ProposalDetails proposal={proposal} /> <ProposalDetails proposal={proposal} />
<VoteBreakdown proposal={proposal} restData={restData} /> <VoteBreakdown proposal={proposal} />
</> </>
); );
}; };

View File

@ -91,28 +91,6 @@ export type ProposalNode = {
proposal: ProposalData; proposal: ProposalData;
proposalType: ProposalNodeType; proposalType: ProposalNodeType;
proposals: SubProposalData[]; proposals: SubProposalData[];
yes?: [
{
partyId: string;
elsPerMarket?: [
{
marketId: string;
els: string;
}
];
}
];
no?: [
{
partyId: string;
elsPerMarket?: [
{
marketId: string;
els: string;
}
];
}
];
}; };
type SingleProposalNode = ProposalNode & { type SingleProposalNode = ProposalNode & {

View File

@ -48,7 +48,6 @@ export const Proposal = ({ proposal, restData }: ProposalProps) => {
<ProposalHeader <ProposalHeader
proposal={proposal} proposal={proposal}
restData={restData}
isListItem={false} isListItem={false}
voteState={voteState} voteState={voteState}
/> />

View File

@ -17,7 +17,6 @@ import {
import { useBatchVoteInformation } from '../../hooks/use-vote-information'; import { useBatchVoteInformation } from '../../hooks/use-vote-information';
import { MarketName } from '../proposal/market-name'; import { MarketName } from '../proposal/market-name';
import { Indicator } from '../proposal/indicator'; import { Indicator } from '../proposal/indicator';
import { type ProposalNode } from '../proposal/proposal-utils';
export const CompactVotes = ({ number }: { number: BigNumber }) => ( export const CompactVotes = ({ number }: { number: BigNumber }) => (
<CompactNumber <CompactNumber
@ -111,64 +110,24 @@ const Status = ({ reached, threshold, text, testId }: StatusProps) => {
export const VoteBreakdown = ({ export const VoteBreakdown = ({
proposal, proposal,
restData,
}: { }: {
proposal: Proposal | BatchProposal; proposal: Proposal | BatchProposal;
restData?: ProposalNode | null;
}) => { }) => {
if (proposal.__typename === 'Proposal') { if (proposal.__typename === 'Proposal') {
return <VoteBreakdownNormal proposal={proposal} />; return <VoteBreakdownNormal proposal={proposal} />;
} }
if (proposal.__typename === 'BatchProposal') { if (proposal.__typename === 'BatchProposal') {
return <VoteBreakdownBatch proposal={proposal} restData={restData} />; return <VoteBreakdownBatch proposal={proposal} />;
} }
return null; return null;
}; };
const VoteBreakdownBatch = ({ const VoteBreakdownBatch = ({ proposal }: { proposal: BatchProposal }) => {
proposal,
restData,
}: {
proposal: BatchProposal;
restData?: ProposalNode | null;
}) => {
const [fullBreakdown, setFullBreakdown] = useState(false); const [fullBreakdown, setFullBreakdown] = useState(false);
const { t } = useTranslation(); const { t } = useTranslation();
const yesELS =
restData?.yes?.reduce((all, y) => {
if (y.elsPerMarket) {
y.elsPerMarket.forEach((item) => {
const share = Number(item.els);
if (all[item.marketId]) {
all[item.marketId].push(share);
} else {
all[item.marketId] = [share];
}
return all;
});
}
return all;
}, {} as Record<string, number[]>) || {};
const noELS =
restData?.no?.reduce((all, y) => {
if (y.elsPerMarket) {
y.elsPerMarket.forEach((item) => {
const share = Number(item.els);
if (all[item.marketId]) {
all[item.marketId].push(share);
} else {
all[item.marketId] = [share];
}
return all;
});
}
return all;
}, {} as Record<string, number[]>) || {};
const voteInfo = useBatchVoteInformation({ const voteInfo = useBatchVoteInformation({
terms: compact( terms: compact(
proposal.subProposals ? proposal.subProposals.map((p) => p?.terms) : [] proposal.subProposals ? proposal.subProposals.map((p) => p?.terms) : []
@ -235,8 +194,6 @@ const VoteBreakdownBatch = ({
proposal={proposal} proposal={proposal}
votes={proposal.votes} votes={proposal.votes}
terms={p.terms} terms={p.terms}
yesELS={yesELS}
noELS={noELS}
/> />
); );
})} })}
@ -297,8 +254,6 @@ const VoteBreakdownBatch = ({
proposal={proposal} proposal={proposal}
votes={proposal.votes} votes={proposal.votes}
terms={p.terms} terms={p.terms}
yesELS={yesELS}
noELS={noELS}
/> />
); );
})} })}
@ -316,17 +271,17 @@ const VoteBreakdownBatchSubProposal = ({
votes, votes,
terms, terms,
indicator, indicator,
yesELS,
noELS,
}: { }: {
proposal: BatchProposal; proposal: BatchProposal;
votes: VoteFieldsFragment; votes: VoteFieldsFragment;
terms: ProposalTermsFieldsFragment; terms: ProposalTermsFieldsFragment;
indicator?: number; indicator?: number;
yesELS: Record<string, number[]>;
noELS: Record<string, number[]>;
}) => { }) => {
const { t } = useTranslation(); const { t } = useTranslation();
const voteInfo = useVoteInformation({
votes,
terms,
});
const isProposalOpen = proposal?.state === ProposalState.STATE_OPEN; const isProposalOpen = proposal?.state === ProposalState.STATE_OPEN;
const isUpdateMarket = terms?.change?.__typename === 'UpdateMarket'; const isUpdateMarket = terms?.change?.__typename === 'UpdateMarket';
@ -339,15 +294,6 @@ const VoteBreakdownBatchSubProposal = ({
marketId = terms.change.market.id; marketId = terms.change.market.id;
} }
const voteInfo = useVoteInformation({
votes,
terms,
// yes votes ELS for this specific proposal (market)
yesELS: marketId ? yesELS[marketId] : undefined,
// no votes ELS for this specific proposal (market)
noELS: marketId ? noELS[marketId] : undefined,
});
const marketName = marketId ? ( const marketName = marketId ? (
<> <>
: <MarketName marketId={marketId} /> : <MarketName marketId={marketId} />

View File

@ -8,18 +8,13 @@ import {
type VoteFieldsFragment, type VoteFieldsFragment,
} from '../__generated__/Proposals'; } from '../__generated__/Proposals';
import { type ProposalChangeType } from '../types'; import { type ProposalChangeType } from '../types';
import sum from 'lodash/sum';
export const useVoteInformation = ({ export const useVoteInformation = ({
votes, votes,
terms, terms,
yesELS,
noELS,
}: { }: {
votes: VoteFieldsFragment; votes: VoteFieldsFragment;
terms: ProposalTermsFieldsFragment; terms: ProposalTermsFieldsFragment;
yesELS?: number[];
noELS?: number[];
}) => { }) => {
const { const {
appState: { totalSupply, decimals }, appState: { totalSupply, decimals },
@ -36,9 +31,7 @@ export const useVoteInformation = ({
paramsForChange, paramsForChange,
votes, votes,
totalSupply, totalSupply,
decimals, decimals
yesELS,
noELS
); );
}; };
@ -79,11 +72,7 @@ const getVoteData = (
}, },
votes: ProposalFieldsFragment['votes'], votes: ProposalFieldsFragment['votes'],
totalSupply: BigNumber, totalSupply: BigNumber,
decimals: number, decimals: number
/** A list of ELS yes votes */
yesELS?: number[],
/** A list if ELS no votes */
noELS?: number[]
) => { ) => {
const requiredMajorityPercentage = params.requiredMajority const requiredMajorityPercentage = params.requiredMajority
? new BigNumber(params.requiredMajority).times(100) ? new BigNumber(params.requiredMajority).times(100)
@ -97,31 +86,17 @@ const getVoteData = (
addDecimal(votes.no.totalTokens ?? 0, decimals) addDecimal(votes.no.totalTokens ?? 0, decimals)
); );
let noEquityLikeShareWeight = !votes.no.totalEquityLikeShareWeight const noEquityLikeShareWeight = !votes.no.totalEquityLikeShareWeight
? new BigNumber(0) ? new BigNumber(0)
: new BigNumber(votes.no.totalEquityLikeShareWeight).times(100); : new BigNumber(votes.no.totalEquityLikeShareWeight).times(100);
// there's no meaningful `totalEquityLikeShareWeight` in batch proposals,
// it has to be deduced from `elsPerMarket` of `no` votes of given proposal
// data. (by REST DATA)
if (noELS != null) {
const noTotalELS = sum(noELS);
noEquityLikeShareWeight = new BigNumber(noTotalELS).times(100);
}
const yesTokens = new BigNumber( const yesTokens = new BigNumber(
addDecimal(votes.yes.totalTokens ?? 0, decimals) addDecimal(votes.yes.totalTokens ?? 0, decimals)
); );
let yesEquityLikeShareWeight = !votes.yes.totalEquityLikeShareWeight const yesEquityLikeShareWeight = !votes.yes.totalEquityLikeShareWeight
? new BigNumber(0) ? new BigNumber(0)
: new BigNumber(votes.yes.totalEquityLikeShareWeight).times(100); : new BigNumber(votes.yes.totalEquityLikeShareWeight).times(100);
// there's no meaningful `totalEquityLikeShareWeight` in batch proposals,
// it has to be deduced from `elsPerMarket` of `yes` votes of given proposal
// data. (by REST DATA)
if (noELS != null) {
const yesTotalELS = sum(yesELS);
yesEquityLikeShareWeight = new BigNumber(yesTotalELS).times(100);
}
const totalTokensVoted = yesTokens.plus(noTokens); const totalTokensVoted = yesTokens.plus(noTokens);

View File

@ -39,8 +39,6 @@ const nextConfig = {
GIT_COMMIT: commitHash, GIT_COMMIT: commitHash,
GIT_TAG: tag, GIT_TAG: tag,
}, },
basePath: '/apps/vegas', // Set the base path
assetPrefix: '/apps/vegas', // Set the asset prefix
}; };
module.exports = SENTRY_AUTH_TOKEN module.exports = SENTRY_AUTH_TOKEN

View File

@ -1,5 +1,5 @@
import * as Schema from '@vegaprotocol/types'; import * as Schema from '@vegaprotocol/types';
import { determineId } from '../utils'; import { determineId } from '@vegaprotocol/wallet';
import { setGraphQLEndpoint } from './request'; import { setGraphQLEndpoint } from './request';
import { vote } from './vote'; import { vote } from './vote';
import { stakeForVegaPublicKey } from './ethereum-setup'; import { stakeForVegaPublicKey } from './ethereum-setup';

View File

@ -1,7 +1,6 @@
import type { ProposalSubmissionBody } from '@vegaprotocol/wallet'; import { determineId, type ProposalSubmissionBody } from '@vegaprotocol/wallet';
import { sendVegaTx } from './wallet-client'; import { sendVegaTx } from './wallet-client';
import { waitForProposal } from './propose-market'; import { waitForProposal } from './propose-market';
import { determineId } from '../utils';
const vegaPubKey = Cypress.env('VEGA_PUBLIC_KEY'); const vegaPubKey = Cypress.env('VEGA_PUBLIC_KEY');
export async function submitProposal(proposalTx: ProposalSubmissionBody) { export async function submitProposal(proposalTx: ProposalSubmissionBody) {

View File

@ -1,15 +1,5 @@
import { ethers } from 'ethers';
import sha3 from 'js-sha3';
import BigNumber from 'bignumber.js'; import BigNumber from 'bignumber.js';
/**
* copy of determineId in libs/wallet/src/utils.ts
* to avoid pulling in any jsx files which will cypress is not set up to compile
*/
export function determineId(sig: string) {
return sha3.sha3_256(ethers.utils.arrayify('0x' + sig));
}
/** /**
* copy of removeDecimal from libs/react-helpers/src/lib/format/number.tsx * copy of removeDecimal from libs/react-helpers/src/lib/format/number.tsx
* to avoid pulling in any jsx files which will cypress is not set up to compile * to avoid pulling in any jsx files which will cypress is not set up to compile

View File

@ -34,21 +34,6 @@
"options": { "options": {
"jestConfig": "libs/types/jest.config.ts" "jestConfig": "libs/types/jest.config.ts"
} }
},
"generate": {
"executor": "nx:run-commands",
"options": {
"commands": ["npx graphql-codegen --config=libs/types/codegen.yml"],
"parallel": false
}
},
"local-registry": {
"executor": "@nx/js:verdaccio",
"options": {
"port": 4873,
"config": ".verdaccio/config.yml",
"storage": "tmp/local-registry/storage"
}
} }
}, },
"tags": [] "tags": []

View File

@ -35,14 +35,6 @@
"options": { "options": {
"jestConfig": "libs/utils/jest.config.ts" "jestConfig": "libs/utils/jest.config.ts"
} }
},
"local-registry": {
"executor": "@nx/js:verdaccio",
"options": {
"port": 4873,
"config": ".verdaccio/config.yml",
"storage": "tmp/local-registry/storage"
}
} }
}, },
"tags": [] "tags": []

View File

@ -3,8 +3,6 @@
"version": "0.0.3", "version": "0.0.3",
"dependencies": { "dependencies": {
"@vegaprotocol/types": "0.0.7", "@vegaprotocol/types": "0.0.7",
"@vegaprotocol/utils": "0.0.11",
"ethers": "^5.6.0",
"eventemitter3": "^5.0.1", "eventemitter3": "^5.0.1",
"js-sha3": "^0.8.0", "js-sha3": "^0.8.0",
"zustand": "^4.5.0" "zustand": "^4.5.0"

View File

@ -15,7 +15,7 @@
"project": "libs/wallet/package.json", "project": "libs/wallet/package.json",
"compiler": "swc", "compiler": "swc",
"format": ["esm"], "format": ["esm"],
"external": ["@vegaprotocol/types", "@vegaprotocol/utils"] "external": ["@vegaprotocol/types"]
} }
}, },
"publish": { "publish": {
@ -35,14 +35,6 @@
"options": { "options": {
"jestConfig": "libs/wallet/jest.config.ts" "jestConfig": "libs/wallet/jest.config.ts"
} }
},
"local-registry": {
"executor": "@nx/js:verdaccio",
"options": {
"port": 4873,
"config": ".verdaccio/config.yml",
"storage": "tmp/local-registry/storage"
}
} }
}, },
"tags": [] "tags": []

View File

@ -1,6 +1,6 @@
import { type StoreApi } from 'zustand'; import { type StoreApi } from 'zustand';
import { type Store, type Connector } from '../types'; import { type Store, type Connector } from '../types';
import { isValidVegaPublicKey } from '@vegaprotocol/utils'; import { type TransactionResponse } from '../transaction-types';
import { import {
ConnectorError, ConnectorError,
chainIdError, chainIdError,
@ -9,7 +9,7 @@ import {
sendTransactionError, sendTransactionError,
userRejectedError, userRejectedError,
} from '../errors'; } from '../errors';
import { type TransactionResponse } from '../transaction-types'; import { isValidVegaPublicKey } from '../utils';
export class ViewPartyConnector implements Connector { export class ViewPartyConnector implements Connector {
readonly id = 'viewParty'; readonly id = 'viewParty';

View File

@ -1,4 +1,3 @@
import { ethers } from 'ethers';
import { sha3_256 } from 'js-sha3'; import { sha3_256 } from 'js-sha3';
import { import {
type ApplyReferralCode, type ApplyReferralCode,
@ -20,16 +19,20 @@ import {
* Can match up the newly created order with incoming orders via a subscription * Can match up the newly created order with incoming orders via a subscription
*/ */
export const determineId = (sig: string) => { export const determineId = (sig: string) => {
return sha3_256(ethers.utils.arrayify('0x' + sig)); return sha3_256(new Uint8Array(hexToBytes(sig)));
}; };
/** function hexToBytes(hex: string) {
* Base64 encode a transaction object const bytes = [];
*/ for (let i = 0; i < hex.length; i += 2) {
export const encodeTransaction = (tx: Transaction): string => { bytes.push(parseInt(hex.substring(i, i + 2), 16));
return ethers.utils.base64.encode( }
ethers.utils.toUtf8Bytes(JSON.stringify(tx)) return bytes;
); }
/* Validates string is 64 chars hex string */
export const isValidVegaPublicKey = (value: string) => {
return /^[A-Fa-f0-9]{64}$/i.test(value);
}; };
/** /**

View File

@ -241,5 +241,8 @@
"graphql": "15.8.0", "graphql": "15.8.0",
"//": "workaround storybook issue: https://github.com/storybookjs/storybook/issues/21642", "//": "workaround storybook issue: https://github.com/storybookjs/storybook/issues/21642",
"@storybook/react-docgen-typescript-plugin": "1.0.6--canary.9.cd77847.0" "@storybook/react-docgen-typescript-plugin": "1.0.6--canary.9.cd77847.0"
},
"nx": {
"includedScripts": []
} }
} }

14
project.json Normal file
View File

@ -0,0 +1,14 @@
{
"name": "nx-monorepo",
"$schema": "node_modules/nx/schemas/project-schema.json",
"targets": {
"local-registry": {
"executor": "@nx/js:verdaccio",
"options": {
"port": 4873,
"config": ".verdaccio/config.yml",
"storage": "tmp/local-registry/storage"
}
}
}
}