@openocean.finance/wallet 0.4.62 → 0.4.63

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,7 +1,7 @@
1
1
  import { EnumChains, EnumWalletName, EnumWalletType } from "../types";
2
2
  import BaseWallet from "./BaseWallet";
3
3
  import { WalletConnection, utils } from "near-api-js";
4
- import { createTransaction, functionCall } from 'near-api-js/lib/transaction';
4
+ import { createTransaction, functionCall } from "near-api-js/lib/transaction";
5
5
  declare class NearWallet extends BaseWallet {
6
6
  name: EnumWalletName;
7
7
  icon: any;
@@ -12,12 +12,10 @@ declare class NearWallet extends BaseWallet {
12
12
  functionCall: typeof functionCall;
13
13
  PublicKey: typeof utils.key_pair.PublicKey;
14
14
  utils: typeof utils;
15
- init(): Promise<void>;
16
15
  /**
17
16
  * connect metamask and get wallet address
18
17
  * @param chainId specific chainId,throw error when not match
19
18
  */
20
19
  requestConnect(): Promise<string>;
21
- constructor();
22
20
  }
23
21
  export default NearWallet;
@@ -67,91 +67,53 @@ var BaseWallet_1 = __importDefault(require("./BaseWallet"));
67
67
  var near_api_js_1 = require("near-api-js");
68
68
  var transaction_1 = require("near-api-js/lib/transaction");
69
69
  var utils_1 = require("near-api-js/lib/utils");
70
- var helper_1 = require("../helper");
70
+ var core_1 = require("@near-wallet-selector/core");
71
+ var near_wallet_1 = require("@near-wallet-selector/near-wallet");
71
72
  var NearWallet = /** @class */ (function (_super) {
72
73
  __extends(NearWallet, _super);
73
74
  function NearWallet() {
74
- var _this = _super.call(this) || this;
75
+ var _this = _super !== null && _super.apply(this, arguments) || this;
75
76
  _this.name = types_1.EnumWalletName.NearWallet;
76
77
  _this.icon = near_svg_1.default;
77
- _this.supportChains = [
78
- types_1.EnumChains.NEAR
79
- ];
78
+ _this.supportChains = [types_1.EnumChains.NEAR];
80
79
  _this.type = types_1.EnumWalletType.Extension;
81
80
  _this.sdk = null;
82
81
  _this.createTransaction = transaction_1.createTransaction;
83
82
  _this.functionCall = transaction_1.functionCall;
84
83
  _this.PublicKey = utils_1.PublicKey;
85
84
  _this.utils = near_api_js_1.utils;
86
- _this.init();
87
85
  return _this;
88
86
  }
89
- NearWallet.prototype.init = function () {
90
- return __awaiter(this, void 0, void 0, function () {
91
- var account_id, query, vars, i, pair;
92
- return __generator(this, function (_a) {
93
- switch (_a.label) {
94
- case 0:
95
- if (window.localStorage.getItem('connectwallet') !== this.name) {
96
- return [2 /*return*/];
97
- }
98
- account_id = '';
99
- query = window.location.search.substring(1);
100
- vars = query.split("&");
101
- for (i = 0; i < vars.length; i++) {
102
- pair = vars[i].split("=");
103
- if (pair[0] == 'account_id') {
104
- account_id = pair[1];
105
- }
106
- }
107
- if (!account_id) return [3 /*break*/, 2];
108
- return [4 /*yield*/, this.requestConnect()];
109
- case 1:
110
- _a.sent();
111
- _a.label = 2;
112
- case 2: return [2 /*return*/];
113
- }
114
- });
115
- });
116
- };
117
87
  /**
118
88
  * connect metamask and get wallet address
119
89
  * @param chainId specific chainId,throw error when not match
120
90
  */
121
91
  NearWallet.prototype.requestConnect = function () {
122
92
  return __awaiter(this, void 0, void 0, function () {
123
- var wallet, account;
93
+ var nearWallet, selector, wallet, accounts;
124
94
  return __generator(this, function (_a) {
125
95
  switch (_a.label) {
126
- case 0: return [4 /*yield*/, (0, helper_1.sleep)(1000)];
127
- case 1:
128
- _a.sent();
129
- window.localStorage.setItem('connectwallet', this.name);
130
- return [4 /*yield*/, (0, near_api_js_1.connect)({
131
- networkId: "mainnet",
132
- keyStore: new near_api_js_1.keyStores.BrowserLocalStorageKeyStore(),
133
- nodeUrl: "https://rpc.mainnet.near.org",
134
- walletUrl: "https://wallet.mainnet.near.org",
135
- helperUrl: "https://helper.mainnet.near.org",
136
- headers: {}
137
- // explorerUrl: "https://explorer.mainnet.near.org",
96
+ case 0:
97
+ nearWallet = (0, near_wallet_1.setupNearWallet)();
98
+ return [4 /*yield*/, (0, core_1.setupWalletSelector)({
99
+ network: "mainnet",
100
+ debug: true,
101
+ modules: [nearWallet],
138
102
  })];
103
+ case 1:
104
+ selector = _a.sent();
105
+ return [4 /*yield*/, selector.wallet("near-wallet")];
139
106
  case 2:
140
107
  wallet = _a.sent();
141
- this.sdk = new near_api_js_1.WalletConnection(wallet, 'OpenOcean');
142
- account = this.sdk.account();
143
- if (!!account.accountId) return [3 /*break*/, 4];
144
- return [4 /*yield*/, this.sdk.requestSignIn({
145
- contractId: 'a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48.factory.bridge.near',
146
- methodNames: [], // optional
108
+ return [4 /*yield*/, wallet.signIn({
109
+ contractId: "a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48.factory.bridge.near",
110
+ accounts: []
147
111
  })];
148
112
  case 3:
149
- _a.sent();
150
- _a.label = 4;
151
- case 4:
152
- account = this.sdk.account();
153
- this.address = account.accountId;
154
- return [2 /*return*/, this.address || ''];
113
+ accounts = _a.sent();
114
+ this.sdk = wallet;
115
+ this.address = accounts && accounts[0] && accounts[0].accountId || "";
116
+ return [2 /*return*/, this.address || ""];
155
117
  }
156
118
  });
157
119
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openocean.finance/wallet",
3
- "version": "0.4.62",
3
+ "version": "0.4.63",
4
4
  "description": "A multi-chain wallets manager",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -46,6 +46,8 @@
46
46
  "@gnosis.pm/safe-apps-sdk": "^7.5.0",
47
47
  "@near-wallet-selector/core": "^7.8.2",
48
48
  "@near-wallet-selector/meteor-wallet": "^7.8.2",
49
+ "@near-wallet-selector/my-near-wallet": "^7.8.2",
50
+ "@near-wallet-selector/near-wallet": "^7.8.2",
49
51
  "@near-wallet-selector/sender": "^7.8.2",
50
52
  "@onflow/fcl": "^0.0.71",
51
53
  "@ont-dev/ontology-dapi": "^0.5.7",