@openocean.finance/wallet 0.4.47 → 0.4.48

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,19 +1,23 @@
1
1
  import { EnumChains, EnumWalletName, EnumWalletType } from "../types";
2
2
  import BaseWallet from "./BaseWallet";
3
+ import { WalletConnection, utils } from "near-api-js";
4
+ import { createTransaction, functionCall } from 'near-api-js/lib/transaction';
3
5
  declare class NearWallet extends BaseWallet {
4
6
  name: EnumWalletName;
5
7
  icon: any;
6
8
  supportChains: EnumChains[];
7
9
  type: EnumWalletType;
8
- sdk: any | null;
9
- private keyStore;
10
- private config;
10
+ sdk: WalletConnection | null;
11
+ createTransaction: typeof createTransaction;
12
+ functionCall: typeof functionCall;
13
+ PublicKey: typeof utils.key_pair.PublicKey;
14
+ utils: typeof utils;
11
15
  init(): Promise<void>;
12
16
  /**
13
17
  * connect metamask and get wallet address
14
18
  * @param chainId specific chainId,throw error when not match
15
19
  */
16
- requestConnect(): Promise<any>;
20
+ requestConnect(): Promise<string>;
17
21
  constructor();
18
22
  }
19
23
  export default NearWallet;
@@ -65,6 +65,8 @@ var near_svg_1 = __importDefault(require("../assets/near.svg"));
65
65
  var types_1 = require("../types");
66
66
  var BaseWallet_1 = __importDefault(require("./BaseWallet"));
67
67
  var near_api_js_1 = require("near-api-js");
68
+ var transaction_1 = require("near-api-js/lib/transaction");
69
+ var utils_1 = require("near-api-js/lib/utils");
68
70
  var NearWallet = /** @class */ (function (_super) {
69
71
  __extends(NearWallet, _super);
70
72
  function NearWallet() {
@@ -76,23 +78,18 @@ var NearWallet = /** @class */ (function (_super) {
76
78
  ];
77
79
  _this.type = types_1.EnumWalletType.Extension;
78
80
  _this.sdk = null;
79
- _this.keyStore = new near_api_js_1.keyStores.BrowserLocalStorageKeyStore();
80
- _this.config = {
81
- networkId: "mainnet",
82
- keyStore: _this.keyStore,
83
- nodeUrl: "https://public-rpc.blockpi.io/http/near",
84
- walletUrl: "https://wallet.mainnet.near.org",
85
- helperUrl: "https://helper.mainnet.near.org",
86
- explorerUrl: "https://explorer.mainnet.near.org",
87
- };
81
+ _this.createTransaction = transaction_1.createTransaction;
82
+ _this.functionCall = transaction_1.functionCall;
83
+ _this.PublicKey = utils_1.PublicKey;
84
+ _this.utils = near_api_js_1.utils;
88
85
  _this.init();
89
86
  return _this;
90
87
  }
91
88
  NearWallet.prototype.init = function () {
92
89
  return __awaiter(this, void 0, void 0, function () {
93
- var account_id, query, vars, i, pair, _a;
94
- return __generator(this, function (_b) {
95
- switch (_b.label) {
90
+ var account_id, query, vars, i, pair;
91
+ return __generator(this, function (_a) {
92
+ switch (_a.label) {
96
93
  case 0:
97
94
  account_id = '';
98
95
  query = window.location.search.substring(1);
@@ -104,11 +101,10 @@ var NearWallet = /** @class */ (function (_super) {
104
101
  }
105
102
  }
106
103
  if (!account_id) return [3 /*break*/, 2];
107
- _a = near_api_js_1.WalletConnection.bind;
108
- return [4 /*yield*/, (0, near_api_js_1.connect)(this.config)];
104
+ return [4 /*yield*/, this.requestConnect()];
109
105
  case 1:
110
- new (_a.apply(near_api_js_1.WalletConnection, [void 0, _b.sent(), 'openOcen']))();
111
- _b.label = 2;
106
+ _a.sent();
107
+ _a.label = 2;
112
108
  case 2: return [2 /*return*/];
113
109
  }
114
110
  });
@@ -120,25 +116,34 @@ var NearWallet = /** @class */ (function (_super) {
120
116
  */
121
117
  NearWallet.prototype.requestConnect = function () {
122
118
  return __awaiter(this, void 0, void 0, function () {
123
- var near, account, address;
119
+ var wallet, account;
124
120
  return __generator(this, function (_a) {
125
121
  switch (_a.label) {
126
- case 0: return [4 /*yield*/, (0, near_api_js_1.connect)(this.config)];
122
+ case 0: return [4 /*yield*/, (0, near_api_js_1.connect)({
123
+ networkId: "mainnet",
124
+ keyStore: new near_api_js_1.keyStores.BrowserLocalStorageKeyStore(),
125
+ nodeUrl: "https://rpc.mainnet.near.org",
126
+ walletUrl: "https://wallet.mainnet.near.org",
127
+ helperUrl: "https://helper.mainnet.near.org",
128
+ headers: {}
129
+ // explorerUrl: "https://explorer.mainnet.near.org",
130
+ })];
127
131
  case 1:
128
- near = _a.sent();
129
- this.sdk = new near_api_js_1.WalletConnection(near, 'openOcen');
130
- if (!this.sdk._authData.accountId) {
131
- this.sdk.requestSignIn({
132
- contractId: 'v2.ref-farming.near',
132
+ wallet = _a.sent();
133
+ this.sdk = new near_api_js_1.WalletConnection(wallet, 'openOcen');
134
+ account = this.sdk.account();
135
+ if (!!account.accountId) return [3 /*break*/, 3];
136
+ return [4 /*yield*/, this.sdk.requestSignIn({
137
+ contractId: 'a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48.factory.bridge.near',
133
138
  methodNames: [], // optional
134
- // successUrl: 'http://localhost:12345/', // optional
135
- // failureUrl: 'http://localhost:12345?key=error' // optional
136
- });
137
- }
139
+ })];
140
+ case 2:
141
+ _a.sent();
142
+ _a.label = 3;
143
+ case 3:
138
144
  account = this.sdk.account();
139
- address = account.accountId;
140
- this.address = address;
141
- return [2 /*return*/, address];
145
+ this.address = account.accountId;
146
+ return [2 /*return*/, this.address || ''];
142
147
  }
143
148
  });
144
149
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openocean.finance/wallet",
3
- "version": "0.4.47",
3
+ "version": "0.4.48",
4
4
  "description": "A multi-chain wallets manager",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {