Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
lts/erbium
14
10 changes: 10 additions & 0 deletions src/app/containers/BlockChainProvider/classifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ export const rpcNodes = {
};

export const wssNodes = {
30: 'wss://mainnet.sovryn.app/webscoket',
31: 'wss://testnet.sovryn.app/webscoket',
};

export const databaseRpcNodes = {
30: 'https://backend.sovryn.app/rpc',
31: 'https://testnet.sovryn.app/backend/rpc',
};

export const rpcBackupNodes = {
30: 'wss://mainnet2.sovryn.app/websocket',
31: 'wss://testnet.sovryn.app/websocket',
};
Expand Down
47 changes: 42 additions & 5 deletions src/app/containers/BlockChainProvider/network.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { databaseRpcNodes } from './classifiers';
import Web3 from 'web3';
import ContractClass, { EventData, Contract } from 'web3-eth-contract';
import { RevertInstructionError } from 'web3-core-helpers';
Expand Down Expand Up @@ -29,9 +30,49 @@ class Network {
public wsContracts: {} = {};
public writeContracts: { [key: string]: Contract } = {};

private _databaseWeb3: Web3 = null as any;
public databaseContracts: { [key: string]: Contract } = {};
public databaseContractList: Contract[] = [];

private _network: NetworkName = null as any;
private _writeNetwork: NetworkName = null as any;

public async initDatabaseWeb3(chainId: number) {
try {
const nodeUrl = databaseRpcNodes[chainId];
const web3Provider = new Web3.providers.HttpProvider(nodeUrl, {
keepAlive: true,
});
this._databaseWeb3 = new Web3(web3Provider);

const netwrokName = chainId === 30 ? 'mainnet' : 'testnet';
Array.from(Object.keys(contracts[netwrokName])).forEach(key => {
this.addDatabaseContract(key, contracts[netwrokName][key]);
});
} catch (e) {
console.error('init database web3 fails.');
console.error(e);
}
}

public addDatabaseContract(
contractName: string,
contractConfig: {
address: string;
abi: AbiItem | AbiItem[];
},
) {
if (!this._databaseWeb3) {
return;
}
console.log('contractConfig: ', contractName, contractConfig);
const contract = this.makeContract(this._databaseWeb3, contractConfig);
// @ts-ignore
this.databaseContracts[contractName] = contract;
// @ts-ignore
this.databaseContractList.push(contract);
}

public setWeb3(web3: Web3, network: NetworkName) {
this.web3 = web3;
if (this._network !== network) {
Expand Down Expand Up @@ -267,11 +308,7 @@ class Network {
fromBlock: number = 0,
toBlock: number | 'latest' = 'latest',
): Promise<EventData[]> {
if (!this.wsContracts.hasOwnProperty(contractName)) {
return Promise.resolve([]);
}

return this.wsContracts[contractName].getPastEvents(eventName, {
return this.databaseContracts[contractName].getPastEvents(eventName, {
fromBlock,
toBlock,
filter,
Expand Down
1 change: 1 addition & 0 deletions src/app/containers/BlockChainProvider/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function* setupSaga({ payload }: PayloadAction<ChainId>) {
const web3 = new Web3(web3Provider);
const wsWeb3 = new Web3(web3WsProvider);

network.initDatabaseWeb3(payload);
network.setWeb3(web3, payload === 30 ? 'mainnet' : 'testnet');
network.setWsWeb3(wsWeb3, payload === 30 ? 'mainnet' : 'testnet', true);

Expand Down
9 changes: 7 additions & 2 deletions src/app/hooks/useProposalList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,27 @@ export function useProposalList(page: number, limit: number = 0) {

setTotal(adminItemsCount + ownerItemsCount);

const adminItems = await getProposalsOf(
const adminPromise = await getProposalsOf(
'governorAdmin',
getContract('governorAdmin').address,
adminItemsCount,
page,
limit,
);

const ownerItems = await getProposalsOf(
const ownerPromise = await getProposalsOf(
'governorOwner',
getContract('governorOwner').address,
ownerItemsCount,
page,
limit,
);

const [adminItems, ownerItems] = await Promise.all([
adminPromise,
ownerPromise,
]);

const merged = [...adminItems, ...ownerItems]
.sort((a, b) => b.startBlock - a.startBlock)
.filter(item => {
Expand Down