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",
|
"@coingecko/cryptoformat": "^0.5.4",
|
||||||
"@loadable/component": "^5.15.2",
|
"@loadable/component": "^5.15.2",
|
||||||
"@oceanprotocol/art": "^3.2.0",
|
"@oceanprotocol/art": "^3.2.0",
|
||||||
"@oceanprotocol/lib": "^3.0.0",
|
"@oceanprotocol/lib": "^3.0.1",
|
||||||
"@oceanprotocol/typographies": "^0.1.0",
|
"@oceanprotocol/typographies": "^0.1.0",
|
||||||
"@oceanprotocol/use-dark-mode": "^2.4.3",
|
"@oceanprotocol/use-dark-mode": "^2.4.3",
|
||||||
"@orbisclub/orbis-sdk": "^0.4.40",
|
"@orbisclub/orbis-sdk": "^0.4.40",
|
||||||
@ -6057,9 +6057,9 @@
|
|||||||
"integrity": "sha512-I6xoADZpP/8EyN3VWZ+dLYv24DbJj3xzmSDcYv0FolXeAUF3FluzminL5AgQtAaoyUtlHl1D3ij1B++KupWcQQ=="
|
"integrity": "sha512-I6xoADZpP/8EyN3VWZ+dLYv24DbJj3xzmSDcYv0FolXeAUF3FluzminL5AgQtAaoyUtlHl1D3ij1B++KupWcQQ=="
|
||||||
},
|
},
|
||||||
"node_modules/@oceanprotocol/lib": {
|
"node_modules/@oceanprotocol/lib": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-3.0.1.tgz",
|
||||||
"integrity": "sha512-clhhMoRsxTYiPmSWg+KS4HBiT5Du0NJXCoIO5qNKK0cGlWpI1fPtcbVKro2J44z67kY/i8dScY7AIl+jVcJ6yQ==",
|
"integrity": "sha512-9GPwQ5SBv4tej6YfrNmZpCnQPte6kinU3U7jPCdFAAVCpRc+IuQymu0/PfzYb1yo3GrMyGsp3ht6wjZDhy37QA==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@oceanprotocol/contracts": "^1.1.8",
|
"@oceanprotocol/contracts": "^1.1.8",
|
||||||
"cross-fetch": "^3.1.5",
|
"cross-fetch": "^3.1.5",
|
||||||
@ -58419,9 +58419,9 @@
|
|||||||
"integrity": "sha512-I6xoADZpP/8EyN3VWZ+dLYv24DbJj3xzmSDcYv0FolXeAUF3FluzminL5AgQtAaoyUtlHl1D3ij1B++KupWcQQ=="
|
"integrity": "sha512-I6xoADZpP/8EyN3VWZ+dLYv24DbJj3xzmSDcYv0FolXeAUF3FluzminL5AgQtAaoyUtlHl1D3ij1B++KupWcQQ=="
|
||||||
},
|
},
|
||||||
"@oceanprotocol/lib": {
|
"@oceanprotocol/lib": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-3.0.1.tgz",
|
||||||
"integrity": "sha512-clhhMoRsxTYiPmSWg+KS4HBiT5Du0NJXCoIO5qNKK0cGlWpI1fPtcbVKro2J44z67kY/i8dScY7AIl+jVcJ6yQ==",
|
"integrity": "sha512-9GPwQ5SBv4tej6YfrNmZpCnQPte6kinU3U7jPCdFAAVCpRc+IuQymu0/PfzYb1yo3GrMyGsp3ht6wjZDhy37QA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@oceanprotocol/contracts": "^1.1.8",
|
"@oceanprotocol/contracts": "^1.1.8",
|
||||||
"cross-fetch": "^3.1.5",
|
"cross-fetch": "^3.1.5",
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
"@coingecko/cryptoformat": "^0.5.4",
|
"@coingecko/cryptoformat": "^0.5.4",
|
||||||
"@loadable/component": "^5.15.2",
|
"@loadable/component": "^5.15.2",
|
||||||
"@oceanprotocol/art": "^3.2.0",
|
"@oceanprotocol/art": "^3.2.0",
|
||||||
"@oceanprotocol/lib": "^3.0.0",
|
"@oceanprotocol/lib": "^3.0.1",
|
||||||
"@oceanprotocol/typographies": "^0.1.0",
|
"@oceanprotocol/typographies": "^0.1.0",
|
||||||
"@oceanprotocol/use-dark-mode": "^2.4.3",
|
"@oceanprotocol/use-dark-mode": "^2.4.3",
|
||||||
"@orbisclub/orbis-sdk": "^0.4.40",
|
"@orbisclub/orbis-sdk": "^0.4.40",
|
||||||
|
@ -160,7 +160,7 @@ function getAccessDetailsFromTokenPrice(
|
|||||||
export async function getOrderPriceAndFees(
|
export async function getOrderPriceAndFees(
|
||||||
asset: AssetExtended,
|
asset: AssetExtended,
|
||||||
accountId: string,
|
accountId: string,
|
||||||
signer: Signer,
|
signer?: Signer,
|
||||||
providerFees?: ProviderFees
|
providerFees?: ProviderFees
|
||||||
): Promise<OrderPriceAndFees> {
|
): Promise<OrderPriceAndFees> {
|
||||||
const orderPriceAndFee = {
|
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 abiFre from '@oceanprotocol/contracts/artifacts/contracts/pools/fixedRate/FixedRateExchange.sol/FixedRateExchange.json'
|
||||||
import { getOceanConfig } from '.'
|
import { getOceanConfig } from '.'
|
||||||
import { consumeMarketFixedSwapFee } from '../../../app.config'
|
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
|
* 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(
|
export async function getFixedBuyPrice(
|
||||||
accessDetails: AccessDetails,
|
accessDetails: AccessDetails,
|
||||||
chainId: number,
|
chainId?: number,
|
||||||
provider: Signer
|
signer?: Signer
|
||||||
): Promise<PriceAndFees> {
|
): Promise<PriceAndFees> {
|
||||||
const config = getOceanConfig(chainId)
|
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(
|
const estimatedPrice = await fixed.calcBaseInGivenDatatokensOut(
|
||||||
accessDetails.addressOrId,
|
accessDetails.addressOrId,
|
||||||
'1',
|
'1',
|
||||||
|
@ -1,13 +1,30 @@
|
|||||||
import { LoggerInstance } from '@oceanprotocol/lib'
|
import { LoggerInstance } from '@oceanprotocol/lib'
|
||||||
import { createClient, erc20ABI } from 'wagmi'
|
import { createClient, erc20ABI } from 'wagmi'
|
||||||
import { mainnet, polygon, bsc, goerli, polygonMumbai } from 'wagmi/chains'
|
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 { formatEther } from 'ethers/lib/utils'
|
||||||
import { getDefaultClient } from 'connectkit'
|
import { getDefaultClient } from 'connectkit'
|
||||||
import { energyWeb, moonriver } from './chains'
|
import { energyWeb, moonriver } from './chains'
|
||||||
import { getNetworkDisplayName } from '@hooks/useNetworkMetadata'
|
import { getNetworkDisplayName } from '@hooks/useNetworkMetadata'
|
||||||
import { getOceanConfig } from '../ocean'
|
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
|
// Wagmi client
|
||||||
export const wagmiClient = createClient(
|
export const wagmiClient = createClient(
|
||||||
getDefaultClient({
|
getDefaultClient({
|
||||||
|
@ -46,6 +46,9 @@ import { getComputeFeedback } from '@utils/feedback'
|
|||||||
import { initializeProviderForCompute } from '@utils/provider'
|
import { initializeProviderForCompute } from '@utils/provider'
|
||||||
import { useUserPreferences } from '@context/UserPreferences'
|
import { useUserPreferences } from '@context/UserPreferences'
|
||||||
import { useAccount, useSigner } from 'wagmi'
|
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.
|
const refreshInterval = 10000 // 10 sec.
|
||||||
|
|
||||||
@ -103,6 +106,8 @@ export default function Compute({
|
|||||||
const [isLoadingJobs, setIsLoadingJobs] = useState(false)
|
const [isLoadingJobs, setIsLoadingJobs] = useState(false)
|
||||||
const [jobs, setJobs] = useState<ComputeJobMetaData[]>([])
|
const [jobs, setJobs] = useState<ComputeJobMetaData[]>([])
|
||||||
const [retry, setRetry] = useState<boolean>(false)
|
const [retry, setRetry] = useState<boolean>(false)
|
||||||
|
const { isSupportedOceanNetwork } = useNetworkMetadata()
|
||||||
|
const { isAssetNetwork } = useAsset()
|
||||||
|
|
||||||
const hasDatatoken = Number(dtBalance) >= 1
|
const hasDatatoken = Number(dtBalance) >= 1
|
||||||
const isComputeButtonDisabled =
|
const isComputeButtonDisabled =
|
||||||
@ -117,7 +122,8 @@ export default function Compute({
|
|||||||
|
|
||||||
async function checkAssetDTBalance(asset: DDO) {
|
async function checkAssetDTBalance(asset: DDO) {
|
||||||
if (!asset?.services[0].datatokenAddress) return
|
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(
|
const dtBalance = await datatokenInstance.balance(
|
||||||
asset?.services[0].datatokenAddress,
|
asset?.services[0].datatokenAddress,
|
||||||
accountId || ZERO_ADDRESS // if the user is not connected, we use ZERO_ADDRESS as accountId
|
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 feeValidity = providerData?.datasets?.[0]?.providerFee?.validUntil
|
||||||
|
|
||||||
const feeAmount = await unitsToAmount(
|
const feeAmount = await unitsToAmount(
|
||||||
// !isSupportedOceanNetwork || !isAssetNetwork
|
!isSupportedOceanNetwork || !isAssetNetwork
|
||||||
// ? await getDummyWeb3(asset?.chainId)
|
? await getDummySigner(asset?.chainId)
|
||||||
// : web3,
|
: signer,
|
||||||
signer,
|
|
||||||
providerFeeToken,
|
providerFeeToken,
|
||||||
providerFeeAmount
|
providerFeeAmount
|
||||||
)
|
)
|
||||||
setProviderFeeAmount(feeAmount)
|
setProviderFeeAmount(feeAmount)
|
||||||
|
|
||||||
const datatoken = new Datatoken(signer)
|
const datatoken = new Datatoken(await getDummySigner(asset?.chainId))
|
||||||
// const datatoken = new Datatoken(
|
|
||||||
// await getDummyWeb3(asset?.chainId),
|
|
||||||
// null,
|
|
||||||
// null,
|
|
||||||
// minAbi
|
|
||||||
// )
|
|
||||||
setProviderFeesSymbol(await datatoken.getSymbol(providerFeeToken))
|
setProviderFeesSymbol(await datatoken.getSymbol(providerFeeToken))
|
||||||
|
|
||||||
const computeDuration = asset.accessDetails.validProviderFees
|
const computeDuration = asset.accessDetails.validProviderFees
|
||||||
|
@ -84,8 +84,7 @@ export default function Download({
|
|||||||
|
|
||||||
const _orderPriceAndFees = await getOrderPriceAndFees(
|
const _orderPriceAndFees = await getOrderPriceAndFees(
|
||||||
asset,
|
asset,
|
||||||
ZERO_ADDRESS,
|
ZERO_ADDRESS
|
||||||
signer
|
|
||||||
)
|
)
|
||||||
setOrderPriceAndFees(_orderPriceAndFees)
|
setOrderPriceAndFees(_orderPriceAndFees)
|
||||||
!orderPriceAndFees && setIsPriceLoading(false)
|
!orderPriceAndFees && setIsPriceLoading(false)
|
||||||
|
@ -3,26 +3,26 @@ import MetaItem from './MetaItem'
|
|||||||
import styles from './MetaFull.module.css'
|
import styles from './MetaFull.module.css'
|
||||||
import Publisher from '@shared/Publisher'
|
import Publisher from '@shared/Publisher'
|
||||||
import { useAsset } from '@context/Asset'
|
import { useAsset } from '@context/Asset'
|
||||||
import { Asset, LoggerInstance } from '@oceanprotocol/lib'
|
import { Asset, LoggerInstance, Datatoken } from '@oceanprotocol/lib'
|
||||||
import { getPaymentCollector } from '@utils/ocean'
|
import { getPaymentCollector } from '@utils/ocean'
|
||||||
import { useProvider } from 'wagmi'
|
import { useProvider } from 'wagmi'
|
||||||
|
import { getDummySigner } from '@utils/wallet'
|
||||||
|
|
||||||
export default function MetaFull({ ddo }: { ddo: Asset }): ReactElement {
|
export default function MetaFull({ ddo }: { ddo: Asset }): ReactElement {
|
||||||
const { isInPurgatory, assetState } = useAsset()
|
const { isInPurgatory, assetState } = useAsset()
|
||||||
const provider = useProvider()
|
|
||||||
|
|
||||||
const [paymentCollector, setPaymentCollector] = useState<string>()
|
const [paymentCollector, setPaymentCollector] = useState<string>()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!ddo || !provider) return
|
if (!ddo) return
|
||||||
|
|
||||||
async function getInitialPaymentCollector() {
|
async function getInitialPaymentCollector() {
|
||||||
try {
|
try {
|
||||||
const paymentCollector = await getPaymentCollector(
|
const signer = await getDummySigner(ddo.chainId)
|
||||||
ddo.datatokens[0].address,
|
const datatoken = new Datatoken(signer)
|
||||||
provider
|
setPaymentCollector(
|
||||||
|
await datatoken.getPaymentCollector(ddo.datatokens[0].address)
|
||||||
)
|
)
|
||||||
setPaymentCollector(paymentCollector)
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
LoggerInstance.error(
|
LoggerInstance.error(
|
||||||
'[MetaFull: getInitialPaymentCollector]',
|
'[MetaFull: getInitialPaymentCollector]',
|
||||||
@ -31,7 +31,7 @@ export default function MetaFull({ ddo }: { ddo: Asset }): ReactElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
getInitialPaymentCollector()
|
getInitialPaymentCollector()
|
||||||
}, [ddo, provider])
|
}, [ddo])
|
||||||
|
|
||||||
function DockerImage() {
|
function DockerImage() {
|
||||||
const containerInfo = ddo?.metadata?.algorithm?.container
|
const containerInfo = ddo?.metadata?.algorithm?.container
|
||||||
|
Loading…
Reference in New Issue
Block a user