chore(wallet): reduce bundle size by removing unnecessary deps (#5955)

This commit is contained in:
Matthew Russell 2024-03-11 14:07:45 +00:00 committed by GitHub
parent a77858c1c0
commit 2e28a175ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 17 additions and 27 deletions

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

@ -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": {

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);
}; };
/** /**