mirror of
https://github.com/oceanprotocol/react.git
synced 2025-02-14 21:10:38 +01:00
removed unnecessary code
This commit is contained in:
parent
93177c08cb
commit
2dda6edf81
16759
package-lock.json
generated
16759
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -33,26 +33,38 @@ interface OceanProviderValue {
|
|||||||
balance: Balance
|
balance: Balance
|
||||||
networkId: number | undefined
|
networkId: number | undefined
|
||||||
status: ProviderStatus
|
status: ProviderStatus
|
||||||
connect: (config?: Config) => Promise<void>
|
createOcean: (config?: Config) => Promise<void>
|
||||||
refreshBalance: () => Promise<void>
|
refreshBalance: () => Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
const OceanContext = createContext({} as OceanProviderValue)
|
const OceanContext = createContext({} as OceanProviderValue)
|
||||||
|
|
||||||
function OceanProvider({ initialConfig, children }: {
|
function OceanProvider({
|
||||||
|
initialConfig,
|
||||||
|
web3Provider,
|
||||||
|
children
|
||||||
|
}: {
|
||||||
initialConfig: Config | ConfigHelperConfig
|
initialConfig: Config | ConfigHelperConfig
|
||||||
|
web3Provider: Web3
|
||||||
children: ReactNode
|
children: ReactNode
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const [ocean, setOcean] = useState<Ocean | undefined>()
|
const [ocean, setOcean] = useState<Ocean | undefined>()
|
||||||
const [account, setAccount] = useState<Account | undefined>()
|
const [account, setAccount] = useState<Account | undefined>()
|
||||||
const [accountId, setAccountId] = useState<string | undefined>()
|
const [accountId, setAccountId] = useState<string | undefined>()
|
||||||
const [networkId, setNetworkId] = useState<number | undefined>()
|
const [networkId, setNetworkId] = useState<number | undefined>()
|
||||||
const [balance, setBalance] = useState<Balance | undefined>({ eth: undefined, ocean: undefined });
|
const [balance, setBalance] = useState<Balance | undefined>({
|
||||||
|
eth: undefined,
|
||||||
|
ocean: undefined
|
||||||
|
})
|
||||||
|
|
||||||
const [isInPurgatory, setIsInPurgatory] = useState(false)
|
const [isInPurgatory, setIsInPurgatory] = useState(false)
|
||||||
const [purgatoryData, setPurgatoryData] = useState<AccountPurgatoryData>()
|
const [purgatoryData, setPurgatoryData] = useState<AccountPurgatoryData>()
|
||||||
const [config, setConfig] = useState<Config | ConfigHelperConfig>(initialConfig)
|
const [config, setConfig] = useState<Config | ConfigHelperConfig>(
|
||||||
const [status, setStatus] = useState<ProviderStatus>(ProviderStatus.NOT_AVAILABLE)
|
initialConfig
|
||||||
|
)
|
||||||
|
const [status, setStatus] = useState<ProviderStatus>(
|
||||||
|
ProviderStatus.NOT_AVAILABLE
|
||||||
|
)
|
||||||
|
|
||||||
const setPurgatory = useCallback(async (address: string): Promise<void> => {
|
const setPurgatory = useCallback(async (address: string): Promise<void> => {
|
||||||
if (!address) return
|
if (!address) return
|
||||||
@ -73,15 +85,14 @@ function OceanProvider({ initialConfig, children }: {
|
|||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const connect = useCallback(
|
const createOcean = useCallback(
|
||||||
async (newConfig?: Config | ConfigHelperConfig) => {
|
async (newConfig?: Config | ConfigHelperConfig) => {
|
||||||
try {
|
try {
|
||||||
Logger.log('Connecting ...', newConfig)
|
Logger.log('Connecting ...', newConfig)
|
||||||
|
|
||||||
newConfig && setConfig(newConfig)
|
newConfig && setConfig(newConfig)
|
||||||
|
|
||||||
// ========
|
// ========
|
||||||
// config.web3Provider = web3
|
config.web3Provider = web3Provider
|
||||||
const ocean = await Ocean.getInstance(config)
|
const ocean = await Ocean.getInstance(config)
|
||||||
setOcean(ocean)
|
setOcean(ocean)
|
||||||
Logger.log('Ocean instance created.', ocean)
|
Logger.log('Ocean instance created.', ocean)
|
||||||
@ -93,23 +104,20 @@ function OceanProvider({ initialConfig, children }: {
|
|||||||
// setNetworkId(networkId)
|
// setNetworkId(networkId)
|
||||||
// Logger.log('network id ', networkId)
|
// Logger.log('network id ', networkId)
|
||||||
|
|
||||||
// ACCOUNT
|
// Account
|
||||||
|
const account = (await ocean.accounts.list())[0]
|
||||||
|
setAccount(account)
|
||||||
|
Logger.log('Account ', account)
|
||||||
|
|
||||||
// const account = (await ocean.accounts.list())[0]
|
// Account Id
|
||||||
// setAccount(account)
|
const accountId = await getAccountId(web3Provider)
|
||||||
// Logger.log('Account ', account)
|
setAccountId(accountId)
|
||||||
|
Logger.log('account id', accountId)
|
||||||
|
|
||||||
// ACCOUNT ID
|
// Balance
|
||||||
|
const balance = await getBalance(account)
|
||||||
// const accountId = await getAccountId(web3)
|
setBalance(balance)
|
||||||
// setAccountId(accountId)
|
Logger.log('balance', JSON.stringify(balance))
|
||||||
// Logger.log('account id', accountId)
|
|
||||||
|
|
||||||
// BALANCE
|
|
||||||
|
|
||||||
// const balance = await getBalance(account)
|
|
||||||
// setBalance(balance)
|
|
||||||
// Logger.log('balance', JSON.stringify(balance))
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Logger.error(error)
|
Logger.error(error)
|
||||||
}
|
}
|
||||||
@ -141,7 +149,7 @@ function OceanProvider({ initialConfig, children }: {
|
|||||||
purgatoryData,
|
purgatoryData,
|
||||||
status,
|
status,
|
||||||
config,
|
config,
|
||||||
connect,
|
createOcean,
|
||||||
refreshBalance
|
refreshBalance
|
||||||
} as OceanProviderValue
|
} as OceanProviderValue
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user