@keplr-wallet/stores 0.11.17 → 0.11.18-alpha.2

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.
@@ -1,13 +1,25 @@
1
1
  import { InteractionStore } from "./interaction";
2
2
  import { ChainInfo } from "@keplr-wallet/types";
3
+ import { ChainInfoWithRepoUpdateOptions } from "@keplr-wallet/background";
3
4
  export declare class ChainSuggestStore {
4
5
  protected readonly interactionStore: InteractionStore;
6
+ protected readonly communityChainInfoRepo: {
7
+ readonly organizationName: string;
8
+ readonly repoName: string;
9
+ };
5
10
  protected _isLoading: boolean;
6
- constructor(interactionStore: InteractionStore);
11
+ communityChainInfo: ChainInfo | undefined;
12
+ constructor(interactionStore: InteractionStore, communityChainInfoRepo: {
13
+ readonly organizationName: string;
14
+ readonly repoName: string;
15
+ });
7
16
  get waitingSuggestedChainInfo(): import("@keplr-wallet/background").InteractionWaitingData<ChainInfo & {
8
17
  origin: string;
9
18
  }> | undefined;
10
- approve(): Generator<Generator<Promise<void>, void, unknown>, void, unknown>;
19
+ get communityChainInfoRepoUrl(): string;
20
+ getCommunityChainInfoUrl(chainId: string): string;
21
+ fetchCommunityChainInfo(): Generator<Promise<import("axios").AxiosResponse<ChainInfo, any>>, void, unknown>;
22
+ approve(chainInfo: ChainInfoWithRepoUpdateOptions): Generator<Generator<Promise<void>, void, unknown>, void, unknown>;
11
23
  reject(): Generator<Generator<Promise<void>, void, unknown>, void, unknown>;
12
24
  rejectAll(): Generator<Generator<Generator<Promise<void>, void, unknown>, void, unknown>, void, unknown>;
13
25
  get isLoading(): boolean;
@@ -5,14 +5,21 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
7
  };
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
8
11
  Object.defineProperty(exports, "__esModule", { value: true });
9
12
  exports.ChainSuggestStore = void 0;
10
13
  const background_1 = require("@keplr-wallet/background");
11
14
  const mobx_1 = require("mobx");
