Skip to content

Commit

Permalink
Export function to detect if wallet plugin is installed
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben-Rey committed Feb 5, 2024
1 parent 2e42483 commit 5228c16
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,8 @@ export { MassaStationAccount } from './massaStation/MassaStationAccount';
export { providers, ProvidersListener } from './providersManager';

export { connectBearby, disconnectBearby } from './bearbyWallet/BearbyConnect';

export {
isMassaStationInstalled,
isMassaWalletPluginInstalled,
} from './massaStation/MassaStationDiscovery';
9 changes: 2 additions & 7 deletions src/massaStation/MassaStationAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ import { IAccountSignOutput, ISignMessage } from '../account/AccountSign';
import { encode as base58Encode } from 'bs58check';
import { ExecuteFunctionBody } from './types';

/**
* The maximum allowed gas for a read operation
*/
const MAX_READ_BLOCK_GAS = BigInt(4_294_967_295);

/**
* This interface represents the the individual wallet's final and pending balances returned by MassaStation
*/
Expand Down Expand Up @@ -360,11 +355,11 @@ export class MassaStationAccount implements IAccount {
): Promise<IContractReadOperationResponse> {
const node = await this.getNodeUrlFromMassaStation();
// Gas amount check
if (maxGas > MAX_READ_BLOCK_GAS) {
if (maxGas > MAX_GAS_CALL) {
throw new Error(
`
The gas submitted ${maxGas.toString()} exceeds the max. allowed block gas of
${MAX_READ_BLOCK_GAS.toString()}
${MAX_GAS_CALL.toString()}
`,
);
}
Expand Down
27 changes: 23 additions & 4 deletions src/massaStation/MassaStationDiscovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { PluginManagerBody } from './types';
export const MASSA_STATION_DISCOVERY_URL =
'https://station.massa/plugin-manager';

export const MASSA_STATION_PLUGIN_DISCOVERY_URL =
'https://station.massa//plugin-store';

const MS_WALLET_PLUGIN_NAME = 'Massa Wallet';
const MS_WALLET_PLUGIN_AUTHOR = 'Massa Labs';
// timeout
Expand All @@ -18,13 +21,29 @@ export async function isMassaStationInstalled(): Promise<boolean> {
TIMEOUT,
);

return !response.isError;
}

export async function isMassaWalletPluginInstalled(): Promise<boolean> {
const response = await getRequest<PluginManagerBody>(
MASSA_STATION_PLUGIN_DISCOVERY_URL,
TIMEOUT,
);

if (response.isError) {
return false;
}

const isMassaStation = (module) =>
module.name === MS_WALLET_PLUGIN_NAME &&
module.author === MS_WALLET_PLUGIN_AUTHOR;
return !!response.result.find(
(module) =>
module.name === MS_WALLET_PLUGIN_NAME &&
module.author === MS_WALLET_PLUGIN_AUTHOR,
);
}

export async function isMassaStationAndWalletPluginInstalled(): Promise<boolean> {
const isMassaStation = await isMassaStationInstalled();
const isMassaWalletPlugin = await isMassaWalletPluginInstalled();

return !!response.result.find(isMassaStation);
return isMassaStation && isMassaWalletPlugin;
}
4 changes: 2 additions & 2 deletions src/providersManager/providerList.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { web3 } from '@hicaru/bearby.js';
import { BearbyProvider } from '../bearbyWallet/BearbyProvider';
import { isMassaStationInstalled } from '../massaStation/MassaStationDiscovery';
import { isMassaStationAndWalletPluginInstalled } from '../massaStation/MassaStationDiscovery';
import { MassaStationProvider } from '../massaStation/MassaStationProvider';
import { IProvider } from '../provider/IProvider';

Expand All @@ -20,7 +20,7 @@ export const providerList: ProviderList[] = [
},
{
name: 'MASSA_STATION',
checkInstalled: isMassaStationInstalled,
checkInstalled: isMassaStationAndWalletPluginInstalled,
createInstance: () => new MassaStationProvider(),
isInstalled: false,
},
Expand Down

0 comments on commit 5228c16

Please sign in to comment.