chore: remove dependency on utils and ethers from wallet

This commit is contained in:
Matthew Russell 2024-03-08 21:38:45 +00:00
parent 2d98205028
commit a4bc1cf95d
No known key found for this signature in database
7 changed files with 11 additions and 18 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,7 +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",
"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

@ -25,11 +25,16 @@ export const determineId = (sig: string) => {
function hexToBytes(hex: string) { function hexToBytes(hex: string) {
const bytes = []; const bytes = [];
for (let i = 0; i < hex.length; i += 2) { for (let i = 0; i < hex.length; i += 2) {
bytes.push(parseInt(hex.substr(i, 2), 16)); bytes.push(parseInt(hex.substring(i, i + 2), 16));
} }
return bytes; return bytes;
} }
/* Validates string is 64 chars hex string */
export const isValidVegaPublicKey = (value: string) => {
return /^[A-Fa-f0-9]{64}$/i.test(value);
};
/** /**
* TODO: We may want to create a package similar to @metamask/detect-ethereum-provider as this wont suffice * TODO: We may want to create a package similar to @metamask/detect-ethereum-provider as this wont suffice
* if called immeidately, and before the extension has been able to add the vega object to the window * if called immeidately, and before the extension has been able to add the vega object to the window