Skip to content

Commit

Permalink
chore: set get-starknet Snap's version through env variable (#435)
Browse files Browse the repository at this point in the history
* chore: fix get-starknet snap version through env variable

* chore: add SNAP_VERSION env set in webpack config

* chore: pr comments handled

* chore: fix lint

* chore: updated workflow to use SNAP_VERSION for get-starknet
  • Loading branch information
khanti42 authored Nov 25, 2024
1 parent fe2b8a5 commit 08640d3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ jobs:
echo "Building Get Starknet with GET_STARKNET_PUBLIC_PATH=$GET_STARKNET_PUBLIC_PATH"
GET_STARKNET_PUBLIC_PATH=$GET_STARKNET_PUBLIC_PATH yarn workspace @consensys/get-starknet build
SNAP_VERSION="${VERSION}" GET_STARKNET_PUBLIC_PATH=$GET_STARKNET_PUBLIC_PATH yarn workspace @consensys/get-starknet build
env:
SNAP_ENV: ${{ needs.prepare-deployment.outputs.ENV }}
VERSION: ${{ needs.prepare-deployment.outputs.VERSION }}
Expand Down
16 changes: 14 additions & 2 deletions packages/get-starknet/src/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,26 @@ export class MetaMaskSnapWallet implements StarknetWindowObject {
// eslint-disable-next-line @typescript-eslint/naming-convention, no-restricted-globals
static readonly snapId = process.env.SNAP_ID ?? 'npm:@consensys/starknet-snap';

constructor(metamaskProvider: MetaMaskProvider, snapVersion = '*') {
// eslint-disable-next-line @typescript-eslint/naming-convention, no-restricted-globals
static readonly snapVersion = process.env.SNAP_VERSION ?? '*';

/**
* Initializes a new instance of the MetaMaskSnapWallet class.
*
* The Snap version is now enforced globally via a static `snapVersion` property,
* this ensures consistent versioning across all instances and removes the need for consumers to specify it.
*
* @param metamaskProvider - The MetaMask Wallet Provider.
* @param _snapVersion - The `_snapVersion` parameter remains to maintain compatibility with existing usage.
*/
constructor(metamaskProvider: MetaMaskProvider, _snapVersion = '*') {
this.id = 'metamask';
this.name = 'Metamask';
this.version = 'v2.0.0';
this.icon = WalletIconMetaData;
this.lock = new Mutex();
this.metamaskProvider = metamaskProvider;
this.snap = new MetaMaskSnap(MetaMaskSnapWallet.snapId, snapVersion, this.metamaskProvider);
this.snap = new MetaMaskSnap(MetaMaskSnapWallet.snapId, MetaMaskSnapWallet.snapVersion, this.metamaskProvider);
this.isConnected = false;

this.#rpcHandlers = new Map<string, IStarknetWalletRpc>([
Expand Down
1 change: 1 addition & 0 deletions packages/get-starknet/webpack.config.build.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = (env) =>
plugins: [
new webpack.DefinePlugin({
'process.env.SNAP_ID': JSON.stringify(process.env.SNAP_ID || 'npm:@consensys/starknet-snap'),
'process.env.SNAP_VERSION': JSON.stringify(process.env.SNAP_VERSION || '*'),
}),
new ModuleFederationPlugin({
name: 'MetaMaskStarknetSnapWallet',
Expand Down

0 comments on commit 08640d3

Please sign in to comment.