@ -5,16 +5,16 @@ import store from '~/store';
import { ContractType } from '~/types/store' ;
import { ContractType } from '~/types/store' ;
// 0x7a89c2D92Bf53160ab58d7889966741cA8Eb5855
// 0x7a89c2D92Bf53160ab58d7889966741cA8Eb5855
export const config = {
export const config = {
56 : {
chainId : 56 ,
rpc : "https://bsc-dataseed1.defibit.io" ,
address : {
FIL__factory : "0x0d8ce2a99bb6e3b7db580ed848240e4a0f9ae153" ,
NFT__factory : "0x5fd156B6B47Bb0B363fa3D4e2E31a8394Ee7A630" ,
Pool__factory : "0xC31cEb39961076d8fAD3936D88489972c02b4D83" ,
Pledge__factory : "0x2F3d8761c8214627743F84F9890A8eEeD914ddf1" ,
}
} ,
// 56: {
// chainId: 56,
// rpc: "https://bsc-dataseed1.defibit.io",
// address: {
// FIL__factory: "0x0d8ce2a99bb6e3b7db580ed848240e4a0f9ae153",
// NFT__factory: "0x5fd156B6B47Bb0B363fa3D4e2E31a8394Ee7A630",
// Pool__factory: "0xC31cEb39961076d8fAD3936D88489972c02b4D83",
// Pledge__factory: "0x2F3d8761c8214627743F84F9890A8eEeD914ddf1",
// }
// },
97 : {
97 : {
chainId : 97 ,
chainId : 97 ,
rpc : "https://bsc-testnet.blockpi.network/v1/rpc/public" ,
rpc : "https://bsc-testnet.blockpi.network/v1/rpc/public" ,
@ -34,7 +34,7 @@ export const config = {
Pool__factory : "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9" ,
Pool__factory : "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9" ,
Pledge__factory : "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707" ,
Pledge__factory : "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707" ,
}
}
}
} ,
} as any
} as any
// 57.333333333333333332
// 57.333333333333333332
const contractObj = {
const contractObj = {
@ -75,42 +75,46 @@ const switchNetWork = () => {
export const initContract = async ( ) = > {
export const initContract = async ( ) = > {
let chainId = Number ( process . env . REACT_APP_CHAINID ) ;
let account = [ ] as string [ ] ;
try {
let chainId = Number ( process . env . REACT_APP_CHAINID ) ;
let account = [ ] as string [ ] ;
let _contract : { [ key : string ] : any } = {
_contract : { } ,
_provider : null
} ;
let _contract : { [ key : string ] : any } = {
_contract : { } ,
_provider : null
} ;
if ( window . ethereum ) {
account = await window . ethereum . request ( {
method : 'eth_accounts'
} ) ;
chainId = ethers . toNumber ( await window . ethereum . request ( {
method : 'eth_chainId'
} ) )
}
if ( window . ethereum ) {
account = await window . ethereum . request ( {
method : 'eth_accounts'
} ) ;
chainId = ethers . toNumber ( await window . ethereum . request ( {
method : 'eth_chainId'
} ) )
}
if ( ! config [ chainId ] ) {
chainId = Number ( process . env . REACT_APP_CHAINID )
} ;
if ( ! config [ chainId ] ) {
chainId = Number ( process . env . REACT_APP_CHAINID )
} ;
const contractAddress = config [ chainId ] ;
let _provider = null as any ;
const contractAddress = config [ chainId ] ;
let _provider = null as any ;
if ( account . length <= 0 ) {
_provider = new ethers . JsonRpcProvider ( contractAddress . rpc )
} else {
_provider = await new ethers . BrowserProvider ( window . ethereum ) . getSigner ( )
}
if ( account . length <= 0 ) {
_provider = new ethers . JsonRpcProvider ( contractAddress . rpc )
} else {
_provider = await new ethers . BrowserProvider ( window . ethereum ) . getSigner ( )
}
_contract . _provider = _provider ;
_contract . _provider = _provider ;
Object . keys ( contractAddress . address ) . forEach ( ( item ) = > {
_contract . _contract [ item ] = contractObj [ item ] . connect ( contractAddress . address [ item ] , _provider ) ;
} )
store . setContract ( _contract as ContractType ) ;
} catch ( error ) {
Object . keys ( contractAddress . address ) . forEach ( ( item ) = > {
_contract . _contract [ item ] = contractObj [ item ] . connect ( contractAddress . address [ item ] , _provider ) ;
} )
store . setContract ( _contract as ContractType ) ;
}
}
}