@openocean.finance/wallet 0.4.63 → 0.4.65

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,10 +12,12 @@ 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>;
15
16
  /**
16
17
  * connect metamask and get wallet address
17
18
  * @param chainId specific chainId,throw error when not match
18
19
  */
19
20
  requestConnect(): Promise<string>;
21
+ constructor();
20
22
  }
21
23
  export default NearWallet;
@@ -67,53 +67,91 @@ 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 core_1 = require("@near-wallet-selector/core");
71
- var near_wallet_1 = require("@near-wallet-selector/near-wallet");
70
+ var helper_1 = require("../helper");
72
71
  var NearWallet = /** @class */ (function (_super) {
73
72
  __extends(NearWallet, _super);
74
73
  function NearWallet() {
75
- var _this = _super !== null && _super.apply(this, arguments) || this;
74
+ var _this = _super.call(this) || this;
76
75
  _this.name = types_1.EnumWalletName.NearWallet;
77
76
  _this.icon = near_svg_1.default;
78
- _this.supportChains = [types_1.EnumChains.NEAR];
77
+ _this.supportChains = [
78
+ types_1.EnumChains.NEAR
79
+ ];
79
80
  _this.type = types_1.EnumWalletType.Extension;
80
81
  _this.sdk = null;
81
82
  _this.createTransaction = transaction_1.createTransaction;
82
83
  _this.functionCall = transaction_1.functionCall;
83
84
  _this.PublicKey = utils_1.PublicKey;
84
85
  _this.utils = near_api_js_1.utils;
86
+ _this.init();
85
87
  return _this;
86
88
  }
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
+ };
87
117
  /**
88
118
  * connect metamask and get wallet address
89
119
  * @param chainId specific chainId,throw error when not match
90
120
  */
91
121
  NearWallet.prototype.requestConnect = function () {
92
122
  return __awaiter(this, void 0, void 0, function () {
93
- var nearWallet, selector, wallet, accounts;
123
+ var wallet, account;
94
124
  return __generator(this, function (_a) {
95
125
  switch (_a.label) {
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],
102
- })];
126
+ case 0: return [4 /*yield*/, (0, helper_1.sleep)(1000)];
103
127
  case 1:
104
- selector = _a.sent();
105
- return [4 /*yield*/, selector.wallet("near-wallet")];
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",
138
+ })];
106
139
  case 2:
107
140
  wallet = _a.sent();
108
- return [4 /*yield*/, wallet.signIn({
109
- contractId: "a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48.factory.bridge.near",
110
- accounts: []
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
111
147
  })];
112
148
  case 3:
113
- accounts = _a.sent();
114
- this.sdk = wallet;
115
- this.address = accounts && accounts[0] && accounts[0].accountId || "";
116
- return [2 /*return*/, this.address || ""];
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 || ''];
117
155
  }
118
156
  });
119
157
  });
@@ -94,6 +94,9 @@ var SenderWallet = /** @class */ (function (_super) {
94
94
  return __generator(this, function (_a) {
95
95
  switch (_a.label) {
96
96
  case 0:
97
+ if (!window.near || !window.near.isSender) {
98
+ throw new Error(types_1.EnumErrors.NoSender);
99
+ }
97
100
  sender = (0, sender_1.setupSender)();
98
101
  return [4 /*yield*/, (0, core_1.setupWalletSelector)({
99
102
  network: "mainnet",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openocean.finance/wallet",
3
- "version": "0.4.63",
3
+ "version": "0.4.65",
4
4
  "description": "A multi-chain wallets manager",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {