Skip to content
This repository has been archived by the owner on Dec 3, 2024. It is now read-only.

Commit

Permalink
feat: add genesis hash to injected accounts
Browse files Browse the repository at this point in the history
DApp will use this to determine which network can the account be used with.
This is especially important in this case, as accounts are always restricted to one network.
  • Loading branch information
tien committed Jul 1, 2024
1 parent ae02ce9 commit 240b709
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions packages/adapter/src/extension/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ interface IInjectPolkadotSnap extends IEnablePolkadotSnapParams {
injectedSnapId?: string;
}

function transformAccounts(accounts: string[]): InjectedAccount[] {
function transformAccounts(accounts: string[], config?: SnapConfig): InjectedAccount[] {
return accounts.map((address, i) => ({
address,
genesisHash: config?.genesisHash,
name: `Polkadot Snap #${i}`,
type: 'ed25519'
}));
Expand All @@ -46,7 +47,7 @@ function injectPolkadotSnap({
accounts: {
get: async (): Promise<InjectedAccount[]> => {
const response = await snap.getAddress();
return transformAccounts([response]);
return transformAccounts([response], config);
},
// Currently there is only available only one account, in that case this method will never return anything
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down
3 changes: 3 additions & 0 deletions packages/snap/src/configuration/predefined.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { SnapConfig } from '@chainsafe/metamask-polkadot-types';
export const kusamaConfiguration: SnapConfig = {
addressPrefix: 2,
networkName: 'kusama',
genesisHash: '0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe',
unit: {
decimals: 12,
image: 'https://svgshare.com/i/L3o.svg',
Expand All @@ -14,6 +15,7 @@ export const kusamaConfiguration: SnapConfig = {
export const westendConfiguration: SnapConfig = {
addressPrefix: 42,
networkName: 'westend',
genesisHash: '0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e',
unit: {
decimals: 12,
image: 'https://svgshare.com/i/L2d.svg',
Expand All @@ -25,6 +27,7 @@ export const westendConfiguration: SnapConfig = {
export const polkadotConfiguration: SnapConfig = {
addressPrefix: 0,
networkName: 'polkadot',
genesisHash: '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3',
unit: {
decimals: 12,
image: 'https://polkadot.js.org/apps/static/polkadot-circle.1eea41b2..svg',
Expand Down
3 changes: 2 additions & 1 deletion packages/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface ExportAccountRequest {
method: 'exportAccount';
params: {
jsonPassphrase?: string;
}
};
}

export interface GetTransactionsRequest {
Expand Down Expand Up @@ -136,6 +136,7 @@ export type SnapNetworks = 'polkadot' | 'kusama' | 'westend' | string;

export interface SnapConfig {
networkName: SnapNetworks;
genesisHash?: `0x${string}`;
wsRpcUrl?: string;
addressPrefix?: number;
unit?: UnitConfiguration;
Expand Down

0 comments on commit 240b709

Please sign in to comment.