15
+ const cosmos_1 = require("@keplr-wallet/cosmos");
16
+ const axios_1 = __importDefault(require("axios"));
12
17
  class ChainSuggestStore {
13
- constructor(interactionStore) {
18
+ constructor(interactionStore, communityChainInfoRepo) {
14
19
  this.interactionStore = interactionStore;
20
+ this.communityChainInfoRepo = communityChainInfoRepo;
15
21
  this._isLoading = false;
22
+ this.communityChainInfo = undefined;
16
23
  mobx_1.makeObservable(this);
17
24
  }
18
25
  get waitingSuggestedChainInfo() {
@@ -21,12 +28,34 @@ class ChainSuggestStore {
21
28
  return datas[0];
22
29
  }
23
30
  }
24
- *approve() {
31
+ get communityChainInfoRepoUrl() {
32
+ return `https://github.com/${this.communityChainInfoRepo.organizationName}/${this.communityChainInfoRepo.repoName}`;
33
+ }
34
+ getCommunityChainInfoUrl(chainId) {
35
+ const chainIdHelper = cosmos_1.ChainIdHelper.parse(chainId);
36
+ return `${this.communityChainInfoRepoUrl}/blob/main/cosmos/${chainIdHelper.identifier}.json`;
37
+ }
38
+ *fetchCommunityChainInfo() {
39
+ this._isLoading = true;
40
+ if (this.waitingSuggestedChainInfo) {
41
+ try {
42
+ const chainIdentifier = cosmos_1.ChainIdHelper.parse(this.waitingSuggestedChainInfo.data.chainId).identifier;
43
+ const chainInfoResponse = yield axios_1.default.get(`/cosmos/${chainIdentifier}.json`, {
44
+ baseURL: `https://raw.githubusercontent.com/${this.communityChainInfoRepo.organizationName}/${this.communityChainInfoRepo.repoName}/main`,
45
+ });
46
+ this.communityChainInfo = chainInfoResponse.data;
47
+ }
48
+ finally {
49
+ this._isLoading = false;
50
+ }
51
+ }
52
+ }
53
+ *approve(chainInfo) {
25
54
  this._isLoading = true;
26
55
  try {
27
56
  const data = this.waitingSuggestedChainInfo;
28
57
  if (data) {
29
- yield this.interactionStore.approve(data.type, data.id, {});
58
+ yield this.interactionStore.approve(data.type, data.id, chainInfo);
30
59
  }
31
60
  }
32
61
  finally {
@@ -61,6 +90,12 @@ class ChainSuggestStore {
61
90
  __decorate([
62
91
  mobx_1.observable
63
92
  ], ChainSuggestStore.prototype, "_isLoading", void 0);
93
+ __decorate([
94
+ mobx_1.observable
95
+ ], ChainSuggestStore.prototype, "communityChainInfo", void 0);
96
+ __decorate([
97
+ mobx_1.flow
98
+ ], ChainSuggestStore.prototype, "fetchCommunityChainInfo", null);
64
99
  __decorate([
65
100
  mobx_1.flow
66
101
  ], ChainSuggestStore.prototype, "approve", null);
@@ -1 +1 @@
1
- {"version":3,"file":"chain-suggest.js","sourceRoot":"","sources":["../../../src/core/interaction/chain-suggest.ts"],"names":[],"mappings":";;;;;;;;;AAEA,yDAA+D;AAC/D,+BAAwD;AAExD,MAAa,iBAAiB;IAI5B,YAA+B,gBAAkC;QAAlC,qBAAgB,GAAhB,gBAAgB,CAAkB;QAFvD,eAAU,GAAY,KAAK,CAAC;QAGpC,qBAAc,CAAC,IAAI,CAAC,CAAC;IACvB,CAAC;IAED,IAAI,yBAAyB;QAC3B,MAAM,KAAK,GAAG,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAE1C,gCAAmB,CAAC,IAAI,EAAE,CAAC,CAAC;QAE9B,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;YACpB,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;SACjB;IACH,CAAC;IAGD,CAAC,OAAO;QACN,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QAEvB,IAAI;YACF,MAAM,IAAI,GAAG,IAAI,CAAC,yBAAyB,CAAC;YAC5C,IAAI,IAAI,EAAE;gBACR,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;aAC7D;SACF;gBAAS;YACR,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;SACzB;IACH,CAAC;IAGD,CAAC,MAAM;QACL,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QAEvB,IAAI;YACF,MAAM,IAAI,GAAG,IAAI,CAAC,yBAAyB,CAAC;YAC5C,IAAI,IAAI,EAAE;gBACR,MAAM,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;aACxD;SACF;gBAAS;YACR,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;SACzB;IACH,CAAC;IAGD,CAAC,SAAS;QACR,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,IAAI;YACF,MAAM,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,gCAAmB,CAAC,IAAI,EAAE,CAAC,CAAC;SACnE;gBAAS;YACR,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;SACzB;IACH,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;CACF;AAzDC;IADC,iBAAU;qDAC2B;AAiBtC;IADC,WAAI;gDAYJ;AAGD;IADC,WAAI;+CAYJ;AAGD;IADC,WAAI;kDAQJ;AAtDH,8CA2DC"}
1
+ {"version":3,"file":"chain-suggest.js","sourceRoot":"","sources":["../../../src/core/interaction/chain-suggest.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,yDAGkC;AAClC,+BAAwD;AACxD,iDAAqD;AACrD,kDAA0B;AAE1B,MAAa,iBAAiB;IAO5B,YACqB,gBAAkC,EAClC,sBAGlB;QAJkB,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,2BAAsB,GAAtB,sBAAsB,CAGxC;QAVO,eAAU,GAAY,KAAK,CAAC;QAGtC,uBAAkB,GAA0B,SAAS,CAAC;QASpD,qBAAc,CAAC,IAAI,CAAC,CAAC;IACvB,CAAC;IAED,IAAI,yBAAyB;QA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yBAAyB,CAAC;YAE5C,IAAI,IAAI,EAAE;gBACR,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC;aACpE;SACF;gBAAS;YACR,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;SACzB;IACH,CAAC;IAGD,CAAC,MAAM;QACL,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QAEvB,IAAI;YACF,MAAM,IAAI,GAAG,IAAI,CAAC,yBAAyB,CAAC;YAC5C,IAAI,IAAI,EAAE;gBACR,MAAM,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;aACxD;SACF;gBAAS;YACR,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;SACzB;IACH,CAAC;IAGD,CAAC,SAAS;QACR,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,IAAI;YACF,MAAM,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,gCAAmB,CAAC,IAAI,EAAE,CAAC,CAAC;SACnE;gBAAS;YACR,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;SACzB;IACH,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;CACF;AAnGC;IADC,iBAAU;qDAC2B;AAGtC;IADC,iBAAU;6DAC2C;AAgCtD;IADC,WAAI;gEAqBJ;AAGD;IADC,WAAI;gDAaJ;AAGD;IADC,WAAI;+CAYJ;AAGD;IADC,WAAI;kDAQJ;AAhGH,8CAqGC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keplr-wallet/stores",
3
- "version": "0.11.17",
3
+ "version": "0.11.18-alpha.2",
4
4
  "main": "build/index.js",
5
5
  "author": "chainapsis",
6
6
  "license": "Apache-2.0",
@@ -17,17 +17,17 @@
17
17
  "lint-fix": "eslint --fix \"src/**/*\" && prettier --write \"src/**/*\""
18
18
  },
19
19
  "devDependencies": {
20
- "@keplr-wallet/provider-mock": "0.11.17"
20
+ "@keplr-wallet/provider-mock": "0.11.18-alpha.2"
21
21
  },
22
22
  "dependencies": {
23
- "@keplr-wallet/background": "0.11.17",
24
- "@keplr-wallet/common": "0.11.17",
25
- "@keplr-wallet/cosmos": "0.11.17",
26
- "@keplr-wallet/crypto": "0.11.17",
27
- "@keplr-wallet/proto-types": "0.11.17",
28
- "@keplr-wallet/router": "0.11.17",
29
- "@keplr-wallet/types": "0.11.17",
30
- "@keplr-wallet/unit": "0.11.17",
23
+ "@keplr-wallet/background": "0.11.18-alpha.2",
24
+ "@keplr-wallet/common": "0.11.18-alpha.2",
25
+ "@keplr-wallet/cosmos": "0.11.18-alpha.2",
26
+ "@keplr-wallet/crypto": "0.11.18-alpha.2",
27
+ "@keplr-wallet/proto-types": "0.11.18-alpha.2",
28
+ "@keplr-wallet/router": "0.11.18-alpha.2",
29
+ "@keplr-wallet/types": "0.11.18-alpha.2",
30
+ "@keplr-wallet/unit": "0.11.18-alpha.2",
31
31
  "axios": "^0.27.2",
32
32
  "buffer": "^6.0.3",
33
33
  "deepmerge": "^4.2.2",
@@ -37,5 +37,5 @@
37
37
  "p-queue": "^6.6.2",
38
38
  "utility-types": "^3.10.0"
39
39
  },
40
- "gitHead": "8bc62c943a923d02727341ddc8768a3661dee11c"
40
+ "gitHead": "2e7c96c5af61ec73e920946ff3871de12d8c56c0"
41
41
  }
@@ -1,13 +1,27 @@
1
1
  import { InteractionStore } from "./interaction";
2
2
  import { ChainInfo } from "@keplr-wallet/types";
3
- import { SuggestChainInfoMsg } from "@keplr-wallet/background";
3
+ import {
4
+ ChainInfoWithRepoUpdateOptions,
5
+ SuggestChainInfoMsg,
6
+ } from "@keplr-wallet/background";
4
7
  import { flow, makeObservable, observable } from "mobx";
8
+ import { ChainIdHelper } from "@keplr-wallet/cosmos";
9
+ import Axios from "axios";
5
10
 
6
11
  export class ChainSuggestStore {
7
12
  @observable
8
13
  protected _isLoading: boolean = false;
9
14
 
10
- constructor(protected readonly interactionStore: InteractionStore) {
15
+ @observable
16
+ communityChainInfo: ChainInfo | undefined = undefined;
17
+
18
+ constructor(
19
+ protected readonly interactionStore: InteractionStore,
20
+ protected readonly communityChainInfoRepo: {
21
+ readonly organizationName: string;
22
+ readonly repoName: string;
23
+ }
24
+ ) {
11
25
  makeObservable(this);
12
26
  }
13
27
 
@@ -21,14 +35,47 @@ export class ChainSuggestStore {
21
35
  }
22
36
  }
23
37
 
38
+ get communityChainInfoRepoUrl(): string {
39
+ return `https://github.com/${this.communityChainInfoRepo.organizationName}/${this.communityChainInfoRepo.repoName}`;
40
+ }
41
+
42
+ getCommunityChainInfoUrl(chainId: string): string {
43
+ const chainIdHelper = ChainIdHelper.parse(chainId);
44
+ return `${this.communityChainInfoRepoUrl}/blob/main/cosmos/${chainIdHelper.identifier}.json`;
45
+ }
46
+
47
+ @flow
48
+ *fetchCommunityChainInfo() {
49
+ this._isLoading = true;
50
+
51
+ if (this.waitingSuggestedChainInfo) {
52
+ try {
53
+ const chainIdentifier = ChainIdHelper.parse(
54
+ this.waitingSuggestedChainInfo.data.chainId
55
+ ).identifier;
56
+ const chainInfoResponse = yield Axios.get<ChainInfo>(
57
+ `/cosmos/${chainIdentifier}.json`,
58
+ {
59
+ baseURL: `https://raw.githubusercontent.com/${this.communityChainInfoRepo.organizationName}/${this.communityChainInfoRepo.repoName}/main`,
60
+ }
61
+ );
62
+
63
+ this.communityChainInfo = chainInfoResponse.data;
64
+ } finally {
65
+ this._isLoading = false;
66
+ }
67
+ }
68
+ }
69
+
24
70
  @flow
25
- *approve() {
71
+ *approve(chainInfo: ChainInfoWithRepoUpdateOptions) {
26
72
  this._isLoading = true;
27
73
 
28
74
  try {
29
75
  const data = this.waitingSuggestedChainInfo;
76
+
30
77
  if (data) {
31
- yield this.interactionStore.approve(data.type, data.id, {});
78
+ yield this.interactionStore.approve(data.type, data.id, chainInfo);
32
79
  }
33
80
  } finally {
34
81
  this._isLoading = false;