2021-06-25 09:50:56 +02:00
|
|
|
import { gql, OperationResult, TypedDocumentNode, OperationContext } from 'urql'
|
2021-11-11 08:51:13 +01:00
|
|
|
import { Logger } from '@oceanprotocol/lib'
|
2021-10-13 18:48:59 +02:00
|
|
|
import { getUrqlClientInstance } from '@context/UrqlProvider'
|
2021-06-25 09:50:56 +02:00
|
|
|
import { getOceanConfig } from './ocean'
|
2021-07-09 10:36:43 +02:00
|
|
|
import {
|
|
|
|
AssetsPoolPrice,
|
2021-09-01 17:48:54 +02:00
|
|
|
AssetsPoolPrice_pools as AssetsPoolPricePool
|
2021-07-09 10:36:43 +02:00
|
|
|
} from '../@types/apollo/AssetsPoolPrice'
|
|
|
|
import {
|
|
|
|
AssetsFrePrice,
|
2021-09-01 17:48:54 +02:00
|
|
|
AssetsFrePrice_fixedRateExchanges as AssetsFrePriceFixedRateExchange
|
2021-07-09 10:36:43 +02:00
|
|
|
} from '../@types/apollo/AssetsFrePrice'
|
|
|
|
import {
|
|
|
|
AssetsFreePrice,
|
|
|
|
AssetsFreePrice_dispensers as AssetFreePriceDispenser
|
|
|
|
} from '../@types/apollo/AssetsFreePrice'
|
2021-07-06 00:09:51 +02:00
|
|
|
import { AssetPreviousOrder } from '../@types/apollo/AssetPreviousOrder'
|
2021-07-15 17:25:53 +02:00
|
|
|
import {
|
2021-09-01 17:48:54 +02:00
|
|
|
HighestLiquidityAssets_pools as HighestLiquidityAssetsPool,
|
2021-07-15 17:25:53 +02:00
|
|
|
HighestLiquidityAssets as HighestLiquidityGraphAssets
|
|
|
|
} from '../@types/apollo/HighestLiquidityAssets'
|
Account metadata header (#776)
* get all neded data for the header from 3box, aqua and subgraph
* fix tvl display error
* WIP metadata header styling
* added more styling for the header
* make page title optional so we can remove it on account page
* stroke change for svg images and default values
* more styling added to the header
* fixed linter
* added ocean balance to tvl
* update styling for statistcs
* fixed eror for go to my account from another account page
* updated styling for mobile use
* wip show more on explorer links and description
* properly display read more for explorer links and description
* replaced show more with 3box redirect on description
* change accounts default picture and check links length before display element
* use optional on links
* grid cleanup, new number unit, split up stats
* rename all the things, more profile header styling
* visual hierarchy, improve image loading experience
* layout flow & visual tweaks
* more description
* replaced account route with profile when accesing a profile by the eth address
* use account id from url if exists when fetching data
* bump @oceanprotocol/art to v3.2.0
* styling, fallbacks, edge case fixes
* clean up Publisher atom, link to profile page
* fixed issue when switching to my profile from another profile
* output accountId, make it copyable, remove stats icons
* render tweaks, markup cleanup
* add 3box reference
* mobile tabs spacing tweaks
* text flow and spacing tweaks
Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
2021-09-01 13:56:34 +02:00
|
|
|
import {
|
|
|
|
PoolShares as PoolSharesList,
|
|
|
|
PoolShares_poolShares as PoolShare
|
|
|
|
} from '../@types/apollo/PoolShares'
|
2021-09-13 16:39:32 +02:00
|
|
|
import { OrdersData_tokenOrders as OrdersData } from '../@types/apollo/OrdersData'
|
Account metadata header (#776)
* get all neded data for the header from 3box, aqua and subgraph
* fix tvl display error
* WIP metadata header styling
* added more styling for the header
* make page title optional so we can remove it on account page
* stroke change for svg images and default values
* more styling added to the header
* fixed linter
* added ocean balance to tvl
* update styling for statistcs
* fixed eror for go to my account from another account page
* updated styling for mobile use
* wip show more on explorer links and description
* properly display read more for explorer links and description
* replaced show more with 3box redirect on description
* change accounts default picture and check links length before display element
* use optional on links
* grid cleanup, new number unit, split up stats
* rename all the things, more profile header styling
* visual hierarchy, improve image loading experience
* layout flow & visual tweaks
* more description
* replaced account route with profile when accesing a profile by the eth address
* use account id from url if exists when fetching data
* bump @oceanprotocol/art to v3.2.0
* styling, fallbacks, edge case fixes
* clean up Publisher atom, link to profile page
* fixed issue when switching to my profile from another profile
* output accountId, make it copyable, remove stats icons
* render tweaks, markup cleanup
* add 3box reference
* mobile tabs spacing tweaks
* text flow and spacing tweaks
Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
2021-09-01 13:56:34 +02:00
|
|
|
|
2021-09-13 16:39:32 +02:00
|
|
|
export interface UserLiquidity {
|
Account metadata header (#776)
* get all neded data for the header from 3box, aqua and subgraph
* fix tvl display error
* WIP metadata header styling
* added more styling for the header
* make page title optional so we can remove it on account page
* stroke change for svg images and default values
* more styling added to the header
* fixed linter
* added ocean balance to tvl
* update styling for statistcs
* fixed eror for go to my account from another account page
* updated styling for mobile use
* wip show more on explorer links and description
* properly display read more for explorer links and description
* replaced show more with 3box redirect on description
* change accounts default picture and check links length before display element
* use optional on links
* grid cleanup, new number unit, split up stats
* rename all the things, more profile header styling
* visual hierarchy, improve image loading experience
* layout flow & visual tweaks
* more description
* replaced account route with profile when accesing a profile by the eth address
* use account id from url if exists when fetching data
* bump @oceanprotocol/art to v3.2.0
* styling, fallbacks, edge case fixes
* clean up Publisher atom, link to profile page
* fixed issue when switching to my profile from another profile
* output accountId, make it copyable, remove stats icons
* render tweaks, markup cleanup
* add 3box reference
* mobile tabs spacing tweaks
* text flow and spacing tweaks
Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
2021-09-01 13:56:34 +02:00
|
|
|
price: string
|
|
|
|
oceanBalance: string
|
|
|
|
}
|
2021-04-09 11:55:18 +02:00
|
|
|
|
2021-04-14 13:41:17 +02:00
|
|
|
export interface PriceList {
|
|
|
|
[key: string]: string
|
|
|
|
}
|
|
|
|
|
2021-05-17 16:08:15 +02:00
|
|
|
export interface AssetListPrices {
|
2021-11-11 08:51:13 +01:00
|
|
|
ddo: Asset
|
2021-05-17 16:08:15 +02:00
|
|
|
price: BestPrice
|
|
|
|
}
|
|
|
|
|
|
|
|
interface DidAndDatatokenMap {
|
|
|
|
[name: string]: string
|
|
|
|
}
|
|
|
|
|
2021-06-16 03:32:11 +02:00
|
|
|
const FreeQuery = gql`
|
|
|
|
query AssetsFreePrice($datatoken_in: [String!]) {
|
|
|
|
dispensers(orderBy: id, where: { datatoken_in: $datatoken_in }) {
|
|
|
|
datatoken {
|
|
|
|
id
|
|
|
|
address
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
const AssetFreeQuery = gql`
|
|
|
|
query AssetFreePrice($datatoken: String) {
|
|
|
|
dispensers(orderBy: id, where: { datatoken: $datatoken }) {
|
|
|
|
active
|
|
|
|
owner {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
minterApproved
|
|
|
|
isTrueMinter
|
|
|
|
maxTokens
|
|
|
|
maxBalance
|
|
|
|
balance
|
|
|
|
datatoken {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2021-04-20 08:44:18 +02:00
|
|
|
const FreQuery = gql`
|
|
|
|
query AssetsFrePrice($datatoken_in: [String!]) {
|
2021-04-09 11:55:18 +02:00
|
|
|
fixedRateExchanges(orderBy: id, where: { datatoken_in: $datatoken_in }) {
|
|
|
|
rate
|
|
|
|
id
|
2021-09-02 17:01:25 +02:00
|
|
|
baseTokenSymbol
|
2021-04-09 11:55:18 +02:00
|
|
|
datatoken {
|
|
|
|
id
|
|
|
|
address
|
2021-09-02 17:01:25 +02:00
|
|
|
symbol
|
2021-04-09 11:55:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2021-04-20 08:44:18 +02:00
|
|
|
const AssetFreQuery = gql`
|
|
|
|
query AssetFrePrice($datatoken: String) {
|
|
|
|
fixedRateExchanges(orderBy: id, where: { datatoken: $datatoken }) {
|
|
|
|
rate
|
|
|
|
id
|
2021-09-02 17:01:25 +02:00
|
|
|
baseTokenSymbol
|
|
|
|
datatoken {
|
|
|
|
id
|
|
|
|
address
|
|
|
|
symbol
|
|
|
|
}
|
2021-04-20 08:44:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
const PoolQuery = gql`
|
|
|
|
query AssetsPoolPrice($datatokenAddress_in: [String!]) {
|
2021-04-09 11:55:18 +02:00
|
|
|
pools(where: { datatokenAddress_in: $datatokenAddress_in }) {
|
|
|
|
id
|
|
|
|
spotPrice
|
2021-04-23 15:44:31 +02:00
|
|
|
consumePrice
|
2021-04-09 11:55:18 +02:00
|
|
|
datatokenAddress
|
2021-05-17 16:08:15 +02:00
|
|
|
datatokenReserve
|
|
|
|
oceanReserve
|
2021-09-01 16:05:59 +02:00
|
|
|
tokens(where: { isDatatoken: false }) {
|
|
|
|
isDatatoken
|
|
|
|
symbol
|
|
|
|
}
|
2021-04-09 11:55:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2021-09-01 17:48:54 +02:00
|
|
|
const AssetPoolPriceQuery = gql`
|
2021-04-20 08:44:18 +02:00
|
|
|
query AssetPoolPrice($datatokenAddress: String) {
|
|
|
|
pools(where: { datatokenAddress: $datatokenAddress }) {
|
2021-04-09 11:55:18 +02:00
|
|
|
id
|
2021-04-20 08:44:18 +02:00
|
|
|
spotPrice
|
2021-04-22 13:03:58 +02:00
|
|
|
consumePrice
|
2021-04-09 11:55:18 +02:00
|
|
|
datatokenAddress
|
2021-04-20 08:44:18 +02:00
|
|
|
datatokenReserve
|
|
|
|
oceanReserve
|
2021-09-10 21:30:01 +02:00
|
|
|
tokens(where: { isDatatoken: false }) {
|
2021-09-01 16:05:59 +02:00
|
|
|
symbol
|
|
|
|
}
|
2021-04-09 11:55:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2021-04-20 08:44:18 +02:00
|
|
|
const PreviousOrderQuery = gql`
|
2021-04-11 01:13:43 +02:00
|
|
|
query AssetPreviousOrder($id: String!, $account: String!) {
|
|
|
|
tokenOrders(
|
|
|
|
first: 1
|
|
|
|
where: { datatokenId: $id, payer: $account }
|
|
|
|
orderBy: timestamp
|
|
|
|
orderDirection: desc
|
|
|
|
) {
|
|
|
|
timestamp
|
|
|
|
tx
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
2021-06-02 11:14:54 +02:00
|
|
|
const HighestLiquidityAssets = gql`
|
2021-07-15 17:25:53 +02:00
|
|
|
query HighestLiquidityAssets {
|
2021-06-04 13:23:18 +02:00
|
|
|
pools(
|
|
|
|
where: { datatokenReserve_gte: 1 }
|
2021-07-15 17:25:53 +02:00
|
|
|
orderBy: oceanReserve
|
2021-06-04 13:23:18 +02:00
|
|
|
orderDirection: desc
|
|
|
|
first: 15
|
|
|
|
) {
|
2021-06-02 11:14:54 +02:00
|
|
|
id
|
|
|
|
datatokenAddress
|
|
|
|
valueLocked
|
2021-07-15 17:25:53 +02:00
|
|
|
oceanReserve
|
2021-06-02 11:14:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
2021-04-11 01:13:43 +02:00
|
|
|
|
Account metadata header (#776)
* get all neded data for the header from 3box, aqua and subgraph
* fix tvl display error
* WIP metadata header styling
* added more styling for the header
* make page title optional so we can remove it on account page
* stroke change for svg images and default values
* more styling added to the header
* fixed linter
* added ocean balance to tvl
* update styling for statistcs
* fixed eror for go to my account from another account page
* updated styling for mobile use
* wip show more on explorer links and description
* properly display read more for explorer links and description
* replaced show more with 3box redirect on description
* change accounts default picture and check links length before display element
* use optional on links
* grid cleanup, new number unit, split up stats
* rename all the things, more profile header styling
* visual hierarchy, improve image loading experience
* layout flow & visual tweaks
* more description
* replaced account route with profile when accesing a profile by the eth address
* use account id from url if exists when fetching data
* bump @oceanprotocol/art to v3.2.0
* styling, fallbacks, edge case fixes
* clean up Publisher atom, link to profile page
* fixed issue when switching to my profile from another profile
* output accountId, make it copyable, remove stats icons
* render tweaks, markup cleanup
* add 3box reference
* mobile tabs spacing tweaks
* text flow and spacing tweaks
Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
2021-09-01 13:56:34 +02:00
|
|
|
const TotalAccountOrders = gql`
|
2021-09-07 12:11:13 +02:00
|
|
|
query TotalAccountOrders($datatokenId_in: [String!]) {
|
|
|
|
tokenOrders(where: { datatokenId_in: $datatokenId_in }) {
|
Account metadata header (#776)
* get all neded data for the header from 3box, aqua and subgraph
* fix tvl display error
* WIP metadata header styling
* added more styling for the header
* make page title optional so we can remove it on account page
* stroke change for svg images and default values
* more styling added to the header
* fixed linter
* added ocean balance to tvl
* update styling for statistcs
* fixed eror for go to my account from another account page
* updated styling for mobile use
* wip show more on explorer links and description
* properly display read more for explorer links and description
* replaced show more with 3box redirect on description
* change accounts default picture and check links length before display element
* use optional on links
* grid cleanup, new number unit, split up stats
* rename all the things, more profile header styling
* visual hierarchy, improve image loading experience
* layout flow & visual tweaks
* more description
* replaced account route with profile when accesing a profile by the eth address
* use account id from url if exists when fetching data
* bump @oceanprotocol/art to v3.2.0
* styling, fallbacks, edge case fixes
* clean up Publisher atom, link to profile page
* fixed issue when switching to my profile from another profile
* output accountId, make it copyable, remove stats icons
* render tweaks, markup cleanup
* add 3box reference
* mobile tabs spacing tweaks
* text flow and spacing tweaks
Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
2021-09-01 13:56:34 +02:00
|
|
|
payer {
|
|
|
|
id
|
|
|
|
}
|
2021-09-07 12:11:13 +02:00
|
|
|
datatokenId {
|
|
|
|
id
|
|
|
|
}
|
Account metadata header (#776)
* get all neded data for the header from 3box, aqua and subgraph
* fix tvl display error
* WIP metadata header styling
* added more styling for the header
* make page title optional so we can remove it on account page
* stroke change for svg images and default values
* more styling added to the header
* fixed linter
* added ocean balance to tvl
* update styling for statistcs
* fixed eror for go to my account from another account page
* updated styling for mobile use
* wip show more on explorer links and description
* properly display read more for explorer links and description
* replaced show more with 3box redirect on description
* change accounts default picture and check links length before display element
* use optional on links
* grid cleanup, new number unit, split up stats
* rename all the things, more profile header styling
* visual hierarchy, improve image loading experience
* layout flow & visual tweaks
* more description
* replaced account route with profile when accesing a profile by the eth address
* use account id from url if exists when fetching data
* bump @oceanprotocol/art to v3.2.0
* styling, fallbacks, edge case fixes
* clean up Publisher atom, link to profile page
* fixed issue when switching to my profile from another profile
* output accountId, make it copyable, remove stats icons
* render tweaks, markup cleanup
* add 3box reference
* mobile tabs spacing tweaks
* text flow and spacing tweaks
Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
2021-09-01 13:56:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
2021-09-07 12:11:13 +02:00
|
|
|
|
Account metadata header (#776)
* get all neded data for the header from 3box, aqua and subgraph
* fix tvl display error
* WIP metadata header styling
* added more styling for the header
* make page title optional so we can remove it on account page
* stroke change for svg images and default values
* more styling added to the header
* fixed linter
* added ocean balance to tvl
* update styling for statistcs
* fixed eror for go to my account from another account page
* updated styling for mobile use
* wip show more on explorer links and description
* properly display read more for explorer links and description
* replaced show more with 3box redirect on description
* change accounts default picture and check links length before display element
* use optional on links
* grid cleanup, new number unit, split up stats
* rename all the things, more profile header styling
* visual hierarchy, improve image loading experience
* layout flow & visual tweaks
* more description
* replaced account route with profile when accesing a profile by the eth address
* use account id from url if exists when fetching data
* bump @oceanprotocol/art to v3.2.0
* styling, fallbacks, edge case fixes
* clean up Publisher atom, link to profile page
* fixed issue when switching to my profile from another profile
* output accountId, make it copyable, remove stats icons
* render tweaks, markup cleanup
* add 3box reference
* mobile tabs spacing tweaks
* text flow and spacing tweaks
Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
2021-09-01 13:56:34 +02:00
|
|
|
const UserSharesQuery = gql`
|
|
|
|
query UserSharesQuery($user: String, $pools: [String!]) {
|
|
|
|
poolShares(where: { userAddress: $user, poolId_in: $pools }) {
|
|
|
|
id
|
|
|
|
balance
|
|
|
|
userAddress {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
poolId {
|
|
|
|
id
|
|
|
|
datatokenAddress
|
|
|
|
valueLocked
|
|
|
|
tokens {
|
|
|
|
tokenId {
|
|
|
|
symbol
|
|
|
|
}
|
|
|
|
}
|
|
|
|
oceanReserve
|
|
|
|
datatokenReserve
|
|
|
|
totalShares
|
|
|
|
consumePrice
|
|
|
|
spotPrice
|
|
|
|
createTime
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
2021-09-13 16:39:32 +02:00
|
|
|
|
|
|
|
const userPoolSharesQuery = gql`
|
|
|
|
query PoolShares($user: String) {
|
|
|
|
poolShares(where: { userAddress: $user, balance_gt: 0.001 }, first: 1000) {
|
|
|
|
id
|
|
|
|
balance
|
|
|
|
userAddress {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
poolId {
|
|
|
|
id
|
|
|
|
datatokenAddress
|
|
|
|
valueLocked
|
|
|
|
tokens {
|
|
|
|
id
|
|
|
|
isDatatoken
|
|
|
|
symbol
|
|
|
|
}
|
|
|
|
oceanReserve
|
|
|
|
datatokenReserve
|
|
|
|
totalShares
|
|
|
|
consumePrice
|
|
|
|
spotPrice
|
|
|
|
createTime
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
const UserTokenOrders = gql`
|
|
|
|
query OrdersData($user: String!) {
|
|
|
|
tokenOrders(
|
|
|
|
orderBy: timestamp
|
|
|
|
orderDirection: desc
|
|
|
|
where: { consumer: $user }
|
|
|
|
) {
|
|
|
|
datatokenId {
|
|
|
|
address
|
|
|
|
symbol
|
|
|
|
}
|
|
|
|
timestamp
|
|
|
|
tx
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
2021-10-18 16:43:32 +02:00
|
|
|
const UserSalesQuery = gql`
|
2021-10-18 20:44:33 +02:00
|
|
|
query UserSalesQuery($userSalesId: ID) {
|
2021-10-18 16:43:32 +02:00
|
|
|
users(where: { id: $userSalesId }) {
|
|
|
|
id
|
|
|
|
nrSales
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
2021-09-13 16:39:32 +02:00
|
|
|
|
2021-08-17 11:46:51 +02:00
|
|
|
export function getSubgraphUri(chainId: number): string {
|
2021-06-25 09:50:56 +02:00
|
|
|
const config = getOceanConfig(chainId)
|
|
|
|
return config.subgraphUri
|
|
|
|
}
|
|
|
|
|
2021-07-22 14:01:30 +02:00
|
|
|
export function getQueryContext(chainId: number): OperationContext {
|
|
|
|
const queryContext: OperationContext = {
|
2021-08-17 11:46:51 +02:00
|
|
|
url: `${getSubgraphUri(
|
2021-07-22 14:01:30 +02:00
|
|
|
Number(chainId)
|
|
|
|
)}/subgraphs/name/oceanprotocol/ocean-subgraph`,
|
2021-08-19 16:25:51 +02:00
|
|
|
requestPolicy: 'cache-and-network'
|
2021-07-22 14:01:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return queryContext
|
|
|
|
}
|
|
|
|
|
2021-07-22 13:02:32 +02:00
|
|
|
export async function fetchData(
|
2021-06-22 07:52:49 +02:00
|
|
|
query: TypedDocumentNode,
|
2021-06-25 09:50:56 +02:00
|
|
|
variables: any,
|
|
|
|
context: OperationContext
|
2021-07-22 13:07:52 +02:00
|
|
|
): Promise<any> {
|
2021-04-09 11:55:18 +02:00
|
|
|
try {
|
2021-06-22 07:52:49 +02:00
|
|
|
const client = getUrqlClientInstance()
|
2021-06-25 09:50:56 +02:00
|
|
|
const response = await client.query(query, variables, context).toPromise()
|
2021-04-09 11:55:18 +02:00
|
|
|
return response
|
|
|
|
} catch (error) {
|
2021-04-11 01:13:43 +02:00
|
|
|
console.error('Error fetchData: ', error.message)
|
2021-07-22 13:02:32 +02:00
|
|
|
throw Error(error.message)
|
2021-04-11 01:13:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-23 14:46:25 +02:00
|
|
|
export async function fetchDataForMultipleChains(
|
|
|
|
query: TypedDocumentNode,
|
|
|
|
variables: any,
|
|
|
|
chainIds: number[]
|
|
|
|
): Promise<any[]> {
|
|
|
|
let datas: any[] = []
|
|
|
|
for (const chainId of chainIds) {
|
|
|
|
const context: OperationContext = {
|
2021-08-17 11:46:51 +02:00
|
|
|
url: `${getSubgraphUri(
|
2021-07-23 14:46:25 +02:00
|
|
|
chainId
|
|
|
|
)}/subgraphs/name/oceanprotocol/ocean-subgraph`,
|
|
|
|
requestPolicy: 'network-only'
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
const response = await fetchData(query, variables, context)
|
|
|
|
datas = datas.concat(response.data)
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Error fetchData: ', error.message)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return datas
|
|
|
|
}
|
|
|
|
|
2021-04-11 01:13:43 +02:00
|
|
|
export async function getPreviousOrders(
|
|
|
|
id: string,
|
|
|
|
account: string,
|
|
|
|
assetTimeout: string
|
|
|
|
): Promise<string> {
|
|
|
|
const variables = {
|
|
|
|
id: id,
|
|
|
|
account: account
|
|
|
|
}
|
2021-06-22 07:52:49 +02:00
|
|
|
const fetchedPreviousOrders: OperationResult<AssetPreviousOrder> =
|
2021-06-25 09:50:56 +02:00
|
|
|
await fetchData(PreviousOrderQuery, variables, null)
|
2021-04-12 16:09:41 +02:00
|
|
|
if (fetchedPreviousOrders.data?.tokenOrders?.length === 0) return null
|
|
|
|
if (assetTimeout === '0') {
|
|
|
|
return fetchedPreviousOrders?.data?.tokenOrders[0]?.tx
|
2021-04-11 01:13:43 +02:00
|
|
|
} else {
|
2021-05-07 15:00:40 +02:00
|
|
|
const expiry =
|
|
|
|
fetchedPreviousOrders?.data?.tokenOrders[0]?.timestamp * 1000 +
|
|
|
|
Number(assetTimeout) * 1000
|
|
|
|
if (Date.now() <= expiry) {
|
2021-04-12 16:09:41 +02:00
|
|
|
return fetchedPreviousOrders?.data?.tokenOrders[0]?.tx
|
2021-04-11 01:13:43 +02:00
|
|
|
} else {
|
|
|
|
return null
|
|
|
|
}
|
2021-04-09 11:55:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-17 16:08:15 +02:00
|
|
|
function transformPriceToBestPrice(
|
2021-09-01 17:48:54 +02:00
|
|
|
frePrice: AssetsFrePriceFixedRateExchange[],
|
|
|
|
poolPrice: AssetsPoolPricePool[],
|
2021-06-16 03:32:11 +02:00
|
|
|
freePrice: AssetFreePriceDispenser[]
|
2021-05-17 16:08:15 +02:00
|
|
|
) {
|
|
|
|
if (poolPrice?.length > 0) {
|
|
|
|
const price: BestPrice = {
|
2021-11-23 13:53:09 +01:00
|
|
|
type: 'dynamic',
|
2021-05-17 16:08:15 +02:00
|
|
|
address: poolPrice[0]?.id,
|
|
|
|
value:
|
|
|
|
poolPrice[0]?.consumePrice === '-1'
|
|
|
|
? poolPrice[0]?.spotPrice
|
|
|
|
: poolPrice[0]?.consumePrice,
|
|
|
|
ocean: poolPrice[0]?.oceanReserve,
|
2021-09-01 16:05:59 +02:00
|
|
|
oceanSymbol: poolPrice[0]?.tokens[0]?.symbol,
|
2021-05-17 16:08:15 +02:00
|
|
|
datatoken: poolPrice[0]?.datatokenReserve,
|
|
|
|
pools: [poolPrice[0]?.id],
|
|
|
|
isConsumable: poolPrice[0]?.consumePrice === '-1' ? 'false' : 'true'
|
|
|
|
}
|
|
|
|
return price
|
|
|
|
} else if (frePrice?.length > 0) {
|
|
|
|
// TODO Hacky hack, temporary™: set isConsumable to true for fre assets.
|
|
|
|
// isConsumable: 'true'
|
|
|
|
const price: BestPrice = {
|
2021-11-23 13:53:09 +01:00
|
|
|
type: 'fixed',
|
2021-05-17 16:08:15 +02:00
|
|
|
value: frePrice[0]?.rate,
|
|
|
|
address: frePrice[0]?.id,
|
2021-09-01 16:05:59 +02:00
|
|
|
exchangeId: frePrice[0]?.id,
|
2021-09-02 17:01:25 +02:00
|
|
|
oceanSymbol: frePrice[0]?.baseTokenSymbol,
|
2021-05-17 16:08:15 +02:00
|
|
|
ocean: 0,
|
|
|
|
datatoken: 0,
|
|
|
|
pools: [],
|
|
|
|
isConsumable: 'true'
|
|
|
|
}
|
|
|
|
return price
|
2021-06-16 03:32:11 +02:00
|
|
|
} else if (freePrice?.length > 0) {
|
|
|
|
const price: BestPrice = {
|
|
|
|
type: 'free',
|
|
|
|
value: 0,
|
|
|
|
address: freePrice[0]?.datatoken.id,
|
2021-09-01 16:05:59 +02:00
|
|
|
exchangeId: '',
|
2021-06-16 03:32:11 +02:00
|
|
|
ocean: 0,
|
|
|
|
datatoken: 0,
|
|
|
|
pools: [],
|
|
|
|
isConsumable: 'true'
|
|
|
|
}
|
|
|
|
return price
|
2021-05-17 16:08:15 +02:00
|
|
|
} else {
|
|
|
|
const price: BestPrice = {
|
|
|
|
type: '',
|
|
|
|
value: 0,
|
|
|
|
address: '',
|
2021-09-01 16:05:59 +02:00
|
|
|
exchangeId: '',
|
2021-05-17 16:08:15 +02:00
|
|
|
ocean: 0,
|
|
|
|
datatoken: 0,
|
|
|
|
pools: [],
|
|
|
|
isConsumable: 'false'
|
|
|
|
}
|
|
|
|
return price
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getAssetsPoolsExchangesAndDatatokenMap(
|
2021-11-11 08:51:13 +01:00
|
|
|
assets: Asset[]
|
2021-05-17 16:08:15 +02:00
|
|
|
): Promise<
|
|
|
|
[
|
2021-09-01 17:48:54 +02:00
|
|
|
AssetsPoolPricePool[],
|
|
|
|
AssetsFrePriceFixedRateExchange[],
|
2021-07-09 10:36:43 +02:00
|
|
|
AssetFreePriceDispenser[],
|
2021-05-17 16:08:15 +02:00
|
|
|
DidAndDatatokenMap
|
|
|
|
]
|
|
|
|
> {
|
|
|
|
const didDTMap: DidAndDatatokenMap = {}
|
2021-06-25 09:50:56 +02:00
|
|
|
const chainAssetLists: any = {}
|
2021-04-13 18:15:09 +02:00
|
|
|
|
2021-04-11 01:13:43 +02:00
|
|
|
for (const ddo of assets) {
|
2021-11-11 08:51:13 +01:00
|
|
|
didDTMap[ddo?.services[0].datatokenAddress.toLowerCase()] = ddo.id
|
2021-06-25 09:50:56 +02:00
|
|
|
// harcoded until we have chainId on assets
|
2021-07-08 00:07:12 +02:00
|
|
|
if (chainAssetLists[ddo.chainId]) {
|
2021-11-11 08:51:13 +01:00
|
|
|
chainAssetLists[ddo.chainId].push(
|
|
|
|
ddo?.services[0].datatokenAddress.toLowerCase()
|
|
|
|
)
|
2021-06-25 09:50:56 +02:00
|
|
|
} else {
|
2021-07-08 00:07:12 +02:00
|
|
|
chainAssetLists[ddo.chainId] = []
|
2021-11-11 08:51:13 +01:00
|
|
|
chainAssetLists[ddo.chainId].push(
|
|
|
|
ddo?.services[0].datatokenAddress.toLowerCase()
|
|
|
|
)
|
2021-06-25 09:50:56 +02:00
|
|
|
}
|
2021-04-09 11:55:18 +02:00
|
|
|
}
|
2021-09-01 17:48:54 +02:00
|
|
|
let poolPriceResponse: AssetsPoolPricePool[] = []
|
|
|
|
let frePriceResponse: AssetsFrePriceFixedRateExchange[] = []
|
2021-07-05 13:27:43 +02:00
|
|
|
let freePriceResponse: AssetFreePriceDispenser[] = []
|
2021-05-17 16:08:15 +02:00
|
|
|
|
2021-06-25 09:50:56 +02:00
|
|
|
for (const chainKey in chainAssetLists) {
|
|
|
|
const freVariables = {
|
|
|
|
datatoken_in: chainAssetLists[chainKey]
|
|
|
|
}
|
|
|
|
const poolVariables = {
|
|
|
|
datatokenAddress_in: chainAssetLists[chainKey]
|
|
|
|
}
|
2021-07-05 13:27:43 +02:00
|
|
|
const freeVariables = {
|
|
|
|
datatoken_in: chainAssetLists[chainKey]
|
|
|
|
}
|
2021-07-08 00:07:12 +02:00
|
|
|
|
2021-07-22 14:01:30 +02:00
|
|
|
const queryContext = getQueryContext(Number(chainKey))
|
2021-06-25 09:50:56 +02:00
|
|
|
|
|
|
|
const chainPoolPriceResponse: OperationResult<AssetsPoolPrice> =
|
|
|
|
await fetchData(PoolQuery, poolVariables, queryContext)
|
|
|
|
|
|
|
|
poolPriceResponse = poolPriceResponse.concat(
|
|
|
|
chainPoolPriceResponse.data.pools
|
|
|
|
)
|
|
|
|
const chainFrePriceResponse: OperationResult<AssetsFrePrice> =
|
|
|
|
await fetchData(FreQuery, freVariables, queryContext)
|
2021-07-08 00:07:12 +02:00
|
|
|
|
2021-06-25 09:50:56 +02:00
|
|
|
frePriceResponse = frePriceResponse.concat(
|
|
|
|
chainFrePriceResponse.data.fixedRateExchanges
|
|
|
|
)
|
2021-05-17 16:08:15 +02:00
|
|
|
|
2021-07-05 13:27:43 +02:00
|
|
|
const chainFreePriceResponse: OperationResult<AssetsFreePrice> =
|
|
|
|
await fetchData(FreeQuery, freeVariables, queryContext)
|
2021-07-08 00:07:12 +02:00
|
|
|
|
2021-07-05 13:27:43 +02:00
|
|
|
freePriceResponse = freePriceResponse.concat(
|
|
|
|
chainFreePriceResponse.data.dispensers
|
|
|
|
)
|
|
|
|
}
|
2021-06-16 03:32:11 +02:00
|
|
|
return [poolPriceResponse, frePriceResponse, freePriceResponse, didDTMap]
|
2021-05-17 16:08:15 +02:00
|
|
|
}
|
|
|
|
|
2021-11-11 08:51:13 +01:00
|
|
|
export async function getAssetsPriceList(assets: Asset[]): Promise<PriceList> {
|
2021-05-17 16:08:15 +02:00
|
|
|
const priceList: PriceList = {}
|
|
|
|
|
|
|
|
const values: [
|
2021-09-01 17:48:54 +02:00
|
|
|
AssetsPoolPricePool[],
|
|
|
|
AssetsFrePriceFixedRateExchange[],
|
2021-07-09 10:36:43 +02:00
|
|
|
AssetFreePriceDispenser[],
|
2021-05-17 16:08:15 +02:00
|
|
|
DidAndDatatokenMap
|
|
|
|
] = await getAssetsPoolsExchangesAndDatatokenMap(assets)
|
|
|
|
const poolPriceResponse = values[0]
|
|
|
|
const frePriceResponse = values[1]
|
2021-06-16 03:32:11 +02:00
|
|
|
const freePriceResponse = values[2]
|
|
|
|
const didDTMap: DidAndDatatokenMap = values[3]
|
2021-05-17 16:08:15 +02:00
|
|
|
|
2021-06-25 09:50:56 +02:00
|
|
|
for (const poolPrice of poolPriceResponse) {
|
2021-04-23 15:44:31 +02:00
|
|
|
priceList[didDTMap[poolPrice.datatokenAddress]] =
|
|
|
|
poolPrice.consumePrice === '-1'
|
|
|
|
? poolPrice.spotPrice
|
|
|
|
: poolPrice.consumePrice
|
2021-04-09 11:55:18 +02:00
|
|
|
}
|
2021-06-25 09:50:56 +02:00
|
|
|
for (const frePrice of frePriceResponse) {
|
2021-04-13 18:15:09 +02:00
|
|
|
priceList[didDTMap[frePrice.datatoken?.address]] = frePrice.rate
|
2021-04-09 11:55:18 +02:00
|
|
|
}
|
2021-07-08 00:07:12 +02:00
|
|
|
for (const freePrice of freePriceResponse) {
|
2021-06-16 03:32:11 +02:00
|
|
|
priceList[didDTMap[freePrice.datatoken?.address]] = '0'
|
|
|
|
}
|
2021-04-09 11:55:18 +02:00
|
|
|
return priceList
|
|
|
|
}
|
2021-04-20 08:44:18 +02:00
|
|
|
|
2021-11-11 08:51:13 +01:00
|
|
|
export async function getPrice(asset: Asset): Promise<BestPrice> {
|
2021-04-20 08:44:18 +02:00
|
|
|
const freVariables = {
|
2021-11-11 08:51:13 +01:00
|
|
|
datatoken: asset?.services[0].datatokenAddress.toLowerCase()
|
2021-04-20 08:44:18 +02:00
|
|
|
}
|
2021-07-05 13:27:43 +02:00
|
|
|
const freeVariables = {
|
2021-11-11 08:51:13 +01:00
|
|
|
datatoken: asset?.services[0].datatokenAddress.toLowerCase()
|
2021-07-05 13:27:43 +02:00
|
|
|
}
|
2021-04-20 08:44:18 +02:00
|
|
|
const poolVariables = {
|
2021-11-11 08:51:13 +01:00
|
|
|
datatokenAddress: asset?.services[0].datatokenAddress.toLowerCase()
|
2021-04-20 08:44:18 +02:00
|
|
|
}
|
2021-07-22 14:01:30 +02:00
|
|
|
const queryContext = getQueryContext(Number(asset.chainId))
|
2021-04-20 08:44:18 +02:00
|
|
|
|
2021-06-22 07:52:49 +02:00
|
|
|
const poolPriceResponse: OperationResult<AssetsPoolPrice> = await fetchData(
|
2021-09-01 17:48:54 +02:00
|
|
|
AssetPoolPriceQuery,
|
2021-06-25 09:50:56 +02:00
|
|
|
poolVariables,
|
|
|
|
queryContext
|
2021-04-20 08:44:18 +02:00
|
|
|
)
|
2021-06-22 07:52:49 +02:00
|
|
|
const frePriceResponse: OperationResult<AssetsFrePrice> = await fetchData(
|
2021-05-17 16:08:15 +02:00
|
|
|
AssetFreQuery,
|
2021-06-25 09:50:56 +02:00
|
|
|
freVariables,
|
|
|
|
queryContext
|
2021-05-17 16:08:15 +02:00
|
|
|
)
|
2021-07-09 10:36:43 +02:00
|
|
|
const freePriceResponse: OperationResult<AssetsFreePrice> = await fetchData(
|
2021-06-16 03:32:11 +02:00
|
|
|
AssetFreeQuery,
|
2021-07-05 13:27:43 +02:00
|
|
|
freeVariables,
|
|
|
|
queryContext
|
2021-06-16 03:32:11 +02:00
|
|
|
)
|
2021-05-17 16:08:15 +02:00
|
|
|
|
|
|
|
const bestPrice: BestPrice = transformPriceToBestPrice(
|
|
|
|
frePriceResponse.data.fixedRateExchanges,
|
2021-06-16 03:32:11 +02:00
|
|
|
poolPriceResponse.data.pools,
|
|
|
|
freePriceResponse.data.dispensers
|
2021-05-17 16:08:15 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
return bestPrice
|
|
|
|
}
|
|
|
|
|
2021-11-11 08:51:13 +01:00
|
|
|
export async function getSpotPrice(asset: Asset): Promise<number> {
|
2021-08-18 11:46:27 +02:00
|
|
|
const poolVariables = {
|
2021-11-11 08:51:13 +01:00
|
|
|
datatokenAddress: asset?.services[0].datatokenAddress.toLowerCase()
|
2021-08-18 11:46:27 +02:00
|
|
|
}
|
|
|
|
const queryContext = getQueryContext(Number(asset.chainId))
|
|
|
|
|
|
|
|
const poolPriceResponse: OperationResult<AssetsPoolPrice> = await fetchData(
|
2021-09-01 17:48:54 +02:00
|
|
|
AssetPoolPriceQuery,
|
2021-08-18 11:46:27 +02:00
|
|
|
poolVariables,
|
|
|
|
queryContext
|
|
|
|
)
|
|
|
|
|
|
|
|
return poolPriceResponse.data.pools[0].spotPrice
|
|
|
|
}
|
|
|
|
|
2021-05-17 16:08:15 +02:00
|
|
|
export async function getAssetsBestPrices(
|
2021-11-11 08:51:13 +01:00
|
|
|
assets: Asset[]
|
2021-05-17 16:08:15 +02:00
|
|
|
): Promise<AssetListPrices[]> {
|
|
|
|
const assetsWithPrice: AssetListPrices[] = []
|
|
|
|
|
|
|
|
const values: [
|
2021-09-01 17:48:54 +02:00
|
|
|
AssetsPoolPricePool[],
|
|
|
|
AssetsFrePriceFixedRateExchange[],
|
2021-07-09 10:36:43 +02:00
|
|
|
AssetFreePriceDispenser[],
|
2021-05-17 16:08:15 +02:00
|
|
|
DidAndDatatokenMap
|
|
|
|
] = await getAssetsPoolsExchangesAndDatatokenMap(assets)
|
2021-07-08 00:07:12 +02:00
|
|
|
|
2021-05-17 16:08:15 +02:00
|
|
|
const poolPriceResponse = values[0]
|
|
|
|
const frePriceResponse = values[1]
|
2021-06-16 03:32:11 +02:00
|
|
|
const freePriceResponse = values[2]
|
2021-05-17 16:08:15 +02:00
|
|
|
for (const ddo of assets) {
|
2021-11-11 08:51:13 +01:00
|
|
|
const dataToken = ddo.services[0].datatokenAddress.toLowerCase()
|
2021-09-01 17:48:54 +02:00
|
|
|
const poolPrice: AssetsPoolPricePool[] = []
|
|
|
|
const frePrice: AssetsFrePriceFixedRateExchange[] = []
|
2021-06-16 03:32:11 +02:00
|
|
|
const freePrice: AssetFreePriceDispenser[] = []
|
2021-07-08 00:07:12 +02:00
|
|
|
const pool = poolPriceResponse.find(
|
2021-09-01 17:48:54 +02:00
|
|
|
(pool: AssetsPoolPricePool) => pool.datatokenAddress === dataToken
|
2021-05-17 16:08:15 +02:00
|
|
|
)
|
|
|
|
pool && poolPrice.push(pool)
|
2021-06-25 09:50:56 +02:00
|
|
|
const fre = frePriceResponse.find(
|
2021-09-01 17:48:54 +02:00
|
|
|
(fre: AssetsFrePriceFixedRateExchange) =>
|
|
|
|
fre.datatoken.address === dataToken
|
2021-05-17 16:08:15 +02:00
|
|
|
)
|
|
|
|
fre && frePrice.push(fre)
|
2021-07-08 00:07:12 +02:00
|
|
|
const free = freePriceResponse.find(
|
2021-09-01 17:48:54 +02:00
|
|
|
(free: AssetFreePriceDispenser) => free.datatoken.address === dataToken
|
2021-06-16 03:32:11 +02:00
|
|
|
)
|
|
|
|
free && freePrice.push(free)
|
|
|
|
const bestPrice = transformPriceToBestPrice(frePrice, poolPrice, freePrice)
|
2021-05-17 16:08:15 +02:00
|
|
|
assetsWithPrice.push({
|
|
|
|
ddo: ddo,
|
|
|
|
price: bestPrice
|
|
|
|
})
|
2021-04-20 08:44:18 +02:00
|
|
|
}
|
2021-05-17 16:08:15 +02:00
|
|
|
|
|
|
|
return assetsWithPrice
|
2021-04-20 08:44:18 +02:00
|
|
|
}
|
2021-06-02 11:14:54 +02:00
|
|
|
|
2021-10-21 09:24:00 +02:00
|
|
|
export async function getHighestLiquidityDatatokens(
|
2021-07-08 00:07:12 +02:00
|
|
|
chainIds: number[]
|
2021-10-21 09:24:00 +02:00
|
|
|
): Promise<string[]> {
|
|
|
|
const dtList: string[] = []
|
2021-09-01 17:48:54 +02:00
|
|
|
let highestLiquidityAssets: HighestLiquidityAssetsPool[] = []
|
2021-07-08 00:07:12 +02:00
|
|
|
for (const chain of chainIds) {
|
2021-07-22 14:01:30 +02:00
|
|
|
const queryContext = getQueryContext(Number(chain))
|
2021-07-15 17:25:53 +02:00
|
|
|
const fetchedPools: OperationResult<HighestLiquidityGraphAssets, any> =
|
|
|
|
await fetchData(HighestLiquidityAssets, null, queryContext)
|
2021-09-01 17:48:54 +02:00
|
|
|
highestLiquidityAssets = highestLiquidityAssets.concat(
|
2021-07-15 17:25:53 +02:00
|
|
|
fetchedPools.data.pools
|
2021-07-08 00:07:12 +02:00
|
|
|
)
|
2021-07-15 17:25:53 +02:00
|
|
|
}
|
2021-10-21 09:24:00 +02:00
|
|
|
highestLiquidityAssets.sort((a, b) => b.oceanReserve - a.oceanReserve)
|
2021-09-01 17:48:54 +02:00
|
|
|
for (let i = 0; i < highestLiquidityAssets.length; i++) {
|
|
|
|
if (!highestLiquidityAssets[i].datatokenAddress) continue
|
2021-10-21 09:24:00 +02:00
|
|
|
dtList.push(highestLiquidityAssets[i].datatokenAddress)
|
|
|
|
}
|
|
|
|
return dtList
|
2021-06-02 11:14:54 +02:00
|
|
|
}
|
Account metadata header (#776)
* get all neded data for the header from 3box, aqua and subgraph
* fix tvl display error
* WIP metadata header styling
* added more styling for the header
* make page title optional so we can remove it on account page
* stroke change for svg images and default values
* more styling added to the header
* fixed linter
* added ocean balance to tvl
* update styling for statistcs
* fixed eror for go to my account from another account page
* updated styling for mobile use
* wip show more on explorer links and description
* properly display read more for explorer links and description
* replaced show more with 3box redirect on description
* change accounts default picture and check links length before display element
* use optional on links
* grid cleanup, new number unit, split up stats
* rename all the things, more profile header styling
* visual hierarchy, improve image loading experience
* layout flow & visual tweaks
* more description
* replaced account route with profile when accesing a profile by the eth address
* use account id from url if exists when fetching data
* bump @oceanprotocol/art to v3.2.0
* styling, fallbacks, edge case fixes
* clean up Publisher atom, link to profile page
* fixed issue when switching to my profile from another profile
* output accountId, make it copyable, remove stats icons
* render tweaks, markup cleanup
* add 3box reference
* mobile tabs spacing tweaks
* text flow and spacing tweaks
Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
2021-09-01 13:56:34 +02:00
|
|
|
|
2021-09-01 16:11:47 +02:00
|
|
|
export function calculateUserLiquidity(poolShare: PoolShare): number {
|
Account metadata header (#776)
* get all neded data for the header from 3box, aqua and subgraph
* fix tvl display error
* WIP metadata header styling
* added more styling for the header
* make page title optional so we can remove it on account page
* stroke change for svg images and default values
* more styling added to the header
* fixed linter
* added ocean balance to tvl
* update styling for statistcs
* fixed eror for go to my account from another account page
* updated styling for mobile use
* wip show more on explorer links and description
* properly display read more for explorer links and description
* replaced show more with 3box redirect on description
* change accounts default picture and check links length before display element
* use optional on links
* grid cleanup, new number unit, split up stats
* rename all the things, more profile header styling
* visual hierarchy, improve image loading experience
* layout flow & visual tweaks
* more description
* replaced account route with profile when accesing a profile by the eth address
* use account id from url if exists when fetching data
* bump @oceanprotocol/art to v3.2.0
* styling, fallbacks, edge case fixes
* clean up Publisher atom, link to profile page
* fixed issue when switching to my profile from another profile
* output accountId, make it copyable, remove stats icons
* render tweaks, markup cleanup
* add 3box reference
* mobile tabs spacing tweaks
* text flow and spacing tweaks
Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
2021-09-01 13:56:34 +02:00
|
|
|
const ocean =
|
|
|
|
(poolShare.balance / poolShare.poolId.totalShares) *
|
|
|
|
poolShare.poolId.oceanReserve
|
|
|
|
const datatokens =
|
|
|
|
(poolShare.balance / poolShare.poolId.totalShares) *
|
|
|
|
poolShare.poolId.datatokenReserve
|
2021-10-21 09:24:00 +02:00
|
|
|
const totalLiquidity = ocean + datatokens * poolShare.poolId.spotPrice
|
Account metadata header (#776)
* get all neded data for the header from 3box, aqua and subgraph
* fix tvl display error
* WIP metadata header styling
* added more styling for the header
* make page title optional so we can remove it on account page
* stroke change for svg images and default values
* more styling added to the header
* fixed linter
* added ocean balance to tvl
* update styling for statistcs
* fixed eror for go to my account from another account page
* updated styling for mobile use
* wip show more on explorer links and description
* properly display read more for explorer links and description
* replaced show more with 3box redirect on description
* change accounts default picture and check links length before display element
* use optional on links
* grid cleanup, new number unit, split up stats
* rename all the things, more profile header styling
* visual hierarchy, improve image loading experience
* layout flow & visual tweaks
* more description
* replaced account route with profile when accesing a profile by the eth address
* use account id from url if exists when fetching data
* bump @oceanprotocol/art to v3.2.0
* styling, fallbacks, edge case fixes
* clean up Publisher atom, link to profile page
* fixed issue when switching to my profile from another profile
* output accountId, make it copyable, remove stats icons
* render tweaks, markup cleanup
* add 3box reference
* mobile tabs spacing tweaks
* text flow and spacing tweaks
Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
2021-09-01 13:56:34 +02:00
|
|
|
return totalLiquidity
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getAccountLiquidityInOwnAssets(
|
|
|
|
accountId: string,
|
|
|
|
chainIds: number[],
|
|
|
|
pools: string[]
|
2021-09-13 16:39:32 +02:00
|
|
|
): Promise<UserLiquidity> {
|
Account metadata header (#776)
* get all neded data for the header from 3box, aqua and subgraph
* fix tvl display error
* WIP metadata header styling
* added more styling for the header
* make page title optional so we can remove it on account page
* stroke change for svg images and default values
* more styling added to the header
* fixed linter
* added ocean balance to tvl
* update styling for statistcs
* fixed eror for go to my account from another account page
* updated styling for mobile use
* wip show more on explorer links and description
* properly display read more for explorer links and description
* replaced show more with 3box redirect on description
* change accounts default picture and check links length before display element
* use optional on links
* grid cleanup, new number unit, split up stats
* rename all the things, more profile header styling
* visual hierarchy, improve image loading experience
* layout flow & visual tweaks
* more description
* replaced account route with profile when accesing a profile by the eth address
* use account id from url if exists when fetching data
* bump @oceanprotocol/art to v3.2.0
* styling, fallbacks, edge case fixes
* clean up Publisher atom, link to profile page
* fixed issue when switching to my profile from another profile
* output accountId, make it copyable, remove stats icons
* render tweaks, markup cleanup
* add 3box reference
* mobile tabs spacing tweaks
* text flow and spacing tweaks
Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
2021-09-01 13:56:34 +02:00
|
|
|
const queryVariables = {
|
|
|
|
user: accountId.toLowerCase(),
|
|
|
|
pools: pools
|
|
|
|
}
|
|
|
|
const results: PoolSharesList[] = await fetchDataForMultipleChains(
|
|
|
|
UserSharesQuery,
|
|
|
|
queryVariables,
|
|
|
|
chainIds
|
|
|
|
)
|
|
|
|
let totalLiquidity = 0
|
|
|
|
let totalOceanLiquidity = 0
|
2021-10-21 09:24:00 +02:00
|
|
|
|
Account metadata header (#776)
* get all neded data for the header from 3box, aqua and subgraph
* fix tvl display error
* WIP metadata header styling
* added more styling for the header
* make page title optional so we can remove it on account page
* stroke change for svg images and default values
* more styling added to the header
* fixed linter
* added ocean balance to tvl
* update styling for statistcs
* fixed eror for go to my account from another account page
* updated styling for mobile use
* wip show more on explorer links and description
* properly display read more for explorer links and description
* replaced show more with 3box redirect on description
* change accounts default picture and check links length before display element
* use optional on links
* grid cleanup, new number unit, split up stats
* rename all the things, more profile header styling
* visual hierarchy, improve image loading experience
* layout flow & visual tweaks
* more description
* replaced account route with profile when accesing a profile by the eth address
* use account id from url if exists when fetching data
* bump @oceanprotocol/art to v3.2.0
* styling, fallbacks, edge case fixes
* clean up Publisher atom, link to profile page
* fixed issue when switching to my profile from another profile
* output accountId, make it copyable, remove stats icons
* render tweaks, markup cleanup
* add 3box reference
* mobile tabs spacing tweaks
* text flow and spacing tweaks
Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
2021-09-01 13:56:34 +02:00
|
|
|
for (const result of results) {
|
|
|
|
for (const poolShare of result.poolShares) {
|
|
|
|
const userShare = poolShare.balance / poolShare.poolId.totalShares
|
|
|
|
const userBalance = userShare * poolShare.poolId.oceanReserve
|
|
|
|
totalOceanLiquidity += userBalance
|
|
|
|
const poolLiquidity = calculateUserLiquidity(poolShare)
|
|
|
|
totalLiquidity += poolLiquidity
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
price: totalLiquidity.toString(),
|
|
|
|
oceanBalance: totalOceanLiquidity.toString()
|
|
|
|
}
|
|
|
|
}
|
2021-09-13 16:39:32 +02:00
|
|
|
|
|
|
|
export async function getPoolSharesData(
|
|
|
|
accountId: string,
|
|
|
|
chainIds: number[]
|
|
|
|
): Promise<PoolShare[]> {
|
|
|
|
const variables = { user: accountId?.toLowerCase() }
|
|
|
|
const data: PoolShare[] = []
|
|
|
|
const result = await fetchDataForMultipleChains(
|
|
|
|
userPoolSharesQuery,
|
|
|
|
variables,
|
|
|
|
chainIds
|
|
|
|
)
|
|
|
|
for (let i = 0; i < result.length; i++) {
|
|
|
|
result[i].poolShares.forEach((poolShare: PoolShare) => {
|
|
|
|
data.push(poolShare)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return data
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getUserTokenOrders(
|
|
|
|
accountId: string,
|
|
|
|
chainIds: number[]
|
|
|
|
): Promise<OrdersData[]> {
|
|
|
|
const data: OrdersData[] = []
|
|
|
|
const variables = { user: accountId?.toLowerCase() }
|
|
|
|
|
|
|
|
try {
|
|
|
|
const tokenOrders = await fetchDataForMultipleChains(
|
|
|
|
UserTokenOrders,
|
|
|
|
variables,
|
|
|
|
chainIds
|
|
|
|
)
|
|
|
|
|
|
|
|
for (let i = 0; i < tokenOrders?.length; i++) {
|
|
|
|
tokenOrders[i].tokenOrders.forEach((tokenOrder: OrdersData) => {
|
|
|
|
data.push(tokenOrder)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return data
|
|
|
|
} catch (error) {
|
|
|
|
Logger.error(error.message)
|
|
|
|
}
|
|
|
|
}
|
2021-10-18 16:43:32 +02:00
|
|
|
|
|
|
|
export async function getUserSales(
|
|
|
|
accountId: string,
|
|
|
|
chainIds: number[]
|
|
|
|
): Promise<number> {
|
|
|
|
const variables = { userSalesId: accountId?.toLowerCase() }
|
|
|
|
try {
|
|
|
|
const userSales = await fetchDataForMultipleChains(
|
|
|
|
UserSalesQuery,
|
|
|
|
variables,
|
|
|
|
chainIds
|
|
|
|
)
|
|
|
|
let salesSum = 0
|
|
|
|
for (let i = 0; i < userSales.length; i++) {
|
|
|
|
if (userSales[i].users.length > 0) {
|
|
|
|
salesSum += userSales[i].users[0].nrSales
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return salesSum
|
|
|
|
} catch (error) {
|
|
|
|
Logger.log(error.message)
|
|
|
|
}
|
|
|
|
}
|