@oasisdex/utils
Advanced tools
+191
| Apache License | ||
| Version 2.0, January 2004 | ||
| https://www.apache.org/licenses/ | ||
| TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION | ||
| 1. Definitions. | ||
| "License" shall mean the terms and conditions for use, reproduction, | ||
| and distribution as defined by Sections 1 through 9 of this document. | ||
| "Licensor" shall mean the copyright owner or entity authorized by | ||
| the copyright owner that is granting the License. | ||
| "Legal Entity" shall mean the union of the acting entity and all | ||
| other entities that control, are controlled by, or are under common | ||
| control with that entity. For the purposes of this definition, | ||
| "control" means (i) the power, direct or indirect, to cause the | ||
| direction or management of such entity, whether by contract or | ||
| otherwise, or (ii) ownership of fifty percent (50%) or more of the | ||
| outstanding shares, or (iii) beneficial ownership of such entity. | ||
| "You" (or "Your") shall mean an individual or Legal Entity | ||
| exercising permissions granted by this License. | ||
| "Source" form shall mean the preferred form for making modifications, | ||
| including but not limited to software source code, documentation | ||
| source, and configuration files. | ||
| "Object" form shall mean any form resulting from mechanical | ||
| transformation or translation of a Source form, including but | ||
| not limited to compiled object code, generated documentation, | ||
| and conversions to other media types. | ||
| "Work" shall mean the work of authorship, whether in Source or | ||
| Object form, made available under the License, as indicated by a | ||
| copyright notice that is included in or attached to the work | ||
| (an example is provided in the Appendix below). | ||
| "Derivative Works" shall mean any work, whether in Source or Object | ||
| form, that is based on (or derived from) the Work and for which the | ||
| editorial revisions, annotations, elaborations, or other modifications | ||
| represent, as a whole, an original work of authorship. For the purposes | ||
| of this License, Derivative Works shall not include works that remain | ||
| separable from, or merely link (or bind by name) to the interfaces of, | ||
| the Work and Derivative Works thereof. | ||
| "Contribution" shall mean any work of authorship, including | ||
| the original version of the Work and any modifications or additions | ||
| to that Work or Derivative Works thereof, that is intentionally | ||
| submitted to Licensor for inclusion in the Work by the copyright owner | ||
| or by an individual or Legal Entity authorized to submit on behalf of | ||
| the copyright owner. For the purposes of this definition, "submitted" | ||
| means any form of electronic, verbal, or written communication sent | ||
| to the Licensor or its representatives, including but not limited to | ||
| communication on electronic mailing lists, source code control systems, | ||
| and issue tracking systems that are managed by, or on behalf of, the | ||
| Licensor for the purpose of discussing and improving the Work, but | ||
| excluding communication that is conspicuously marked or otherwise | ||
| designated in writing by the copyright owner as "Not a Contribution." | ||
| "Contributor" shall mean Licensor and any individual or Legal Entity | ||
| on behalf of whom a Contribution has been received by Licensor and | ||
| subsequently incorporated within the Work. | ||
| 2. Grant of Copyright License. Subject to the terms and conditions of | ||
| this License, each Contributor hereby grants to You a perpetual, | ||
| worldwide, non-exclusive, no-charge, royalty-free, irrevocable | ||
| copyright license to reproduce, prepare Derivative Works of, | ||
| publicly display, publicly perform, sublicense, and distribute the | ||
| Work and such Derivative Works in Source or Object form. | ||
| 3. Grant of Patent License. Subject to the terms and conditions of | ||
| this License, each Contributor hereby grants to You a perpetual, | ||
| worldwide, non-exclusive, no-charge, royalty-free, irrevocable | ||
| (except as stated in this section) patent license to make, have made, | ||
| use, offer to sell, sell, import, and otherwise transfer the Work, | ||
| where such license applies only to those patent claims licensable | ||
| by such Contributor that are necessarily infringed by their | ||
| Contribution(s) alone or by combination of their Contribution(s) | ||
| with the Work to which such Contribution(s) was submitted. If You | ||
| institute patent litigation against any entity (including a | ||
| cross-claim or counterclaim in a lawsuit) alleging that the Work | ||
| or a Contribution incorporated within the Work constitutes direct | ||
| or contributory patent infringement, then any patent licenses | ||
| granted to You under this License for that Work shall terminate | ||
| as of the date such litigation is filed. | ||
| 4. Redistribution. You may reproduce and distribute copies of the | ||
| Work or Derivative Works thereof in any medium, with or without | ||
| modifications, and in Source or Object form, provided that You | ||
| meet the following conditions: | ||
| (a) You must give any other recipients of the Work or | ||
| Derivative Works a copy of this License; and | ||
| (b) You must cause any modified files to carry prominent notices | ||
| stating that You changed the files; and | ||
| (c) You must retain, in the Source form of any Derivative Works | ||
| that You distribute, all copyright, patent, trademark, and | ||
| attribution notices from the Source form of the Work, | ||
| excluding those notices that do not pertain to any part of | ||
| the Derivative Works; and | ||
| (d) If the Work includes a "NOTICE" text file as part of its | ||
| distribution, then any Derivative Works that You distribute must | ||
| include a readable copy of the attribution notices contained | ||
| within such NOTICE file, excluding those notices that do not | ||
| pertain to any part of the Derivative Works, in at least one | ||
| of the following places: within a NOTICE text file distributed | ||
| as part of the Derivative Works; within the Source form or | ||
| documentation, if provided along with the Derivative Works; or, | ||
| within a display generated by the Derivative Works, if and | ||
| wherever such third-party notices normally appear. The contents | ||
| of the NOTICE file are for informational purposes only and | ||
| do not modify the License. You may add Your own attribution | ||
| notices within Derivative Works that You distribute, alongside | ||
| or as an addendum to the NOTICE text from the Work, provided | ||
| that such additional attribution notices cannot be construed | ||
| as modifying the License. | ||
| You may add Your own copyright statement to Your modifications and | ||
| may provide additional or different license terms and conditions | ||
| for use, reproduction, or distribution of Your modifications, or | ||
| for any such Derivative Works as a whole, provided Your use, | ||
| reproduction, and distribution of the Work otherwise complies with | ||
| the conditions stated in this License. | ||
| 5. Submission of Contributions. Unless You explicitly state otherwise, | ||
| any Contribution intentionally submitted for inclusion in the Work | ||
| by You to the Licensor shall be under the terms and conditions of | ||
| this License, without any additional terms or conditions. | ||
| Notwithstanding the above, nothing herein shall supersede or modify | ||
| the terms of any separate license agreement you may have executed | ||
| with Licensor regarding such Contributions. | ||
| 6. Trademarks. This License does not grant permission to use the trade | ||
| names, trademarks, service marks, or product names of the Licensor, | ||
| except as required for reasonable and customary use in describing the | ||
| origin of the Work and reproducing the content of the NOTICE file. | ||
| 7. Disclaimer of Warranty. Unless required by applicable law or | ||
| agreed to in writing, Licensor provides the Work (and each | ||
| Contributor provides its Contributions) on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
| implied, including, without limitation, any warranties or conditions | ||
| of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A | ||
| PARTICULAR PURPOSE. You are solely responsible for determining the | ||
| appropriateness of using or redistributing the Work and assume any | ||
| risks associated with Your exercise of permissions under this License. | ||
| 8. Limitation of Liability. In no event and under no legal theory, | ||
| whether in tort (including negligence), contract, or otherwise, | ||
| unless required by applicable law (such as deliberate and grossly | ||
| negligent acts) or agreed to in writing, shall any Contributor be | ||
| liable to You for damages, including any direct, indirect, special, | ||
| incidental, or consequential damages of any character arising as a | ||
| result of this License or out of the use or inability to use the | ||
| Work (including but not limited to damages for loss of goodwill, | ||
| work stoppage, computer failure or malfunction, or any and all | ||
| other commercial damages or losses), even if such Contributor | ||
| has been advised of the possibility of such damages. | ||
| 9. Accepting Warranty or Additional Liability. While redistributing | ||
| the Work or Derivative Works thereof, You may choose to offer, | ||
| and charge a fee for, acceptance of support, warranty, indemnity, | ||
| or other liability obligations and/or rights consistent with this | ||
| License. However, in accepting such obligations, You may act only | ||
| on Your own behalf and on Your sole responsibility, not on behalf | ||
| of any other Contributor, and only if You agree to indemnify, | ||
| defend, and hold each Contributor harmless for any liability | ||
| incurred by, or claims asserted against, such Contributor by reason | ||
| of your accepting any such warranty or additional liability. | ||
| END OF TERMS AND CONDITIONS | ||
| Copyright 2020 Maker Foundation | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
| https://www.apache.org/licenses/LICENSE-2.0 | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. |
+2
-2
| { | ||
| "name": "@oasisdex/utils", | ||
| "version": "0.0.4", | ||
| "version": "0.0.5", | ||
| "description": "Utils", | ||
@@ -22,3 +22,3 @@ "homepage": "https://github.com/OasisDEX/common#readme", | ||
| }, | ||
| "gitHead": "0423d3d02ebfc45bf73092227a118bf9409f4696" | ||
| "gitHead": "ab296fb26f88afa1d0dc8bb1e093b6a03f2a3685" | ||
| } |
| export declare const networkNameToId: { | ||
| [key: string]: number; | ||
| }; | ||
| //# sourceMappingURL=config.d.ts.map |
| {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe;;CAGE,CAAC"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.networkNameToId = void 0; | ||
| exports.networkNameToId = { | ||
| main: 1, | ||
| kovan: 42, | ||
| }; | ||
| //# sourceMappingURL=config.js.map |
| {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":";;;AAAa,QAAA,eAAe,GAAG;IAC7B,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,EAAE;CACmB,CAAC"} |
| export declare const networkNameToId: { | ||
| [key: string]: number; | ||
| }; | ||
| export interface ContractDesc { | ||
| abi: any; | ||
| address: string; | ||
| } | ||
| export declare const contract: any; | ||
| export declare function getNetworkName(): string; | ||
| export declare function getNetworkId(): number; | ||
| //# sourceMappingURL=network.d.ts.map |
| {"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../src/network.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,eAAe;;CAGE,CAAC;AAE/B,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,GAAG,CAAC;IACT,OAAO,EAAE,MAAM,CAAC;CACjB;AAID,eAAO,MAAM,QAAQ,EAAE,GAQtB,CAAC;AAEF,wBAAgB,cAAc,IAAI,MAAM,CAYvC;AAED,wBAAgB,YAAY,IAAI,MAAM,CAIrC"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.getNetworkId = exports.getNetworkName = exports.contract = exports.networkNameToId = void 0; | ||
| const lodash_1 = require("lodash"); | ||
| exports.networkNameToId = { | ||
| main: 1, | ||
| kovan: 42, | ||
| }; | ||
| const web3s = []; | ||
| // TODO | ||
| exports.contract = lodash_1.memoize((web3, { abi, address }) => new web3.eth.Contract(abi.default, address), (web3, { address }) => { | ||
| if (web3s.indexOf(web3) < 0) { | ||
| web3s[web3s.length] = web3; | ||
| } | ||
| return `${web3s.indexOf(web3)}${address}`; | ||
| }); | ||
| function getNetworkName() { | ||
| const name = 'network'; | ||
| const defaultNetwork = 'main'; | ||
| const matchesIfFound = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search); | ||
| if (lodash_1.isNull(matchesIfFound)) { | ||
| return defaultNetwork; | ||
| } | ||
| const networkName = decodeURIComponent(matchesIfFound[1].replace(/\+/g, ' ')); | ||
| if (lodash_1.isUndefined(exports.networkNameToId[networkName])) { | ||
| throw new Error(`Unsupported network in URL param: ${networkName}`); | ||
| } | ||
| return networkName; | ||
| } | ||
| exports.getNetworkName = getNetworkName; | ||
| function getNetworkId() { | ||
| const networkName = getNetworkName(); | ||
| const networkId = exports.networkNameToId[networkName]; | ||
| return networkId; | ||
| } | ||
| exports.getNetworkId = getNetworkId; | ||
| //# sourceMappingURL=network.js.map |
| {"version":3,"file":"network.js","sourceRoot":"","sources":["../../src/network.ts"],"names":[],"mappings":";;;AAAA,mCAAsD;AAGzC,QAAA,eAAe,GAAG;IAC7B,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,EAAE;CACmB,CAAC;AAO/B,MAAM,KAAK,GAAW,EAAE,CAAC;AACzB,OAAO;AACM,QAAA,QAAQ,GAAQ,gBAAO,CAClC,CAAC,IAAU,EAAE,EAAE,GAAG,EAAE,OAAO,EAAgB,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,EAC3F,CAAC,IAAU,EAAE,EAAE,OAAO,EAAgB,EAAE,EAAE;IACxC,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;QAC3B,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;KAC5B;IACD,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,EAAE,CAAC;AAC5C,CAAC,CACF,CAAC;AAEF,SAAgB,cAAc;IAC5B,MAAM,IAAI,GAAG,SAAS,CAAC;IACvB,MAAM,cAAc,GAAG,MAAM,CAAC;IAC9B,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,GAAG,IAAI,GAAG,UAAU,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACvF,IAAI,eAAM,CAAC,cAAc,CAAC,EAAE;QAC1B,OAAO,cAAc,CAAC;KACvB;IACD,MAAM,WAAW,GAAG,kBAAkB,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;IAC9E,IAAI,oBAAW,CAAC,uBAAe,CAAC,WAAW,CAAC,CAAC,EAAE;QAC7C,MAAM,IAAI,KAAK,CAAC,qCAAqC,WAAW,EAAE,CAAC,CAAC;KACrE;IACD,OAAO,WAAW,CAAC;AACrB,CAAC;AAZD,wCAYC;AAED,SAAgB,YAAY;IAC1B,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IACrC,MAAM,SAAS,GAAG,uBAAe,CAAC,WAAW,CAAC,CAAC;IAC/C,OAAO,SAAS,CAAC;AACnB,CAAC;AAJD,oCAIC"} |
| import { AbstractConnector } from '@web3-react/abstract-connector'; | ||
| import BigNumber from 'bignumber.js'; | ||
| import Web3 from 'web3'; | ||
| export declare type ConnectionKind = 'injected' | 'walletLink' | 'walletConnect' | 'trezor' | 'ledger' | 'network' | 'magicLink'; | ||
| interface Connectable { | ||
| connect: (connector: AbstractConnector, connectionKind: ConnectionKind) => void; | ||
| connectLedger: (chainId: number, derivationPath: string) => void; | ||
| } | ||
| export interface Web3ContextNotConnected extends Connectable { | ||
| status: 'notConnected'; | ||
| } | ||
| export interface Web3ContextConnecting { | ||
| status: 'connecting'; | ||
| connectionKind: ConnectionKind; | ||
| } | ||
| export interface AccountWithBalances { | ||
| address: string; | ||
| ethAmount: BigNumber; | ||
| daiAmount: BigNumber; | ||
| } | ||
| export interface Web3ContextConnectingHWSelectAccount { | ||
| status: 'connectingHWSelectAccount'; | ||
| connectionKind: 'ledger' | 'trezor'; | ||
| getAccounts: (accountsLength: number) => Promise<AccountWithBalances[]>; | ||
| selectAccount: (account: string) => void; | ||
| deactivate: () => void; | ||
| } | ||
| export interface Web3ContextConnectedReadonly extends Connectable { | ||
| status: 'connectedReadonly'; | ||
| connectionKind: ConnectionKind; | ||
| web3: Web3; | ||
| chainId: number; | ||
| deactivate: () => void; | ||
| } | ||
| export interface Web3ContextConnected { | ||
| status: 'connected'; | ||
| connectionKind: ConnectionKind; | ||
| web3: Web3; | ||
| chainId: number; | ||
| deactivate: () => void; | ||
| account: string; | ||
| magicLinkEmail?: string; | ||
| } | ||
| export interface Web3ContextError extends Connectable { | ||
| status: 'error'; | ||
| error: Error; | ||
| } | ||
| export declare type Web3Context = Web3ContextNotConnected | Web3ContextConnecting | Web3ContextConnectingHWSelectAccount | Web3ContextError | Web3ContextConnectedReadonly | Web3ContextConnected; | ||
| export {}; | ||
| //# sourceMappingURL=types.d.ts.map |
| {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,oBAAY,cAAc,GACtB,UAAU,GACV,YAAY,GACZ,eAAe,GACf,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,WAAW,CAAC;AAEhB,UAAU,WAAW;IACnB,OAAO,EAAE,CAAC,SAAS,EAAE,iBAAiB,EAAE,cAAc,EAAE,cAAc,KAAK,IAAI,CAAC;IAChF,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,KAAK,IAAI,CAAC;CAClE;AAED,MAAM,WAAW,uBAAwB,SAAQ,WAAW;IAC1D,MAAM,EAAE,cAAc,CAAC;C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||
| //# sourceMappingURL=types.js.map |
| {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""} |
| import { Observable } from 'rxjs'; | ||
| import Web3 from 'web3'; | ||
| import { LedgerConnector } from '../../connectors/lib/src'; | ||
| import { ContractDesc } from './network'; | ||
| import { AccountWithBalances, Web3Context } from './types'; | ||
| export declare type BalanceOfMethod = (address: string) => { | ||
| call: () => Promise<string>; | ||
| }; | ||
| export declare type BalanceOfCreator = (web3: Web3, chainId: number) => BalanceOfMethod; | ||
| export declare function fetchAccountBalances(accountsLength: number, connector: LedgerConnector, daiContractDesc: ContractDesc): Promise<AccountWithBalances[]>; | ||
| export declare function createWeb3Context$(chainIdToRpcUrl: { | ||
| [chainId: number]: string; | ||
| }, chainIdToDaiContractDesc: { | ||
| [chainId: number]: ContractDesc; | ||
| }): [Observable<Web3Context>, () => void]; | ||
| //# sourceMappingURL=web3_context.d.ts.map |
| {"version":3,"file":"web3_context.d.ts","sourceRoot":"","sources":["../../src/web3_context.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAiB,MAAM,MAAM,CAAC;AAEjD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAY,YAAY,EAAgB,MAAM,WAAW,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAkB,WAAW,EAAE,MAAM,SAAS,CAAC;AAG3E,oBAAY,eAAe,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK;IAAE,IAAI,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAA;CAAE,CAAC;AACnF,oBAAY,gBAAgB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,KAAK,eAAe,CAAC;AAEhF,wBAAsB,oBAAoB,CACxC,cAAc,EAAE,MAAM,EACtB,SAAS,EAAE,eAAe,EAC1B,eAAe,EAAE,YAAY,GAC5B,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAiBhC;AAED,wBAAgB,kBAAkB,CAChC,eAAe,EAAE;IAAE,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,EAC9C,wBAAwB,EAAE;IAAE,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,CAAA;CAAE,GAC5D,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC,CA4JvC"} |
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.createWeb3Context$ = exports.fetchAccountBalances = void 0; | ||
| const core_1 = require("@web3-react/core"); | ||
| const network_connector_1 = require("@web3-react/network-connector"); | ||
| const bignumber_js_1 = __importDefault(require("bignumber.js")); | ||
| const lodash_1 = require("lodash"); | ||
| const react_1 = require("react"); | ||
| const rxjs_1 = require("rxjs"); | ||
| const operators_1 = require("rxjs/operators"); | ||
| const web3_1 = __importDefault(require("web3")); | ||
| const network_1 = require("./network"); | ||
| const utils_1 = require("./utils"); | ||
| async function fetchAccountBalances(accountsLength, connector, daiContractDesc) { | ||
| const provider = await connector.getProvider(); | ||
| const web3 = new web3_1.default(provider); | ||
| const accounts = await connector.getAccounts(accountsLength); | ||
| return Promise.all(accounts.map(async (address) => { | ||
| const etherBalance = utils_1.amountFromWei(new bignumber_js_1.default(await web3.eth.getBalance(address))); | ||
| const daiBalanceOfMethod = network_1.contract(web3, daiContractDesc).methods.balanceOf; | ||
| const daiBalance = utils_1.amountFromWei(new bignumber_js_1.default(await daiBalanceOfMethod(address).call())); | ||
| return { | ||
| address: web3_1.default.utils.toChecksumAddress(address), | ||
| daiAmount: daiBalance, | ||
| ethAmount: etherBalance, | ||
| }; | ||
| })); | ||
| } | ||
| exports.fetchAccountBalances = fetchAccountBalances; | ||
| function createWeb3Context$(chainIdToRpcUrl, chainIdToDaiContractDesc) { | ||
| const web3Context$ = new rxjs_1.ReplaySubject(1); | ||
| function push(c) { | ||
| web3Context$.next(c); | ||
| } | ||
| function setupWeb3Context$() { | ||
| const context = core_1.useWeb3React(); | ||
| const { connector, library, chainId, account, activate, deactivate, active, error } = context; | ||
| const [activatingConnector, setActivatingConnector] = react_1.useState(); | ||
| const [connectionKind, setConnectionKind] = react_1.useState(); | ||
| const [hwAccount, setHWAccount] = react_1.useState(); | ||
| async function connect(connector, connectionKind) { | ||
| setActivatingConnector(connector); | ||
| setConnectionKind(connectionKind); | ||
| await activate(connector); | ||
| } | ||
| async function connectLedger(_chainId, _baseDerivationPath) { | ||
| throw new Error('Not implemented yet!'); | ||
| // const connector = new LedgerConnector({ | ||
| // baseDerivationPath, | ||
| // chainId, | ||
| // url: networks[chainId].infuraUrl, | ||
| // pollingInterval: pollingInterval, | ||
| // }) | ||
| // setActivatingConnector(connector) | ||
| // setConnectionKind('ledger') | ||
| // setHWAccount(undefined) | ||
| // await activate(connector) | ||
| } | ||
| react_1.useEffect(() => { | ||
| if (activatingConnector && activatingConnector === connector) { | ||
| setActivatingConnector(undefined); | ||
| } | ||
| }, [activatingConnector, connector]); | ||
| react_1.useEffect(() => { | ||
| // TODO: Move this logic somewhere else to fix Wallet Link autoconnect | ||
| // if (connector && (connector as WalletLinkConnector).walletLink) { | ||
| // const con = connector as WalletLinkConnector; | ||
| // con.walletLink._relay.connection.sessionConfig$ | ||
| // .pipe(filter((c: any) => !!c.metadata && c.metadata.__destroyed === '1')) | ||
| // .subscribe(() => { | ||
| // localStorage.removeItem(AUTO_CONNECT); | ||
| // }); | ||
| // } | ||
| if (activatingConnector) { | ||
| push({ | ||
| status: 'connecting', | ||
| connectionKind: connectionKind, | ||
| }); | ||
| return; | ||
| } | ||
| if (error) { | ||
| console.log(error); | ||
| push({ | ||
| status: 'error', | ||
| error, | ||
| connect, | ||
| connectLedger, | ||
| }); | ||
| return; | ||
| } | ||
| if (!connector) { | ||
| push({ | ||
| status: 'notConnected', | ||
| connect, | ||
| connectLedger, | ||
| }); | ||
| return; | ||
| } | ||
| if (!account) { | ||
| push({ | ||
| status: 'connectedReadonly', | ||
| connectionKind: connectionKind, | ||
| web3: library, | ||
| chainId: chainId, | ||
| connect, | ||
| connectLedger, | ||
| deactivate, | ||
| }); | ||
| return; | ||
| } | ||
| if ((connectionKind === 'ledger' || connectionKind === 'trezor') && !hwAccount) { | ||
| push({ | ||
| status: 'connectingHWSelectAccount', | ||
| connectionKind, | ||
| getAccounts: async (accountsLength) => await fetchAccountBalances(accountsLength, connector, chainIdToDaiContractDesc[chainId]), | ||
| selectAccount: (account) => { | ||
| setHWAccount(account); | ||
| }, | ||
| deactivate, | ||
| }); | ||
| return; | ||
| } | ||
| if (chainId !== network_1.getNetworkId()) { | ||
| setTimeout(() => { | ||
| // eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
| connect(new network_connector_1.NetworkConnector({ | ||
| urls: chainIdToRpcUrl, | ||
| defaultChainId: network_1.getNetworkId(), | ||
| }), 'network'); | ||
| }); | ||
| return; | ||
| } | ||
| if (connectionKind) { | ||
| push({ | ||
| status: 'connected', | ||
| connectionKind, | ||
| web3: library, | ||
| chainId: chainId, | ||
| account: ['ledger', 'trezor'].indexOf(connectionKind) >= 0 ? hwAccount : account, | ||
| deactivate, | ||
| magicLinkEmail: undefined, | ||
| }); | ||
| } | ||
| }, [ | ||
| activatingConnector, | ||
| connectionKind, | ||
| connector, | ||
| library, | ||
| chainId, | ||
| account, | ||
| activate, | ||
| deactivate, | ||
| active, | ||
| error, | ||
| hwAccount, | ||
| ]); | ||
| } | ||
| return [web3Context$.pipe(operators_1.distinctUntilChanged(lodash_1.isEqual)), setupWeb3Context$]; | ||
| } | ||
| exports.createWeb3Context$ = createWeb3Context$; | ||
| //# sourceMappingURL=web3_context.js.map |
| {"version":3,"file":"web3_context.js","sourceRoot":"","sources":["../../src/web3_context.ts"],"names":[],"mappings":";;;;;;AACA,2CAAgD;AAChD,qEAAiE;AACjE,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sBAAY,EAAE;qBAC/B,CAAC,EACF,SAAS,CACV,CAAC;gBACJ,CAAC,CAAC,CAAC;gBACH,OAAO;aACR;YAED,IAAI,cAAc,EAAE;gBAClB,IAAI,CAAC;oBACH,MAAM,EAAE,WAAW;oBACnB,cAAc;oBACd,IAAI,EAAE,OAAc;oBACpB,OAAO,EAAE,OAAQ;oBACjB,OAAO,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAU,CAAC,CAAC,CAAC,OAAO;oBACjF,UAAU;oBACV,cAAc,EAAE,SAAS;iBAK1B,CAAC,CAAC;aACJ;QACH,CAAC,EAAE;YACD,mBAAmB;YACnB,cAAc;YACd,SAAS;YACT,OAAO;YACP,OAAO;YACP,OAAO;YACP,QAAQ;YACR,UAAU;YACV,MAAM;YACN,KAAK;YACL,SAAS;SACV,CAAC,CAAC;IACL,CAAC;IAED,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,gCAAoB,CAAC,gBAAO,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAC;AAC/E,CAAC;AA/JD,gDA+JC"} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No License Found
LicenseLicense information could not be found.
Found 1 instance in 1 package
0
-100%19216
-31.99%14
-51.72%111
-71.97%1
Infinity%