Skip to content

Commit

Permalink
loopring provide
Browse files Browse the repository at this point in the history
  • Loading branch information
windatang committed Mar 24, 2022
1 parent 39eb6d9 commit 8dce545
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 166 deletions.
28 changes: 20 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
<p align="center">
<p align="center" >
<a href="https://github.com/Loopring/loopring-web-v2" rel="noopener" target="_blank"><img width="150" src="https://loopring.org/images/logo.svg" alt="Loopring-website"></a>
</p>


<h1 align="center">Loopring Application</h1>
<h1 align="center">Loopring web3-provider</h1>
<div align="center">
<h2>Ethereum’s First zkRollup Layer2</h2>
<p>Secure, Fast, and Cheap</p>
<h2>A lite tool to connect web extension & Dapp</h2>
<p>Open source and free use</p>

[![license](https://img.shields.io/badge/license-GPL-blue)](https://github.com/Loopring/loopring-web-v2/master/LICENSE)
[![license](https://img.shields.io/badge/license-MIT-blue)](https://github.com/Loopring/loopring-web-v2/master/LICENSE)

[![type-badge](https://img.shields.io/npm/types/react-data-grid)](https://www.npmjs.com/package/react-data-grid)

<!-- [![Materi-UI](https://img.shields.io/npm/types/react-data-grid)](https://www.npmjs.com/package/react-data-grid) -->

</div>

## 🚀 Quick Start

```bash
// with yarn
yarn install
yarn install @loopring-web/web3-provider
```
## 🛒 Support Provider
- Metamask
- WallectConnet
- Coinbase
- Coming soon

## env.product
```.env.product
RPC_URL_1=https://mainnet.eth.loopring.network
RPC_URL_5=https://goerli.infura.io/v3/b951a403f3d3426fb2008c6923254dbc
WALLET_CONNECT_BRIDGE=https://wcbridge.loopring.network
WALLET_CONNECT_PING=https://wcbridge.loopring.network/hello
```
Demo for React hook

## 👉 [What is Loopring?](https://loopring.org/#/)

Expand Down
34 changes: 6 additions & 28 deletions demo/react/.env.example
Original file line number Diff line number Diff line change
@@ -1,30 +1,8 @@
NODE_ENV=production

#NODE_ENV=dev
HTTPS=true
NODE_TLS_REJECT_UNAUTHORIZED=0

ASSET_PATH = './'

#REACT_APP_RPC_URL_1=https://mainnet.infura.io/v3/84842078b09946638c03157f83405213
REACT_APP_RPC_URL_1=https://mainnet.eth.loopring.network
HTTPS=true

#REACT_APP_RPC_URL_1=http://18.220.83.236:8545
REACT_APP_RPC_URL_5=https://goerli.infura.io/v3/b951a403f3d3426fb2008c6923254dbc

#REACT_APP_WALLET_CONNECT_BRIDGE=https://bridge.walletconnect.org
#REACT_APP_WALLET_CONNECT_BRIDGE=http://ec2-3-143-67-250.us-east-2.compute.amazonaws.com:37821
#REACT_APP_WALLET_CONNECT_BRIDGE=https://connect.loopring.io
REACT_APP_WALLET_CONNECT_BRIDGE=https://wcbridge.loopring.network

REACT_APP_FORTMATIC_API_KEY=pk_test_A6260FCBAA2EBDFB
REACT_APP_MAGIC_API_KEY=pk_test_398B82F5F0E88874
REACT_APP_PORTIS_DAPP_ID=e9be171c-2b7f-4ff0-8db9-327707511ee2

#REACT_APP_API_URL=api.loopring.network
#REACT_APP_API_URL_UAT=api.uat.loopring.pro
REACT_APP_API_URL=api3.loopring.io
REACT_APP_API_URL_UAT=uat2.loopring.io

SKIP_PREFLIGHT_CHECK=true

REACT_APP_WITH_PRO=true
RPC_URL_1=https://mainnet.eth.loopring.network
RPC_URL_5=https://goerli.infura.io/v3/b951a403f3d3426fb2008c6923254dbc
WALLET_CONNECT_BRIDGE=https://wcbridge.loopring.network
WALLET_CONNECT_PING=https://wcbridge.loopring.network/hello
6 changes: 3 additions & 3 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const ExtensionSubscribe = (provider: any, web3: Web3) => {
walletServices.sendDisconnect(-1, "disconnect for no account");
}
});
provider.on("chainChanged", (chainId: number) => {
provider.on("chainChanged", (_chainId: number) => {
walletServices.sendConnect(web3, provider);
});
provider.on("disconnect", (code: number, reason: string) => {
Expand All @@ -51,6 +51,6 @@ export enum ConnectProviders {
Coinbase = "Coinbase",
}
export const RPC_URLS: { [chainId: number]: string } = {
1: process.env.REACT_APP_RPC_URL_1 as string,
5: process.env.REACT_APP_RPC_URL_5 as string,
1: process.env.RPC_URL_1 as string,
5: process.env.RPC_URL_5 as string,
};
28 changes: 15 additions & 13 deletions src/walletConnect/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@ import { walletServices } from "../walletServices";
import { ConnectProviders, ErrorType, RPC_URLS } from "../command";
import { IsMobile } from "../utilities";
const POLLING_INTERVAL = 12000;

const DEFAULT_BRIDGE = "https://bridge.walletconnect.org"
export const WalletConnectProvide = async (props?: {
account?: string;
darkMode?: boolean;
}): Promise<{ provider?: WalletConnectProvider; web3?: Web3 } | undefined> => {
try {
const BRIDGE_URL = await fetch("https://wcbridge.loopring.network/hello")
.then(({ status }) => {
return status === 200
? process.env.REACT_APP_WALLET_CONNECT_BRIDGE
: "https://bridge.walletconnect.org";
})
.catch(() => {
return "https://bridge.walletconnect.org";
});
const BRIDGE_URL = (await fetch(process.env.WALLET_CONNECT_PING??'')
.then(({ status }) => {
return status === 200
? process.env.WALLET_CONNECT_BRIDGE
: DEFAULT_BRIDGE;
})
.catch(() => {
return DEFAULT_BRIDGE;
}))??DEFAULT_BRIDGE


// const BRIDGE_URL = "https://bridge.walletconnect.org";

const provider: WalletConnectProvider = new WalletConnectProvider({
Expand Down Expand Up @@ -72,7 +74,7 @@ export const WalletConnectProvide = async (props?: {
export const WalletConnectSubscribe = (
provider: any,
web3: Web3,
account?: string
_account?: string
) => {
const { connector } = provider;
if (provider && connector && connector.connected) {
Expand Down Expand Up @@ -192,8 +194,8 @@ export const WalletConnectUnsubscribe = async (provider: any) => {
// const POLLING_INTERVAL = 12000
//
// const RPC_URLS: { [chainId: number]: string } = {
// 1: process.env.REACT_APP_RPC_URL_1 as string,
// 5: process.env.REACT_APP_RPC_URL_5 as string
// 1: process.env.RPC_URL_1 as string,
// 5: process.env.RPC_URL_5 as string
// }
//
// myLog('RPC_URLS 1:', RPC_URLS[1])
Expand Down
8 changes: 5 additions & 3 deletions src/walletServices.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Subject } from "rxjs-compat";
import Web3 from "web3";
import { Commands, ErrorType, ProcessingType } from "./command";

const { Subject } = require('rxjs');

//TODO typeof account State
const subject = new Subject<{ status: keyof typeof Commands; data: any }>();
const subject = new Subject();

const AvaiableNetwork = [1, 5];
export const walletServices = {subject,
export const walletServices = {
subject,
sendProcess: async (type: keyof typeof ProcessingType, props?: any) => {
subject.next({
status: Commands.Processing,
Expand Down
111 changes: 0 additions & 111 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1688,107 +1688,6 @@
dependencies:
"@types/node" "*"

"@types/rx-core-binding@*":
version "4.0.4"
resolved "https://registry.yarnpkg.com/@types/rx-core-binding/-/rx-core-binding-4.0.4.tgz#d969d32f15a62b89e2862c17b3ee78fe329818d3"
integrity sha512-5pkfxnC4w810LqBPUwP5bg7SFR/USwhMSaAeZQQbEHeBp57pjKXRlXmqpMrLJB4y1oglR/c2502853uN0I+DAQ==
dependencies:
"@types/rx-core" "*"

"@types/rx-core@*":
version "4.0.3"
resolved "https://registry.yarnpkg.com/@types/rx-core/-/rx-core-4.0.3.tgz#0b3354b1238cedbe2b74f6326f139dbc7a591d60"
integrity sha1-CzNUsSOM7b4rdPYybxOdvHpZHWA=

"@types/rx-lite-aggregates@*":
version "4.0.3"
resolved "https://registry.yarnpkg.com/@types/rx-lite-aggregates/-/rx-lite-aggregates-4.0.3.tgz#6efb2b7f3d5f07183a1cb2bd4b1371d7073384c2"
integrity sha512-MAGDAHy8cRatm94FDduhJF+iNS5//jrZ/PIfm+QYw9OCeDgbymFHChM8YVIvN2zArwsRftKgE33QfRWvQk4DPg==
dependencies:
"@types/rx-lite" "*"

"@types/rx-lite-async@*":
version "4.0.2"
resolved "https://registry.yarnpkg.com/@types/rx-lite-async/-/rx-lite-async-4.0.2.tgz#27fbf0caeff029f41e2d2aae638b05e91ceb600c"
integrity sha512-vTEv5o8l6702ZwfAM5aOeVDfUwBSDOs+ARoGmWAKQ6LOInQ8J4/zjM7ov12fuTpktUKdMQjkeCp07Vd73mPkxw==
dependencies:
"@types/rx-lite" "*"

"@types/rx-lite-backpressure@*":
version "4.0.3"
resolved "https://registry.yarnpkg.com/@types/rx-lite-backpressure/-/rx-lite-backpressure-4.0.3.tgz#05abb19bdf87cc740196c355e5d0b37bb50b5d56"
integrity sha512-Y6aIeQCtNban5XSAF4B8dffhIKu6aAy/TXFlScHzSxh6ivfQBQw6UjxyEJxIOt3IT49YkS+siuayM2H/Q0cmgA==
dependencies:
"@types/rx-lite" "*"

"@types/rx-lite-coincidence@*":
version "4.0.3"
resolved "https://registry.yarnpkg.com/@types/rx-lite-coincidence/-/rx-lite-coincidence-4.0.3.tgz#80bd69acc4054a15cdc1638e2dc8843498cd85c0"
integrity sha512-1VNJqzE9gALUyMGypDXZZXzR0Tt7LC9DdAZQ3Ou/Q0MubNU35agVUNXKGHKpNTba+fr8GdIdkC26bRDqtCQBeQ==
dependencies:
"@types/rx-lite" "*"

"@types/rx-lite-experimental@*":
version "4.0.1"
resolved "https://registry.yarnpkg.com/@types/rx-lite-experimental/-/rx-lite-experimental-4.0.1.tgz#c532f5cbdf3f2c15da16ded8930d1b2984023cbd"
integrity sha1-xTL1y98/LBXaFt7Ykw0bKYQCPL0=
dependencies:
"@types/rx-lite" "*"

"@types/rx-lite-joinpatterns@*":
version "4.0.1"
resolved "https://registry.yarnpkg.com/@types/rx-lite-joinpatterns/-/rx-lite-joinpatterns-4.0.1.tgz#f70fe370518a8432f29158cc92ffb56b4e4afc3e"
integrity sha1-9w/jcFGKhDLykVjMkv+1a05K/D4=
dependencies:
"@types/rx-lite" "*"

"@types/rx-lite-testing@*":
version "4.0.1"
resolved "https://registry.yarnpkg.com/@types/rx-lite-testing/-/rx-lite-testing-4.0.1.tgz#21b19d11f4dfd6ffef5a9d1648e9c8879bfe21e9"
integrity sha1-IbGdEfTf1v/vWp0WSOnIh5v+Iek=
dependencies:
"@types/rx-lite-virtualtime" "*"

"@types/rx-lite-time@*":
version "4.0.3"
resolved "https://registry.yarnpkg.com/@types/rx-lite-time/-/rx-lite-time-4.0.3.tgz#0eda65474570237598f3448b845d2696f2dbb1c4"
integrity sha512-ukO5sPKDRwCGWRZRqPlaAU0SKVxmWwSjiOrLhoQDoWxZWg6vyB9XLEZViKOzIO6LnTIQBlk4UylYV0rnhJLxQw==
dependencies:
"@types/rx-lite" "*"

"@types/rx-lite-virtualtime@*":
version "4.0.3"
resolved "https://registry.yarnpkg.com/@types/rx-lite-virtualtime/-/rx-lite-virtualtime-4.0.3.tgz#4b30cacd0fe2e53af29f04f7438584c7d3959537"
integrity sha512-3uC6sGmjpOKatZSVHI2xB1+dedgml669ZRvqxy+WqmGJDVusOdyxcKfyzjW0P3/GrCiN4nmRkLVMhPwHCc5QLg==
dependencies:
"@types/rx-lite" "*"

"@types/rx-lite@*":
version "4.0.6"
resolved "https://registry.yarnpkg.com/@types/rx-lite/-/rx-lite-4.0.6.tgz#3c02921c4244074234f26b772241bcc20c18c253"
integrity sha512-oYiDrFIcor9zDm0VDUca1UbROiMYBxMLMaM6qzz4ADAfOmA9r1dYEcAFH+2fsPI5BCCjPvV9pWC3X3flbrvs7w==
dependencies:
"@types/rx-core" "*"
"@types/rx-core-binding" "*"

"@types/rx@^4.1.2":
version "4.1.2"
resolved "https://registry.yarnpkg.com/@types/rx/-/rx-4.1.2.tgz#a4061b3d72b03cf11a38d69e2022a17334c54dc0"
integrity sha512-1r8ZaT26Nigq7o4UBGl+aXB2UMFUIdLPP/8bLIP0x3d0pZL46ybKKjhWKaJQWIkLl5QCLD0nK3qTOO1QkwdFaA==
dependencies:
"@types/rx-core" "*"
"@types/rx-core-binding" "*"
"@types/rx-lite" "*"
"@types/rx-lite-aggregates" "*"
"@types/rx-lite-async" "*"
"@types/rx-lite-backpressure" "*"
"@types/rx-lite-coincidence" "*"
"@types/rx-lite-experimental" "*"
"@types/rx-lite-joinpatterns" "*"
"@types/rx-lite-testing" "*"
"@types/rx-lite-time" "*"
"@types/rx-lite-virtualtime" "*"

"@types/secp256k1@^4.0.1":
version "4.0.3"
resolved "https://registry.yarnpkg.com/@types/secp256k1/-/secp256k1-4.0.3.tgz#1b8e55d8e00f08ee7220b4d59a6abe89c37a901c"
Expand Down Expand Up @@ -7868,11 +7767,6 @@ rustbn.js@~0.2.0:
resolved "https://registry.yarnpkg.com/rustbn.js/-/rustbn.js-0.2.0.tgz#8082cb886e707155fd1cb6f23bd591ab8d55d0ca"
integrity sha512-4VlvkRUuCJvr2J6Y0ImW7NvTCriMi7ErOAqWk1y69vAdoNIzCF3yPmgeNzx+RQTLEDFq5sHfscn1MwHxP9hNfA==

rxjs-compat@^6.6.7:
version "6.6.7"
resolved "https://registry.yarnpkg.com/rxjs-compat/-/rxjs-compat-6.6.7.tgz#6eb4ef75c0a58ea672854a701ccc8d49f41e69cb"
integrity sha512-szN4fK+TqBPOFBcBcsR0g2cmTTUF/vaFEOZNuSdfU8/pGFnNmmn2u8SystYXG1QMrjOPBc6XTKHMVfENDf6hHw==

rxjs@^6.6.0, rxjs@^6.6.3:
version "6.6.7"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.6.7.tgz#90ac018acabf491bf65044235d5863c4dab804c9"
Expand Down Expand Up @@ -8917,11 +8811,6 @@ typescript@^3.7.3:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.10.tgz#70f3910ac7a51ed6bef79da7800690b19bf778b8"
integrity sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q==

typescript@^4.6.2:
version "4.6.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.6.2.tgz#fe12d2727b708f4eef40f51598b3398baa9611d4"
integrity sha512-HM/hFigTBHZhLXshn9sN37H085+hQGeJHJ/X7LpBWLID/fbc2acUMfU+lGD98X81sKP+pFa9f0DZmCwB9GnbAg==

[email protected]:
version "1.3.5"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-1.3.5.tgz#4b5bfff9186effbaa888e4c9e94bd9fc4c94929d"
Expand Down

0 comments on commit 8dce545

Please sign in to comment.