@openocean.finance/wallet 0.4.20 → 0.4.23

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.
@@ -0,0 +1,16 @@
1
+ import { EnumWalletName, EnumWalletType } from "../types";
2
+ import BaseWallet from "./BaseWallet";
3
+ import Web3 from "web3";
4
+ declare class GnosisSafeWallet extends BaseWallet {
5
+ name: EnumWalletName;
6
+ icon: any;
7
+ supportChains: never[];
8
+ type: EnumWalletType;
9
+ sdk: Web3 | null;
10
+ /**
11
+ * connect metamask and get wallet address
12
+ * @param chainId specific chainId,throw error when not match
13
+ */
14
+ requestConnect(chainId?: number): Promise<string>;
15
+ }
16
+ export default GnosisSafeWallet;
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (_) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ var __importDefault = (this && this.__importDefault) || function (mod) {
54
+ return (mod && mod.__esModule) ? mod : { "default": mod };
55
+ };
56
+ Object.defineProperty(exports, "__esModule", { value: true });
57
+ /**
58
+ * @name GnosisSafe
59
+ * @author openocean
60
+ * @date 2021/4/21
61
+ * @desc
62
+ */
63
+ // @ts-ignore
64
+ var metamask_svg_1 = __importDefault(require("../assets/metamask.svg"));
65
+ var types_1 = require("../types");
66
+ var BaseWallet_1 = __importDefault(require("./BaseWallet"));
67
+ var web3_1 = __importDefault(require("web3"));
68
+ var safe_apps_sdk_1 = __importDefault(require("@gnosis.pm/safe-apps-sdk"));
69
+ var safe_apps_provider_1 = require("@gnosis.pm/safe-apps-provider");
70
+ var GnosisSafeWallet = /** @class */ (function (_super) {
71
+ __extends(GnosisSafeWallet, _super);
72
+ function GnosisSafeWallet() {
73
+ var _this = _super !== null && _super.apply(this, arguments) || this;
74
+ _this.name = types_1.EnumWalletName.GnosisSafeWallet;
75
+ _this.icon = metamask_svg_1.default;
76
+ _this.supportChains = [];
77
+ _this.type = types_1.EnumWalletType.Extension;
78
+ _this.sdk = null;
79
+ return _this;
80
+ }
81
+ /**
82
+ * connect metamask and get wallet address
83
+ * @param chainId specific chainId,throw error when not match
84
+ */
85
+ GnosisSafeWallet.prototype.requestConnect = function (chainId) {
86
+ return __awaiter(this, void 0, void 0, function () {
87
+ var opts, sdk, safe, provider, address, currentChainId;
88
+ return __generator(this, function (_a) {
89
+ switch (_a.label) {
90
+ case 0:
91
+ opts = {
92
+ allowedDomains: [/gnosis-safe.io/],
93
+ debug: true
94
+ };
95
+ sdk = new safe_apps_sdk_1.default(opts);
96
+ return [4 /*yield*/, sdk.safe.getInfo()];
97
+ case 1:
98
+ safe = _a.sent();
99
+ provider = new safe_apps_provider_1.SafeAppProvider(safe, sdk);
100
+ this.sdk = new web3_1.default(provider);
101
+ return [4 /*yield*/, this.sdk.eth.requestAccounts()];
102
+ case 2:
103
+ address = (_a.sent())[0];
104
+ return [4 /*yield*/, this.sdk.eth.getChainId()];
105
+ case 3:
106
+ currentChainId = _a.sent();
107
+ if (chainId && currentChainId !== chainId) {
108
+ throw new Error(types_1.EnumErrors.ChainIdNotMath);
109
+ }
110
+ this.address = address;
111
+ this.chainId = currentChainId;
112
+ return [2 /*return*/, address];
113
+ }
114
+ });
115
+ });
116
+ };
117
+ return GnosisSafeWallet;
118
+ }(BaseWallet_1.default));
119
+ exports.default = GnosisSafeWallet;
@@ -105,7 +105,7 @@ var NearWallet = /** @class */ (function (_super) {
105
105
  }
106
106
  if (!account_id) return [3 /*break*/, 2];
107
107
  _a = near_api_js_1.WalletConnection.bind;
108
- return [4 /*yield*/, (0, near_api_js_1.connect)(this.config)];
108
+ return [4 /*yield*/, near_api_js_1.connect(this.config)];
109
109
  case 1:
110
110
  new (_a.apply(near_api_js_1.WalletConnection, [void 0, _b.sent(), 'openOcen']))();
111
111
  _b.label = 2;
@@ -123,7 +123,7 @@ var NearWallet = /** @class */ (function (_super) {
123
123
  var near, account, address;
124
124
  return __generator(this, function (_a) {
125
125
  switch (_a.label) {
126
- case 0: return [4 /*yield*/, (0, near_api_js_1.connect)(this.config)];
126
+ case 0: return [4 /*yield*/, near_api_js_1.connect(this.config)];
127
127
  case 1:
128
128
  near = _a.sent();
129
129
  this.sdk = new near_api_js_1.WalletConnection(near, 'openOcen');
@@ -1,6 +1,5 @@
1
1
  import { EnumChains, EnumWalletName, EnumWalletType } from "../types";
2
2
  import BaseWallet from "./BaseWallet";
3
- import WalletConnectProvider from "@walletconnect/web3-provider";
4
3
  declare class WalletConnect extends BaseWallet {
5
4
  name: EnumWalletName;
6
5
  icon: any;
@@ -8,8 +7,6 @@ declare class WalletConnect extends BaseWallet {
8
7
  type: EnumWalletType;
9
8
  sdk: any;
10
9
  infuraId?: string;
11
- provider: WalletConnectProvider;
12
- disconnect(): Promise<boolean>;
13
10
  /**
14
11
  * connect metamask and get wallet address
15
12
  * @param chainId specific chainId,throw error when not match
@@ -102,43 +102,8 @@ var WalletConnect = /** @class */ (function (_super) {
102
102
  ];
103
103
  _this.type = types_1.EnumWalletType.WalletConnect;
104
104
  _this.sdk = null;
105
- _this.provider = new web3_provider_1.default({
106
- infuraId: '2c7c4d86c2c746c89de722551b606119',
107
- chainId: 1,
108
- rpc: {
109
- 69: "https://kovan.optimism.io",
110
- 420: "https://goerli.optimism.io",
111
- 10: "https://rpc.ankr.com/optimism",
112
- 25: "https://evm.cronos.org",
113
- 56: "https://bsc-dataseed1.binance.org",
114
- 66: "https://exchainrpc.okex.org",
115
- 100: "https://rpc.xdaichain.com",
116
- 128: "https://http-mainnet.hecochain.com",
117
- 137: "https://rpc-mainnet.maticvigil.com",
118
- 250: "https://rpcapi.fantom.network",
119
- 288: "https://mainnet.boba.network",
120
- 1285: "https://rpc.moonriver.moonbeam.network",
121
- 42161: "https://arb1.arbitrum.io/rpc",
122
- 421611: "https://rinkeby.arbitrum.io/rpc",
123
- 43114: "https://api.avax.network/ext/bc/C/rpc",
124
- 1313161554: "https://mainnet.aurora.dev",
125
- 1666600000: "https://api.s0.t.hmny.io",
126
- }
127
- });
128
105
  return _this;
129
106
  }
130
- WalletConnect.prototype.disconnect = function () {
131
- return __awaiter(this, void 0, void 0, function () {
132
- return __generator(this, function (_a) {
133
- switch (_a.label) {
134
- case 0: return [4 /*yield*/, this.provider.disconnect()];
135
- case 1:
136
- _a.sent();
137
- return [2 /*return*/, true];
138
- }
139
- });
140
- });
141
- };
142
107
  /**
143
108
  * connect metamask and get wallet address
144
109
  * @param chainId specific chainId,throw error when not match
@@ -147,27 +112,42 @@ var WalletConnect = /** @class */ (function (_super) {
147
112
  WalletConnect.prototype.requestConnect = function (chainId, config) {
148
113
  if (chainId === void 0) { chainId = 1; }
149
114
  return __awaiter(this, void 0, void 0, function () {
150
- var currentChainId, address;
115
+ var provider, currentChainId, address;
151
116
  return __generator(this, function (_a) {
152
117
  switch (_a.label) {
153
118
  case 0:
154
- // this.provider.infuraId = this.infuraId
155
- // await this.provider.disconnect()
156
- // await new Promise(r => {
157
- // setTimeout(r, 200);
158
- // })
159
- this.provider.chainId = chainId;
160
- this.provider.updateRpcUrl(chainId);
161
- return [4 /*yield*/, this.provider.enable()];
119
+ if (!this.infuraId) {
120
+ throw new Error("infuraId not set");
121
+ }
122
+ provider = new web3_provider_1.default(__assign({ infuraId: this.infuraId, chainId: chainId, rpc: {
123
+ 69: "https://kovan.optimism.io",
124
+ 420: "https://goerli.optimism.io",
125
+ 10: "https://rpc.ankr.com/optimism",
126
+ 25: "https://evm.cronos.org",
127
+ 56: "https://bsc-dataseed1.binance.org",
128
+ 66: "https://exchainrpc.okex.org",
129
+ 100: "https://rpc.xdaichain.com",
130
+ 128: "https://http-mainnet.hecochain.com",
131
+ 137: "https://rpc-mainnet.maticvigil.com",
132
+ 250: "https://rpcapi.fantom.network",
133
+ 288: "https://mainnet.boba.network",
134
+ 1285: "https://rpc.moonriver.moonbeam.network",
135
+ 42161: "https://arb1.arbitrum.io/rpc",
136
+ 421611: "https://rinkeby.arbitrum.io/rpc",
137
+ 43114: "https://api.avax.network/ext/bc/C/rpc",
138
+ 1313161554: "https://mainnet.aurora.dev",
139
+ 1666600000: "https://api.s0.t.hmny.io",
140
+ } }, config));
141
+ return [4 /*yield*/, provider.enable()];
162
142
  case 1:
163
143
  _a.sent();
164
- this.sdk = new web3_1.default(this.provider);
144
+ this.sdk = new web3_1.default(provider);
165
145
  return [4 /*yield*/, this.sdk.eth.getChainId()];
166
146
  case 2:
167
147
  currentChainId = _a.sent();
168
148
  if (!(chainId && currentChainId != chainId)) return [3 /*break*/, 6];
169
- if (!(!config || !config.isTow)) return [3 /*break*/, 6];
170
- return [4 /*yield*/, this.provider.disconnect()];
149
+ if (!(!config || !config.isSecond)) return [3 /*break*/, 6];
150
+ return [4 /*yield*/, provider.disconnect()];
171
151
  case 3:
172
152
  _a.sent();
173
153
  return [4 /*yield*/, new Promise(function (r) {
@@ -175,7 +155,7 @@ var WalletConnect = /** @class */ (function (_super) {
175
155
  })];
176
156
  case 4:
177
157
  _a.sent();
178
- return [4 /*yield*/, this.requestConnect(chainId, __assign({ isTow: true }, config))];
158
+ return [4 /*yield*/, this.requestConnect(chainId, __assign({ isSecond: true }, config))];
179
159
  case 5: return [2 /*return*/, _a.sent()];
180
160
  case 6:
181
161
  if (chainId && currentChainId != chainId) {
package/lib/index.d.ts CHANGED
@@ -34,6 +34,7 @@ import BraveWallet from "./Wallets/BraveWallet";
34
34
  import CryptoCom from './Wallets/CryptoCom';
35
35
  import NearWallet from './Wallets/NearWallet';
36
36
  import BitKeepWallet from './Wallets/BitKeepWallet';
37
+ import GnosisSafeWallet from './Wallets/GnosisSafeWallet';
37
38
  import { EnumChains } from "./types";
38
39
  export default WalletManager;
39
- export { WalletManager, MetaMask, BscWallet, Cyano, TronLink, EnumChains, Sollet, SolletIo, OntoMobile, WalletConnect, MathWallet, OntoWallet, SafePalWallet, ImTokenWallet, TokenPocket, TrustWallet, Coin98, Phantom, OKExWallet, TerraStation, CoinbaseWallet, CloverWallet, XDEFIWallet, SlopeWallet, SolflareWallet, MetaXWallet, KeplrWallet, BraveWallet, CryptoCom, NearWallet, BitKeepWallet };
40
+ export { WalletManager, MetaMask, BscWallet, Cyano, TronLink, EnumChains, Sollet, SolletIo, OntoMobile, WalletConnect, MathWallet, OntoWallet, SafePalWallet, ImTokenWallet, TokenPocket, TrustWallet, Coin98, Phantom, OKExWallet, TerraStation, CoinbaseWallet, CloverWallet, XDEFIWallet, SlopeWallet, SolflareWallet, MetaXWallet, KeplrWallet, BraveWallet, CryptoCom, NearWallet, BitKeepWallet, GnosisSafeWallet };
package/lib/index.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.BitKeepWallet = exports.NearWallet = exports.CryptoCom = exports.BraveWallet = exports.KeplrWallet = exports.MetaXWallet = exports.SolflareWallet = exports.SlopeWallet = exports.XDEFIWallet = exports.CloverWallet = exports.CoinbaseWallet = exports.TerraStation = exports.OKExWallet = exports.Phantom = exports.Coin98 = exports.TrustWallet = exports.TokenPocket = exports.ImTokenWallet = exports.SafePalWallet = exports.OntoWallet = exports.MathWallet = exports.WalletConnect = exports.OntoMobile = exports.SolletIo = exports.Sollet = exports.EnumChains = exports.TronLink = exports.Cyano = exports.BscWallet = exports.MetaMask = exports.WalletManager = void 0;
6
+ exports.GnosisSafeWallet = exports.BitKeepWallet = exports.NearWallet = exports.CryptoCom = exports.BraveWallet = exports.KeplrWallet = exports.MetaXWallet = exports.SolflareWallet = exports.SlopeWallet = exports.XDEFIWallet = exports.CloverWallet = exports.CoinbaseWallet = exports.TerraStation = exports.OKExWallet = exports.Phantom = exports.Coin98 = exports.TrustWallet = exports.TokenPocket = exports.ImTokenWallet = exports.SafePalWallet = exports.OntoWallet = exports.MathWallet = exports.WalletConnect = exports.OntoMobile = exports.SolletIo = exports.Sollet = exports.EnumChains = exports.TronLink = exports.Cyano = exports.BscWallet = exports.MetaMask = exports.WalletManager = void 0;
7
7
  /**
8
8
  * wallets-manager entry
9
9
  * @author openocean
@@ -70,6 +70,8 @@ var NearWallet_1 = __importDefault(require("./Wallets/NearWallet"));
70
70
  exports.NearWallet = NearWallet_1.default;
71
71
  var BitKeepWallet_1 = __importDefault(require("./Wallets/BitKeepWallet"));
72
72
  exports.BitKeepWallet = BitKeepWallet_1.default;
73
+ var GnosisSafeWallet_1 = __importDefault(require("./Wallets/GnosisSafeWallet"));
74
+ exports.GnosisSafeWallet = GnosisSafeWallet_1.default;
73
75
  var types_1 = require("./types");
74
76
  Object.defineProperty(exports, "EnumChains", { enumerable: true, get: function () { return types_1.EnumChains; } });
75
77
  var process = {};
package/lib/types.d.ts CHANGED
@@ -71,7 +71,8 @@ export declare enum EnumWalletName {
71
71
  keplrWallet = "Keplr Wallet",
72
72
  BraveWallet = "Brave Wallet",
73
73
  CryptoCom = "Crypto.com DeFi Wallet",
74
- BitKeepWallet = "BitKeep Wallet"
74
+ BitKeepWallet = "BitKeep Wallet",
75
+ GnosisSafeWallet = "GnosisSafe Wallet"
75
76
  }
76
77
  export declare enum EnumErrors {
77
78
  NotMetamask = "40001",
package/lib/types.js CHANGED
@@ -74,6 +74,7 @@ var EnumWalletName;
74
74
  EnumWalletName["BraveWallet"] = "Brave Wallet";
75
75
  EnumWalletName["CryptoCom"] = "Crypto.com DeFi Wallet";
76
76
  EnumWalletName["BitKeepWallet"] = "BitKeep Wallet";
77
+ EnumWalletName["GnosisSafeWallet"] = "GnosisSafe Wallet";
77
78
  })(EnumWalletName = exports.EnumWalletName || (exports.EnumWalletName = {}));
78
79
  var EnumErrors;
79
80
  (function (EnumErrors) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openocean.finance/wallet",
3
- "version": "0.4.20",
3
+ "version": "0.4.23",
4
4
  "description": "A multi-chain wallets manager",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -42,6 +42,8 @@
42
42
  "dependencies": {
43
43
  "@cosmjs/launchpad": "^0.27.1",
44
44
  "@cosmjs/stargate": "^0.28.4",
45
+ "@gnosis.pm/safe-apps-provider": "^0.11.3",
46
+ "@gnosis.pm/safe-apps-sdk": "^7.5.0",
45
47
  "@ont-dev/ontology-dapi": "^0.5.7",
46
48
  "@project-serum/sol-wallet-adapter": "0.2.0",
47
49
  "@solana/web3.js": "1.31.0",