Skip to content

Commit

Permalink
refactor: clean wallet files
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben-Rey committed Nov 18, 2024
1 parent ec4fad1 commit 8a64750
Show file tree
Hide file tree
Showing 13 changed files with 19 additions and 82 deletions.
13 changes: 3 additions & 10 deletions src/bearbyWallet/BearbyWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,11 @@ export class BearbyWallet implements Wallet {
return [new BearbyAccount(await web3.wallet.account.base58)];
}

public async importAccount(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
publicKey: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
privateKey: string,
): Promise<void> {
public async importAccount(): Promise<void> {
throw new Error('Method not implemented.');
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
public async deleteAccount(address: string): Promise<void> {
public async deleteAccount(): Promise<void> {
throw new Error('Method not implemented.');
}

Expand All @@ -48,8 +42,7 @@ export class BearbyWallet implements Wallet {
return networkInfos();
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
public async setRpcUrl(url: string): Promise<void> {
public async setRpcUrl(): Promise<void> {
throw new Error(
'setRpcUrl is not yet implemented for the current provider.',
);
Expand Down
29 changes: 16 additions & 13 deletions src/metamaskSnap/MetamaskWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ export class MetamaskWallet implements Wallet {
throw new Error('Method not implemented.');
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
public async deleteAccount(address: string): Promise<void> {
public async deleteAccount(): Promise<void> {
throw new Error('Method not implemented.');
}

Expand All @@ -70,6 +69,12 @@ export class MetamaskWallet implements Wallet {
};
}

/**
* Sets the RPC URL for the MetaMask provider.
*
* @param url - The new RPC URL.
* @returns A promise that resolves when the RPC URL is updated.
*/
public async setRpcUrl(url: string): Promise<void> {
await setRpcUrl(this.metamaskProvider, { network: url });
}
Expand All @@ -87,21 +92,15 @@ export class MetamaskWallet implements Wallet {
/**
* Subscribes to network changes.
*
* @param callback - Callback to be called when the network changes.
*
* @returns A promise that resolves to a function that can be called to unsubscribe.
*
* @remarks
* Don't forget to unsubscribe to avoid memory leaks.
* @param callback - Callback function called when the network changes.
* @returns An object with an `unsubscribe` method to stop listening.
* @remarks Periodically checks for network changes every 500ms.
*
* @example
* ```typescript
* // Subscribe
* const observer = await provider.listenNetworkChanges((network) => {
* console.log(network);
* console.log(network);
* });
*
* // Unsubscribe
* observer.unsubscribe();
* ```
*/
Expand All @@ -110,7 +109,6 @@ export class MetamaskWallet implements Wallet {
): { unsubscribe: () => void } | undefined {
this.eventsListener.on(METAMASK_NETWORK_CHANGED, (evt) => callback(evt));

// check periodically if network changed
const intervalId = setInterval(async () => {
const network = await this.networkInfos();
if (!this.currentNetwork) {
Expand All @@ -135,6 +133,11 @@ export class MetamaskWallet implements Wallet {
};
}

/**
* Connects to MetaMask and ensures it is unlocked and ready.
*
* @returns A promise that resolves to `true` if connected successfully, otherwise `false`.
*/
public async connect() {
try {
const isUnlocked = await isMetaMaskUnlocked();
Expand Down
6 changes: 0 additions & 6 deletions src/metamaskSnap/services/buyRolls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ export type BuyRollsResponse = {
operationId: string;
};

/**
* Function that calls the MetaMask provider to buy rolls
* @param provider - The MetaMask provider
* @param params - The buy rolls parameters (fee and amount)
* @returns The operationId of the operation
*/
export const buyRolls = async (
provider: MetaMaskInpageProvider,
params: BuyRollsParams,
Expand Down
6 changes: 0 additions & 6 deletions src/metamaskSnap/services/callSC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ export type CallSCResponse = {
operationId: string;
};

/**
* Function that calls the MetaMask provider to call a smart contract
* @param provider - The MetaMask provider
* @param params - The call smart contract parameters (see massa standard)
* @returns The response of the operation
*/
export const callSC = async (
provider: MetaMaskInpageProvider,
params: CallSCParams,
Expand Down
5 changes: 0 additions & 5 deletions src/metamaskSnap/services/getActiveAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ export type ActiveAccountResponse = {
address: string;
};

/**
* Function that calls the MetaMask provider to get the active account
* @param provider - The MetaMask provider
* @returns The active account address
*/
export const getActiveAccount = async (
provider: MetaMaskInpageProvider,
): Promise<ActiveAccountResponse | undefined> => {
Expand Down
5 changes: 0 additions & 5 deletions src/metamaskSnap/services/getMinimalFees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ import { MetaMaskInpageProvider } from '@metamask/providers';
import { getNetwork } from './getNetwork';
import { Mas } from '@massalabs/massa-web3';

/**
* Function that calls the MetaMask provider to get the current network
* @param provider - The MetaMask provider
* @returns The current network details
*/
export const getMinimalFees = async (
provider: MetaMaskInpageProvider,
): Promise<bigint> => {
Expand Down
5 changes: 0 additions & 5 deletions src/metamaskSnap/services/getNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ export type NetworkResponse = {
minimalFees: string;
};

/**
* Function that calls the MetaMask provider to get the current network
* @param provider - The MetaMask provider
* @returns The current network details
*/
export const getNetwork = async (
provider: MetaMaskInpageProvider,
): Promise<NetworkResponse | undefined> => {
Expand Down
6 changes: 0 additions & 6 deletions src/metamaskSnap/services/readSC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ export type ReadSCResponse = {
};
};

/**
* Function that calls the MetaMask provider to read a smart contract
* @param provider - The MetaMask provider
* @param params - The read smart contract parameters (see massa standard)
* @returns The response of the operation
*/
export const readSC = async (
provider: MetaMaskInpageProvider,
params: ReadSCParameters,
Expand Down
6 changes: 0 additions & 6 deletions src/metamaskSnap/services/sellRolls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ export type SellRollsResponse = {
operationId: string;
};

/**
* Function that calls the MetaMask provider to sell rolls
* @param provider - The MetaMask provider
* @param params - The sell rolls parameters (amount and fee)
* @returns The operation id of the sell rolls operation
*/
export const sellRolls = async (
provider: MetaMaskInpageProvider,
params: SellRollsParams,
Expand Down
6 changes: 0 additions & 6 deletions src/metamaskSnap/services/setRpcUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ export type SetRpcUrlResponse = {
network: string; // url
};

/**
* Function that calls the MetaMask provider to set a new rpc url
* @param provider - The MetaMask provider
* @param params - The set network parameters (network id to set as a string)
* @returns The response of the operation
*/
export const setRpcUrl = async (
provider: MetaMaskInpageProvider,
params: SetRpcUrlParams,
Expand Down
6 changes: 0 additions & 6 deletions src/metamaskSnap/services/signMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ export type SignMessageResponse = {
publicKey: string;
};

/**
* Function that calls the MetaMask provider to sign a message
* @param provider - The MetaMask provider
* @param params - The sign message parameters (serialized data message as bytes)
* @returns The signature and public key used to sign the message
*/
export const signMessage = async (
provider: MetaMaskInpageProvider,
params: SignMessageParams,
Expand Down
7 changes: 0 additions & 7 deletions src/metamaskSnap/services/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ export type TransferResponse = {
operationId: string;
};

/**
* Function that calls the MetaMask provider to transfer funds
* @param provider - The MetaMask provider
* @param params - The transfer parameters (recipient address, amount, and fee)
* @returns The operation id of the transfer operation
* @throws If the user denies the transaction
*/
export const transfer = async (
provider: MetaMaskInpageProvider,
params: TransferParams,
Expand Down
1 change: 0 additions & 1 deletion src/metamaskSnap/types/account-token.ts

This file was deleted.

0 comments on commit 8a64750

Please sign in to comment.