@cartridge/controller 0.7.13-alpha.2 → 0.7.13-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,6 +4,7 @@ export declare class MetaMaskWallet implements WalletAdapter {
4
4
  readonly platform: ExternalPlatform;
5
5
  private MMSDK;
6
6
  private account;
7
+ private connectedAccounts;
7
8
  constructor();
8
9
  isAvailable(): boolean;
9
10
  getInfo(): ExternalWallet;
@@ -5,6 +5,7 @@ export declare class RabbyWallet implements WalletAdapter {
5
5
  private account;
6
6
  private store;
7
7
  private provider;
8
+ private connectedAccounts;
8
9
  constructor();
9
10
  isAvailable(): boolean;
10
11
  getInfo(): ExternalWallet;
@@ -7,6 +7,7 @@ export interface ExternalWallet {
7
7
  chainId?: string;
8
8
  name?: string;
9
9
  platform?: ExternalPlatform;
10
+ connectedAccounts?: string[];
10
11
  }
11
12
  export interface ExternalWalletResponse<T = unknown> {
12
13
  success: boolean;
@@ -5,7 +5,7 @@ export declare class WalletConnectWallet implements WalletAdapter {
5
5
  readonly type: ExternalWalletType;
6
6
  readonly platform: ExternalPlatform;
7
7
  private account;
8
- constructor(provider: Provider);
8
+ constructor(provider: Provider, account?: string);
9
9
  isAvailable(): boolean;
10
10
  getInfo(): ExternalWallet;
11
11
  connect(): Promise<ExternalWalletResponse<any>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cartridge/controller",
3
- "version": "0.7.13-alpha.2",
3
+ "version": "0.7.13-alpha.4",
4
4
  "description": "Cartridge Controller",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -36,8 +36,8 @@
36
36
  "cbor-x": "^1.5.0",
37
37
  "mipd": "^0.0.7",
38
38
  "@walletconnect/ethereum-provider": "^2.20.0",
39
- "@cartridge/account-wasm": "0.7.13-alpha.2",
40
- "@cartridge/utils": "0.7.13-alpha.2"
39
+ "@cartridge/account-wasm": "0.7.13-alpha.4",
40
+ "@cartridge/utils": "0.7.13-alpha.4"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/jest": "^29.5.14",
@@ -53,7 +53,7 @@
53
53
  "vite-plugin-node-polyfills": "^0.22.0",
54
54
  "vite-plugin-top-level-await": "^1.4.4",
55
55
  "vite-plugin-wasm": "^3.4.1",
56
- "@cartridge/tsconfig": "0.7.13-alpha.2"
56
+ "@cartridge/tsconfig": "0.7.13-alpha.4"
57
57
  },
58
58
  "scripts": {
59
59
  "build:deps": "pnpm build",
@@ -20,10 +20,14 @@ export class WalletBridge {
20
20
 
21
21
  constructor() {
22
22
  this.walletAdapters = new Map<ExternalWalletType, WalletAdapter>();
23
- this.walletAdapters.set("metamask", new MetaMaskWallet());
24
- this.walletAdapters.set("phantom", new PhantomWallet());
25
- this.walletAdapters.set("argent", new ArgentWallet());
26
- this.walletAdapters.set("rabby", new RabbyWallet());
23
+ const metamask = new MetaMaskWallet();
24
+ metamask.isAvailable() && this.walletAdapters.set("metamask", metamask);
25
+ const phantom = new PhantomWallet();
26
+ phantom.isAvailable() && this.walletAdapters.set("phantom", phantom);
27
+ const argent = new ArgentWallet();
28
+ argent.isAvailable() && this.walletAdapters.set("argent", argent);
29
+ const rabby = new RabbyWallet();
30
+ rabby.isAvailable() && this.walletAdapters.set("rabby", rabby);
27
31
 
28
32
  if (typeof window !== "undefined") {
29
33
  window.wallet_bridge = this;
@@ -12,6 +12,7 @@ export class MetaMaskWallet implements WalletAdapter {
12
12
  readonly platform: ExternalPlatform = "ethereum";
13
13
  private MMSDK: MetaMaskSDK;
14
14
  private account: string | undefined = undefined;
15
+ private connectedAccounts: string[] = [];
15
16
 
16
17
  constructor() {
17
18
  this.MMSDK = new MetaMaskSDK({
@@ -20,6 +21,19 @@ export class MetaMaskWallet implements WalletAdapter {
20
21
  url: window.location.href,
21
22
  },
22
23
  });
24
+ this.MMSDK.sdkInitPromise?.then(() => {
25
+ this.MMSDK.getProvider()
26
+ ?.request({
27
+ method: "eth_accounts",
28
+ })
29
+ .then((accounts: any) => {
30
+ if (accounts && accounts.length > 0) {
31
+ console.log(accounts);
32
+ this.account = accounts[0];
33
+ this.connectedAccounts = accounts;
34
+ }
35
+ });
36
+ });
23
37
  }
24
38
 
25
39
  isAvailable(): boolean {
@@ -36,6 +50,7 @@ export class MetaMaskWallet implements WalletAdapter {
36
50
  chainId: available ? window.ethereum?.chainId : undefined,
37
51
  name: "MetaMask",
38
52
  platform: this.platform,
53
+ connectedAccounts: this.connectedAccounts,
39
54
  };
40
55
  }
41
56
 
@@ -52,6 +67,7 @@ export class MetaMaskWallet implements WalletAdapter {
52
67
  const accounts = await this.MMSDK.connect();
53
68
  if (accounts && accounts.length > 0) {
54
69
  this.account = accounts[0];
70
+ this.connectedAccounts = accounts;
55
71
  return { success: true, wallet: this.type, account: this.account };
56
72
  }
57
73
 
@@ -15,19 +15,19 @@ export class RabbyWallet implements WalletAdapter {
15
15
  private account: string | undefined = undefined;
16
16
  private store = createStore();
17
17
  private provider: EIP6963ProviderDetail | undefined;
18
+ private connectedAccounts: string[] = [];
18
19
 
19
20
  constructor() {
20
21
  this.provider = this.store
21
22
  .getProviders()
22
23
  .find((provider) => provider.info.rdns === RABBY_RDNS);
23
- this.store.subscribe((providerDetails) => {
24
- const rabbyProvider = providerDetails.find(
25
- (provider) => provider.info.rdns === RABBY_RDNS,
26
- );
27
- if (rabbyProvider) {
28
- this.provider = rabbyProvider;
29
- }
30
- });
24
+ this.provider?.provider
25
+ .request({
26
+ method: "eth_accounts",
27
+ })
28
+ .then((accounts) => {
29
+ this.connectedAccounts = accounts;
30
+ });
31
31
  }
32
32
 
33
33
  isAvailable(): boolean {
@@ -44,6 +44,7 @@ export class RabbyWallet implements WalletAdapter {
44
44
  chainId: available ? window.ethereum?.chainId : undefined,
45
45
  name: "Rabby",
46
46
  platform: this.platform,
47
+ connectedAccounts: this.connectedAccounts,
47
48
  };
48
49
  }
49
50
 
@@ -62,6 +63,7 @@ export class RabbyWallet implements WalletAdapter {
62
63
  });
63
64
  if (accounts && accounts.length > 0) {
64
65
  this.account = accounts[0];
66
+ this.connectedAccounts = accounts;
65
67
  return { success: true, wallet: this.type, account: this.account };
66
68
  }
67
69
 
@@ -8,6 +8,7 @@ export interface ExternalWallet {
8
8
  chainId?: string;
9
9
  name?: string;
10
10
  platform?: ExternalPlatform;
11
+ connectedAccounts?: string[];
11
12
  }
12
13
 
13
14
  export interface ExternalWalletResponse<T = unknown> {
@@ -12,7 +12,12 @@ export class WalletConnectWallet implements WalletAdapter {
12
12
  readonly platform: ExternalPlatform = "ethereum";
13
13
  private account: string | undefined = undefined;
14
14
 
15
- constructor(private provider: Provider) {}
15
+ constructor(
16
+ private provider: Provider,
17
+ account?: string,
18
+ ) {
19
+ this.account = account;
20
+ }
16
21
 
17
22
  isAvailable(): boolean {
18
23
  return !!this.provider;