Skip to content

Commit

Permalink
v3.0.1: always return a new provider for every request
Browse files Browse the repository at this point in the history
  • Loading branch information
10xSebastian committed Jul 31, 2021
1 parent bc927be commit 02840cd
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 208 deletions.
52 changes: 13 additions & 39 deletions dist/cjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,17 @@ let cache = async function ({ call, key, expires = 0 }) {
return value
};

function _optionalChain$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
let account, provider;

async function ethereumProvider () {
let newAccount;

if (_optionalChain$1([window, 'optionalAccess', _ => _.ethereum])) {
newAccount = await depayWeb3Wallets.getWallet().account();
}

if (provider && newAccount === account) {
return provider
}
account = newAccount;

let account = await depayWeb3Wallets.getWallet().account();

if (account) {
provider = await new ethers.ethers.providers.Web3Provider(window.ethereum);
return await new ethers.ethers.providers.Web3Provider(window.ethereum)
} else {
provider = await new ethers.ethers.providers.JsonRpcProvider(
return await new ethers.ethers.providers.JsonRpcProvider(
['https://mainnet.infu', 'ra.io/v3/9aa3d95b3bc440fa8', '8ea12eaa4456161'].join(''),
);
)
}

return provider
}

let paramsToContractArgs = ({ contract, method, params }) => {
Expand Down Expand Up @@ -128,30 +115,17 @@ var requestEthereum = async ({ address, api, method, params }) => {
})
};

