mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
Fix/ Wallet issues (#1925)
* added get dummy signer method * more dummy signer fixes * bump to ocean lib 3.0.1-next0 * fix getDummySigner method * use ocean js lib 3.0.1
This commit is contained in:
parent
165a9b0fb3
commit
77d122d223
14
package-lock.json
generated
14
package-lock.json
generated
@ -15,7 +15,7 @@
|
||||
"@coingecko/cryptoformat": "^0.5.4",
|
||||
"@loadable/component": "^5.15.2",
|
||||
"@oceanprotocol/art": "^3.2.0",
|
||||
"@oceanprotocol/lib": "^3.0.0",
|
||||
"@oceanprotocol/lib": "^3.0.1",
|
||||
"@oceanprotocol/typographies": "^0.1.0",
|
||||
"@oceanprotocol/use-dark-mode": "^2.4.3",
|
||||
"@orbisclub/orbis-sdk": "^0.4.40",
|
||||
@ -6057,9 +6057,9 @@
|
||||
"integrity": "sha512-I6xoADZpP/8EyN3VWZ+dLYv24DbJj3xzmSDcYv0FolXeAUF3FluzminL5AgQtAaoyUtlHl1D3ij1B++KupWcQQ=="
|
||||
},
|
||||
"node_modules/@oceanprotocol/lib": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-3.0.0.tgz",
|
||||
"integrity": "sha512-clhhMoRsxTYiPmSWg+KS4HBiT5Du0NJXCoIO5qNKK0cGlWpI1fPtcbVKro2J44z67kY/i8dScY7AIl+jVcJ6yQ==",
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-3.0.1.tgz",
|
||||
"integrity": "sha512-9GPwQ5SBv4tej6YfrNmZpCnQPte6kinU3U7jPCdFAAVCpRc+IuQymu0/PfzYb1yo3GrMyGsp3ht6wjZDhy37QA==",
|
||||
"dependencies": {
|
||||
"@oceanprotocol/contracts": "^1.1.8",
|
||||
"cross-fetch": "^3.1.5",
|
||||
@ -58419,9 +58419,9 @@
|
||||
"integrity": "sha512-I6xoADZpP/8EyN3VWZ+dLYv24DbJj3xzmSDcYv0FolXeAUF3FluzminL5AgQtAaoyUtlHl1D3ij1B++KupWcQQ=="
|
||||
},
|
||||
"@oceanprotocol/lib": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-3.0.0.tgz",
|
||||
"integrity": "sha512-clhhMoRsxTYiPmSWg+KS4HBiT5Du0NJXCoIO5qNKK0cGlWpI1fPtcbVKro2J44z67kY/i8dScY7AIl+jVcJ6yQ==",
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-3.0.1.tgz",
|
||||
"integrity": "sha512-9GPwQ5SBv4tej6YfrNmZpCnQPte6kinU3U7jPCdFAAVCpRc+IuQymu0/PfzYb1yo3GrMyGsp3ht6wjZDhy37QA==",
|
||||
"requires": {
|
||||
"@oceanprotocol/contracts": "^1.1.8",
|
||||
"cross-fetch": "^3.1.5",
|
||||
|
@ -29,7 +29,7 @@
|
||||
"@coingecko/cryptoformat": "^0.5.4",
|
||||
"@loadable/component": "^5.15.2",
|
||||
"@oceanprotocol/art": "^3.2.0",
|
||||
"@oceanprotocol/lib": "^3.0.0",
|
||||
"@oceanprotocol/lib": "^3.0.1",
|
||||
"@oceanprotocol/typographies": "^0.1.0",
|
||||
"@oceanprotocol/use-dark-mode": "^2.4.3",
|
||||
"@orbisclub/orbis-sdk": "^0.4.40",
|
||||
|
@ -160,7 +160,7 @@ function getAccessDetailsFromTokenPrice(
|
||||
export async function getOrderPriceAndFees(
|
||||
asset: AssetExtended,
|
||||
accountId: string,
|
||||
signer: Signer,
|
||||
signer?: Signer,
|
||||
providerFees?: ProviderFees
|
||||
): Promise<OrderPriceAndFees> {
|
||||
const orderPriceAndFee = {
|
||||
|
@ -8,18 +8,26 @@ import { ethers, Signer } from 'ethers'
|
||||
import abiFre from '@oceanprotocol/contracts/artifacts/contracts/pools/fixedRate/FixedRateExchange.sol/FixedRateExchange.json'
|
||||
import { getOceanConfig } from '.'
|
||||
import { consumeMarketFixedSwapFee } from '../../../app.config'
|
||||
import { getDummySigner } from '@utils/wallet'
|
||||
|
||||
/**
|
||||
* This is used to calculate the price to buy one datatoken from a fixed rate exchange. You need to pass either a web3 object or a chainId. If you pass a chainId a dummy web3 object will be created
|
||||
*/
|
||||
export async function getFixedBuyPrice(
|
||||
accessDetails: AccessDetails,
|
||||
chainId: number,
|
||||
provider: Signer
|
||||
chainId?: number,
|
||||
signer?: Signer
|
||||
): Promise<PriceAndFees> {
|
||||
const config = getOceanConfig(chainId)
|
||||
|
||||
const fixed = new FixedRateExchange(config.fixedRateExchangeAddress, provider)
|
||||
if (!signer && !chainId)
|
||||
throw new Error("web3 and chainId can't be undefined at the same time!")
|
||||
|
||||
if (!signer) {
|
||||
signer = await getDummySigner(chainId)
|
||||
}
|
||||
|
||||
const fixed = new FixedRateExchange(config.fixedRateExchangeAddress, signer)
|
||||
const estimatedPrice = await fixed.calcBaseInGivenDatatokensOut(
|
||||
accessDetails.addressOrId,
|
||||
'1',
|
||||
|
@ -1,13 +1,30 @@
|
||||
import { LoggerInstance } from '@oceanprotocol/lib'
|
||||
import { createClient, erc20ABI } from 'wagmi'
|
||||
import { mainnet, polygon, bsc, goerli, polygonMumbai } from 'wagmi/chains'
|
||||
import { ethers, Contract } from 'ethers'
|
||||
import { ethers, Contract, Signer, providers } from 'ethers'
|
||||
import { formatEther } from 'ethers/lib/utils'
|
||||
import { getDefaultClient } from 'connectkit'
|
||||
import { energyWeb, moonriver } from './chains'
|
||||
import { getNetworkDisplayName } from '@hooks/useNetworkMetadata'
|
||||
import { getOceanConfig } from '../ocean'
|
||||
|
||||
export async function getDummySigner(chainId: number): Promise<Signer> {
|
||||
if (typeof chainId !== 'number') {
|
||||
throw new Error('Chain ID must be a number')
|
||||
}
|
||||
|
||||
// Get config from ocean lib
|
||||
const config = getOceanConfig(chainId)
|
||||
try {
|
||||
const privateKey =
|
||||
'0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
|
||||
const provider = new ethers.providers.JsonRpcProvider(config.nodeUri)
|
||||
return new ethers.Wallet(privateKey, provider)
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to create dummy signer: ${error.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
// Wagmi client
|
||||
export const wagmiClient = createClient(
|
||||
getDefaultClient({
|
||||
|
@ -46,6 +46,9 @@ import { getComputeFeedback } from '@utils/feedback'
|
||||
import { initializeProviderForCompute } from '@utils/provider'
|
||||
import { useUserPreferences } from '@context/UserPreferences'
|
||||
import { useAccount, useSigner } from 'wagmi'
|
||||
import { getDummySigner } from '@utils/wallet'
|
||||
import useNetworkMetadata from '@hooks/useNetworkMetadata'
|
||||
import { useAsset } from '@context/Asset'
|
||||
|
||||
const refreshInterval = 10000 // 10 sec.
|
||||
|
||||
@ -103,6 +106,8 @@ export default function Compute({
|
||||
const [isLoadingJobs, setIsLoadingJobs] = useState(false)
|
||||
const [jobs, setJobs] = useState<ComputeJobMetaData[]>([])
|
||||
const [retry, setRetry] = useState<boolean>(false)
|
||||
const { isSupportedOceanNetwork } = useNetworkMetadata()
|
||||
const { isAssetNetwork } = useAsset()
|
||||
|
||||
const hasDatatoken = Number(dtBalance) >= 1
|
||||
const isComputeButtonDisabled =
|
||||
@ -117,7 +122,8 @@ export default function Compute({
|
||||
|
||||
async function checkAssetDTBalance(asset: DDO) {
|
||||
if (!asset?.services[0].datatokenAddress) return
|
||||
const datatokenInstance = new Datatoken(signer)
|
||||
const dummySigner = await getDummySigner(asset?.chainId)
|
||||
const datatokenInstance = new Datatoken(dummySigner)
|
||||
const dtBalance = await datatokenInstance.balance(
|
||||
asset?.services[0].datatokenAddress,
|
||||
accountId || ZERO_ADDRESS // if the user is not connected, we use ZERO_ADDRESS as accountId
|
||||
@ -142,22 +148,15 @@ export default function Compute({
|
||||
const feeValidity = providerData?.datasets?.[0]?.providerFee?.validUntil
|
||||
|
||||
const feeAmount = await unitsToAmount(
|
||||
// !isSupportedOceanNetwork || !isAssetNetwork
|
||||
// ? await getDummyWeb3(asset?.chainId)
|
||||
// : web3,
|
||||
signer,
|
||||
!isSupportedOceanNetwork || !isAssetNetwork
|
||||
? await getDummySigner(asset?.chainId)
|
||||
: signer,
|
||||
providerFeeToken,
|
||||
providerFeeAmount
|
||||
)
|
||||
setProviderFeeAmount(feeAmount)
|
||||
|
||||
const datatoken = new Datatoken(signer)
|
||||
// const datatoken = new Datatoken(
|
||||
// await getDummyWeb3(asset?.chainId),
|
||||
// null,
|
||||
// null,
|
||||
// minAbi
|
||||
// )
|
||||
const datatoken = new Datatoken(await getDummySigner(asset?.chainId))
|
||||
setProviderFeesSymbol(await datatoken.getSymbol(providerFeeToken))
|
||||
|
||||
const computeDuration = asset.accessDetails.validProviderFees
|
||||
|
@ -84,8 +84,7 @@ export default function Download({
|
||||
|
||||
const _orderPriceAndFees = await getOrderPriceAndFees(
|
||||
asset,
|
||||
ZERO_ADDRESS,
|
||||
signer
|
||||
ZERO_ADDRESS
|
||||
)
|
||||
setOrderPriceAndFees(_orderPriceAndFees)
|
||||
!orderPriceAndFees && setIsPriceLoading(false)
|
||||
|
@ -3,26 +3,26 @@ import MetaItem from './MetaItem'
|
||||
import styles from './MetaFull.module.css'
|
||||
import Publisher from '@shared/Publisher'
|
||||
import { useAsset } from '@context/Asset'
|
||||
import { Asset, LoggerInstance } from '@oceanprotocol/lib'
|
||||
import { Asset, LoggerInstance, Datatoken } from '@oceanprotocol/lib'
|
||||
import { getPaymentCollector } from '@utils/ocean'
|
||||
import { useProvider } from 'wagmi'
|
||||
import { getDummySigner } from '@utils/wallet'
|
||||
|
||||
export default function MetaFull({ ddo }: { ddo: Asset }): ReactElement {
|
||||
const { isInPurgatory, assetState } = useAsset()
|
||||
const provider = useProvider()
|
||||
|
||||
const [paymentCollector, setPaymentCollector] = useState<string>()
|
||||
|
||||
useEffect(() => {
|
||||
if (!ddo || !provider) return
|
||||
if (!ddo) return
|
||||
|
||||
async function getInitialPaymentCollector() {
|
||||
try {
|
||||
const paymentCollector = await getPaymentCollector(
|
||||
ddo.datatokens[0].address,
|
||||
provider
|
||||
const signer = await getDummySigner(ddo.chainId)
|
||||
const datatoken = new Datatoken(signer)
|
||||
setPaymentCollector(
|
||||
await datatoken.getPaymentCollector(ddo.datatokens[0].address)
|
||||
)
|
||||
setPaymentCollector(paymentCollector)
|
||||
} catch (error) {
|
||||
LoggerInstance.error(
|
||||
'[MetaFull: getInitialPaymentCollector]',
|
||||
@ -31,7 +31,7 @@ export default function MetaFull({ ddo }: { ddo: Asset }): ReactElement {
|
||||
}
|
||||
}
|
||||
getInitialPaymentCollector()
|
||||
}, [ddo, provider])
|
||||
}, [ddo])
|
||||
|
||||
function DockerImage() {
|
||||
const containerInfo = ddo?.metadata?.algorithm?.container
|
||||
|
Loading…
Reference in New Issue
Block a user