function _optionalChain$2(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
let account$1, provider$1;

async function bscProvider () {
let newAccount;

if (_optionalChain$2([window, 'optionalAccess', _ => _.ethereum])) {
newAccount = await depayWeb3Wallets.getWallet().account();
}

if (provider$1 && newAccount === account$1) {
return provider$1
}
account$1 = newAccount;

let account = await depayWeb3Wallets.getWallet().account();

if (account$1) {
provider$1 = await new ethers.ethers.providers.Web3Provider(window.ethereum);
if (account) {
return await new ethers.ethers.providers.Web3Provider(window.ethereum)
} else {
provider$1 = await new ethers.ethers.providers.JsonRpcProvider(
return await new ethers.ethers.providers.JsonRpcProvider(
'https://bsc-dataseed.binance.org'
);
)
}

return provider$1
}

var requestBsc = async ({ address, api, method, params }) => {
Expand Down Expand Up @@ -248,7 +222,7 @@ let request$2 = async function (url, options) {
}
};

async function provider$2 (blockchain) {
async function provider (blockchain) {
switch (blockchain) {

case 'ethereum':
Expand All @@ -263,6 +237,6 @@ async function provider$2 (blockchain) {
}

exports.estimate = request$2;
exports.provider = provider$2;
exports.provider = provider;
exports.request = request$1;
exports.resetCache = resetCache;
52 changes: 13 additions & 39 deletions dist/es/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,17 @@ let cache = async function ({ call, key, expires = 0 }) {
return value
};

function _optionalChain$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
let account, provider;

async function ethereumProvider () {
let newAccount;

if (_optionalChain$1([window, 'optionalAccess', _ => _.ethereum])) {
newAccount = await getWallet().account();
}

if (provider && newAccount === account) {
return provider
}
account = newAccount;

let account = await getWallet().account();

if (account) {
provider = await new ethers.providers.Web3Provider(window.ethereum);
return await new ethers.providers.Web3Provider(window.ethereum)
} else {
provider = await new ethers.providers.JsonRpcProvider(
return await new ethers.providers.JsonRpcProvider(
['https://mainnet.infu', 'ra.io/v3/9aa3d95b3bc440fa8', '8ea12eaa4456161'].join(''),
);
)
}

return provider
}

let paramsToContractArgs = ({ contract, method, params }) => {
Expand Down Expand Up @@ -124,30 +111,17 @@ var requestEthereum = async ({ address, api, method, params }) => {
})
};

function _optionalChain$2(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
let account$1, provider$1;

async function bscProvider () {
let newAccount;

if (_optionalChain$2([window, 'optionalAccess', _ => _.ethereum])) {
newAccount = await getWallet().account();
}

if (provider$1 && newAccount === account$1) {
return provider$1
}
account$1 = newAccount;

let account = await getWallet().account();

if (account$1) {
provider$1 = await new ethers.providers.Web3Provider(window.ethereum);
if (account) {
return await new ethers.providers.Web3Provider(window.ethereum)
} else {
provider$1 = await new ethers.providers.JsonRpcProvider(
return await new ethers.providers.JsonRpcProvider(
'https://bsc-dataseed.binance.org'
);
)
}

return provider$1
}

var requestBsc = async ({ address, api, method, params }) => {
Expand Down Expand Up @@ -244,7 +218,7 @@ let request$2 = async function (url, options) {
}
};

async function provider$2 (blockchain) {
async function provider (blockchain) {
switch (blockchain) {

case 'ethereum':
Expand All @@ -258,4 +232,4 @@ async function provider$2 (blockchain) {
}
}

export { request$2 as estimate, provider$2 as provider, request$1 as request, resetCache };
export { request$2 as estimate, provider, request$1 as request, resetCache };
52 changes: 13 additions & 39 deletions dist/umd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,17 @@
return value
};

function _optionalChain$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
let account, provider;

async function ethereumProvider () {
let newAccount;

if (_optionalChain$1([window, 'optionalAccess', _ => _.ethereum])) {
newAccount = await depayWeb3Wallets.getWallet().account();
}

if (provider && newAccount === account) {
return provider
}
account = newAccount;

let account = await depayWeb3Wallets.getWallet().account();

if (account) {
provider = await new ethers.ethers.providers.Web3Provider(window.ethereum);
return await new ethers.ethers.providers.Web3Provider(window.ethereum)
} else {
provider = await new ethers.ethers.providers.JsonRpcProvider(
return await new ethers.ethers.providers.JsonRpcProvider(
['https://mainnet.infu', 'ra.io/v3/9aa3d95b3bc440fa8', '8ea12eaa4456161'].join(''),
);
)
}

return provider
}

let paramsToContractArgs = ({ contract, method, params }) => {
Expand Down Expand Up @@ -127,30 +114,17 @@
})
};

function _optionalChain$2(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
let account$1, provider$1;

async function bscProvider () {
let newAccount;

if (_optionalChain$2([window, 'optionalAccess', _ => _.ethereum])) {
newAccount = await depayWeb3Wallets.getWallet().account();
}

if (provider$1 && newAccount === account$1) {
return provider$1
}
account$1 = newAccount;

let account = await depayWeb3Wallets.getWallet().account();

if (account$1) {
provider$1 = await new ethers.ethers.providers.Web3Provider(window.ethereum);
if (account) {
return await new ethers.ethers.providers.Web3Provider(window.ethereum)
} else {
provider$1 = await new ethers.ethers.providers.JsonRpcProvider(
return await new ethers.ethers.providers.JsonRpcProvider(
'https://bsc-dataseed.binance.org'
);
)
}

return provider$1
}

var requestBsc = async ({ address, api, method, params }) => {
Expand Down Expand Up @@ -247,7 +221,7 @@
}
};

async function provider$2 (blockchain) {
async function provider (blockchain) {
switch (blockchain) {

case 'ethereum':
Expand All @@ -262,7 +236,7 @@
}

exports.estimate = request$2;
exports.provider = provider$2;
exports.provider = provider;
exports.request = request$1;
exports.resetCache = resetCache;

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "depay-web3-client",
"moduleName": "Web3Client",
"version": "3.0.0",
"version": "3.0.1",
"description": "A web3 client to fetch blockchain data by either using the connected wallet or falling back to RPC.",
"main": "dist/cjs/index.js",
"module": "dist/es/index.js",
Expand Down
18 changes: 4 additions & 14 deletions src/blockchains/bsc/provider.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
import { ethers } from 'ethers'
import { getWallet } from 'depay-web3-wallets'

let account, provider

export default async function () {
let newAccount

if (window?.ethereum) {
newAccount = await getWallet().account()
}

if (provider && newAccount === account) {
return provider
}
account = newAccount

let account = await getWallet().account()

if (account) {
provider = await new ethers.providers.Web3Provider(window.ethereum)
return await new ethers.providers.Web3Provider(window.ethereum)
} else {
provider = await new ethers.providers.JsonRpcProvider(
return await new ethers.providers.JsonRpcProvider(
'https://bsc-dataseed.binance.org'
)
}
Expand Down
18 changes: 4 additions & 14 deletions src/blockchains/ethereum/provider.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
import { ethers } from 'ethers'
import { getWallet } from 'depay-web3-wallets'

let account, provider

export default async function () {
let newAccount

if (window?.ethereum) {
newAccount = await getWallet().account()
}

if (provider && newAccount === account) {
return provider
}
account = newAccount

let account = await getWallet().account()

if (account) {
provider = await new ethers.providers.Web3Provider(window.ethereum)
return await new ethers.providers.Web3Provider(window.ethereum)
} else {
provider = await new ethers.providers.JsonRpcProvider(
return await new ethers.providers.JsonRpcProvider(
['https://mainnet.infu', 'ra.io/v3/9aa3d95b3bc440fa8', '8ea12eaa4456161'].join(''),
)
}
Expand Down
Loading

0 comments on commit 02840cd

Please sign in to comment.