Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.

Release/2.19.0 #396

Merged
merged 13 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-transform-runtime",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-optional-chaining",
[
"babel-plugin-styled-components",
{
Expand Down
12 changes: 11 additions & 1 deletion .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,17 @@ module.exports = {
// enable rules override sparingly
// only if storybook can't transpile something
// rules: custom.module.rules,
rules: rulesWithMarkdownAndImages,
rules: [
...rulesWithMarkdownAndImages,
{
test: /\.m?jsx?$/,
loader: 'babel-loader',
options: {
plugins: ['@babel/plugin-proposal-optional-chaining'],
},
include: /node_modules\/@cowprotocol/,
},
],
},
resolve: {
...config.resolve,
Expand Down
8 changes: 8 additions & 0 deletions getWebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ function getWebpackConfig({ apps = [], config = {}, envVars = {}, defineVars = {
},
],
},
{
test: /\.m?jsx?$/,
loader: 'babel-loader',
options: {
plugins: ['@babel/plugin-proposal-optional-chaining'],
},
include: /node_modules\/@cowprotocol/,
},
{
test: /\.jsx?$/,
exclude: /node_modules/,
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cowprotocol/explorer",
"version": "2.18.2",
"version": "2.19.0",
"description": "",
"main": "src/index.js",
"sideEffects": false,
Expand Down Expand Up @@ -46,9 +46,9 @@
"author": "",
"dependencies": {
"@apollo/client": "^3.1.5",
"@cowprotocol/app-data": "0.0.1-RC.5",
"@cowprotocol/app-data": "v0.1.0-alpha.0",
"@cowprotocol/contracts": "1.3.1",
"@cowprotocol/cow-sdk": "^1.0.2-RC.7",
"@cowprotocol/cow-sdk": "^2.0.0-alpha.4",
"@fortawesome/fontawesome-svg-core": "^6.1.2",
"@fortawesome/free-regular-svg-icons": "^6.1.2",
"@fortawesome/free-solid-svg-icons": "^6.1.2",
Expand Down Expand Up @@ -101,6 +101,7 @@
"devDependencies": {
"@babel/core": "^7.9.4",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/plugin-proposal-optional-chaining": "^7.21.0",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-transform-runtime": "^7.8.3",
"@babel/preset-env": "^7.9.4",
Expand Down
1 change: 1 addition & 0 deletions src/Console.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const ConsoleWrapper = styled.div`
overflow: auto;
z-index: 9999;
`

const ButtonGroup = styled.div`
position: fixed;
bottom: 1.2rem;
Expand Down
19 changes: 9 additions & 10 deletions src/api/operator/accountOrderUtils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { OrderMetaData, SupportedChainId } from '@cowprotocol/cow-sdk'
import { COW_SDK } from 'const'
import { SupportedChainId } from '@cowprotocol/cow-sdk'

import { GetAccountOrdersParams, RawOrder } from './types'
import { prodOrderBookSDK, stagingOrderBookSDK } from 'cowSdk'
import { EnrichedOrder } from '@cowprotocol/cow-sdk'

/**
* Gets a list of orders of one user paginated
Expand All @@ -27,11 +28,9 @@ export async function getAccountOrders(params: GetAccountOrdersParams): Promise<
}

const [prodOrders, barnOrders] = await Promise.all([
state.prodHasNext
? COW_SDK.cowApi.getOrders({ owner, offset, limit: limitPlusOne }, { chainId: networkId, env: 'prod' })
: [],
state.prodHasNext ? prodOrderBookSDK.getOrders({ owner, offset, limit: limitPlusOne }, { chainId: networkId }) : [],
state.barnHasNext
? COW_SDK.cowApi.getOrders({ owner, offset, limit: limitPlusOne }, { chainId: networkId, env: 'staging' })
? stagingOrderBookSDK.getOrders({ owner, offset, limit: limitPlusOne }, { chainId: networkId })
: [],
])

Expand Down Expand Up @@ -75,17 +74,17 @@ type CacheKey = {
}

type CacheState = {
merged: Map<number, OrderMetaData[]>
unmerged: OrderMetaData[]
merged: Map<number, EnrichedOrder[]>
unmerged: EnrichedOrder[]
prodPage: number
prodHasNext: boolean
barnPage: number
barnHasNext: boolean
}

const emptyState = (): CacheState => ({
merged: new Map<number, OrderMetaData[]>(),
unmerged: [] as OrderMetaData[],
merged: new Map<number, EnrichedOrder[]>(),
unmerged: [] as EnrichedOrder[],
prodPage: 0,
prodHasNext: true,
barnPage: 0,
Expand Down
23 changes: 13 additions & 10 deletions src/api/operator/operatorApi.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { GetTradesParams } from '@cowprotocol/cow-sdk'
import { Network } from 'types'
import { COW_SDK } from 'const'
import { buildSearchString } from 'utils/url'
import { isProd, isStaging } from 'utils/env'

import { GetOrderParams, GetOrdersParams, RawOrder, RawTrade, GetTxOrdersParams, WithNetworkId } from './types'
import { fetchQuery } from 'api/baseApi'
import { prodOrderBookSDK, stagingOrderBookSDK } from 'cowSdk'
import { Address, UID } from '@cowprotocol/cow-sdk'

export { getAccountOrders } from './accountOrderUtils'

Expand Down Expand Up @@ -64,7 +64,7 @@ function _get(networkId: Network, url: string): Promise<Response> {
export async function getOrder(params: GetOrderParams): Promise<RawOrder | null> {
const { networkId, orderId } = params

return COW_SDK.cowApi.getOrder(orderId, { chainId: networkId })
return prodOrderBookSDK.getOrderMultiEnv(orderId, { chainId: networkId })
}

/**
Expand Down Expand Up @@ -108,8 +108,8 @@ export async function getTxOrders(params: GetTxOrdersParams): Promise<RawOrder[]

// sdk not merging array responses yet
const orders = await Promise.all([
COW_SDK.cowApi.getTxOrders(txHash, { chainId: networkId, env: 'prod' }),
COW_SDK.cowApi.getTxOrders(txHash, { chainId: networkId, env: 'staging' }),
prodOrderBookSDK.getTxOrders(txHash, { chainId: networkId }),
stagingOrderBookSDK.getTxOrders(txHash, { chainId: networkId }),
])

return [...orders[0], ...orders[1]]
Expand All @@ -124,16 +124,19 @@ export async function getTxOrders(params: GetTxOrdersParams): Promise<RawOrder[]
*
* Both filters cannot be used at the same time
*/
export async function getTrades(params: GetTradesParams & WithNetworkId): Promise<RawTrade[]> {
export async function getTrades(
params: {
owner?: Address
orderId?: UID
} & WithNetworkId,
): Promise<RawTrade[]> {
const { networkId, owner, orderId } = params
console.log(`[getTrades] Fetching trades on network ${networkId} with filters`, { owner, orderId })

// sdk not merging array responses yet
const trades = await Promise.all([
// @ts-expect-error to avoid duplication we just pass both parameters
COW_SDK.cowApi.getTrades({ owner, orderId }, { chainId: networkId, env: 'prod' }),
// @ts-expect-error to avoid duplication we just pass both parameters
COW_SDK.cowApi.getTrades({ owner, orderId }, { chainId: networkId, env: 'staging' }),
prodOrderBookSDK.getTrades({ owner, orderId }, { chainId: networkId }),
stagingOrderBookSDK.getTrades({ owner, orderId }, { chainId: networkId }),
])

return [...trades[0], ...trades[1]]
Expand Down
8 changes: 2 additions & 6 deletions src/api/operator/types.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import BigNumber from 'bignumber.js'

import { TokenErc20 } from '@gnosis.pm/dex-js'

import { OrderKind } from '@cowprotocol/contracts'
import { OrderMetaData, TradeMetaData } from '@cowprotocol/cow-sdk'

import { Network } from 'types'
import { EnrichedOrder, OrderKind, Trade as TradeMetaData } from '@cowprotocol/cow-sdk'

export type OrderID = string
export type TxHash = string

export type OrderStatus = 'open' | 'filled' | 'cancelled' | 'cancelling' | 'expired' | 'signing'
export type RawOrderStatusFromAPI = 'presignaturePending' | 'open' | 'fullfilled' | 'cancelled' | 'expired'

// Raw API response
export type RawOrder = OrderMetaData
export type RawOrder = EnrichedOrder
/**
* Enriched Order type.
* Applies some transformations on the raw api data.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useEffect, useState } from 'react'
import { HistogramData, UTCTimestamp } from 'lightweight-charts'
import { COW_SDK } from 'const'
import { useNetworkId } from 'state/network'
import { Network } from 'types'
import { VolumePeriod } from './VolumeChartWidget'
import { VolumeDataResponse } from './VolumeChart'
import { subgraphApiSDK } from 'cowSdk'

type RawVolumeItem = {
timestamp: number
Expand Down Expand Up @@ -38,7 +38,7 @@ export function useGetVolumeData(volumeTimePeriod = VolumePeriod.DAILY): VolumeD
}

async function getLastHoursData(network: Network): Promise<RawVolumeItem[]> {
const data = await COW_SDK.cowSubgraphApi.getLastHoursVolume(48, { chainId: network })
const data = await subgraphApiSDK.getLastHoursVolume(48, { chainId: network })

return (data?.hourlyTotals as RawVolumeItem[]) || []
}
Expand All @@ -52,7 +52,7 @@ async function getLastDaysData(
[VolumePeriod.MONTHLY]: 30 * 2,
[VolumePeriod.YEARLY]: 365 * 2,
}
const data = await COW_SDK.cowSubgraphApi.getLastDaysVolume(days[period], { chainId: network })
const data = await subgraphApiSDK.getLastDaysVolume(days[period], { chainId: network })

return (data?.dailyTotals as RawVolumeItem[]) || []
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { gql } from '@apollo/client'
import { COW_SDK } from 'const'
import { useCallback, useEffect, useState } from 'react'
import { useNetworkId } from 'state/network'
import { Network } from 'types'
import { subgraphApiSDK } from 'cowSdk'

export interface BatchInfo {
lastBatchDate: Date
Expand Down Expand Up @@ -87,7 +87,7 @@ export function useGetSummaryData(): TotalSummaryResponse | undefined {

const fetchAndBuildSummary = useCallback(async () => {
setSummary((summary) => ({ ...summary, isLoading: true }))
COW_SDK.cowSubgraphApi.runQuery(summaryQuery, undefined, { chainId: network }).then((data: SummaryQuery) => {
subgraphApiSDK.runQuery(summaryQuery, undefined, { chainId: network }).then((data: SummaryQuery) => {
const summary = buildSummary(data)
setSummary({ ...summary, isLoading: false })
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import React, { useState, useEffect, useRef, useCallback } from 'react'
import CytoscapeComponent from 'react-cytoscapejs'
import styled, { useTheme } from 'styled-components'
import BigNumber from 'bignumber.js'
import { OrderKind } from '@cowprotocol/contracts'
import {
faRedo,
faDiceOne,
Expand Down Expand Up @@ -35,6 +34,7 @@ import { EmptyItemWrapper } from 'components/common/StyledUserDetailsTable'
import useWindowSizes from 'hooks/useWindowSizes'
import { layouts, LayoutNames } from './layouts'
import { DropdownOption, DropdownPosition } from 'apps/explorer/components/common/Dropdown'
import { OrderKind } from '@cowprotocol/cow-sdk'

Cytoscape.use(popper)
Cytoscape.use(noOverlap)
Expand Down
2 changes: 1 addition & 1 deletion src/apps/explorer/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const DOCS_LINK = 'https://docs.cow.fi'
export const PROTOCOL_LINK = 'https://cow.fi'
export const CONTRACTS_CODE_LINK = 'https://github.com/cowprotocol/contracts'
export const DISCORD_LINK = 'https://discord.gg/cowprotocol'
export const DUNE_DASHBOARD_LINK = 'https://dune.com/cowprotocol/Gnosis-Protocol-V2'
export const DUNE_DASHBOARD_LINK = 'https://dune.com/cowprotocol/cowswap'
export const TWITTER_LINK = 'https://twitter.com/CoWSwap'
export const COWWIKI_LINK = 'https://en.wikipedia.org/wiki/Coincidence_of_wants'
export const GNOSIS_FORUM_ROADTODECENT_LINK = 'https://forum.gnosis.io/t/gpv2-road-to-decentralization/1245'
Expand Down
14 changes: 8 additions & 6 deletions src/apps/explorer/pages/AppData/EncodePage.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useCallback, useEffect, useState } from 'react'
import Form, { FormValidation } from '@rjsf/core'
import { JSONSchema7 } from 'json-schema'
import { IpfsHashInfo } from '@cowprotocol/cow-sdk'
import { COW_SDK, DEFAULT_IPFS_READ_URI } from 'const'
import { IpfsHashInfo } from '@cowprotocol/app-data'
import { DEFAULT_IPFS_READ_URI } from 'const'
import { RowWithCopyButton } from 'components/common/RowWithCopyButton'
import Spinner from 'components/common/Spinner'
import AppDataWrapper from 'components/common/AppDataWrapper'
Expand All @@ -22,6 +22,7 @@ import {
} from './config'
import { TabData, TabView } from '.'
import { IpfsWrapper } from './styled'
import { metadataApiSDK } from 'cowSdk'

type EncodeProps = {
tabData: TabData
Expand Down Expand Up @@ -51,6 +52,8 @@ const EncodePage: React.FC<EncodeProps> = ({ tabData, setTabData, handleTabChang
const formRef = React.useRef<Form<FormProps>>(null)
const ipfsFormRef = React.useRef<Form<FormProps>>(null)

const isDisabled = !appDataForm.metadata?.orderClass?.orderClass || disabledAppData

useEffect(() => {
const fetchSchema = async (): Promise<void> => {
const latestSchema = await getSchema()
Expand Down Expand Up @@ -134,7 +137,7 @@ const EncodePage: React.FC<EncodeProps> = ({ tabData, setTabData, handleTabChang
const onSubmit = useCallback(async ({ formData }: FormProps): Promise<void> => {
setIsLoading(true)
try {
const hashInfo = await COW_SDK.metadataApi.calculateAppDataHash(handleFormatData(formData))
const hashInfo = await metadataApiSDK.calculateAppDataHash(handleFormatData(formData))
setIpfsHashInfo(hashInfo)
} catch (e) {
setError(e.message)
Expand All @@ -156,8 +159,7 @@ const EncodePage: React.FC<EncodeProps> = ({ tabData, setTabData, handleTabChang
if (!ipfsHashInfo) return
setIsLoading(true)
try {
await COW_SDK.updateContext({ ipfs: formData })
await COW_SDK.metadataApi.uploadMetadataDocToIpfs(handleFormatData(appDataForm))
await metadataApiSDK.uploadMetadataDocToIpfs(handleFormatData(appDataForm), formData)
setIsDocUploaded(true)
} catch (e) {
if (INVALID_IPFS_CREDENTIALS.includes(e.message)) {
Expand Down Expand Up @@ -214,7 +216,7 @@ const EncodePage: React.FC<EncodeProps> = ({ tabData, setTabData, handleTabChang
schema={schema}
uiSchema={uiSchema}
>
<button className="btn btn-info" disabled={disabledAppData} type="submit">
<button className="btn btn-info" disabled={isDisabled} type="submit">
GENERATE APPDATA DOC
</button>
</Form>
Expand Down
2 changes: 1 addition & 1 deletion src/apps/explorer/pages/AppData/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const INVALID_IPFS_CREDENTIALS = [
export type FormProps = Record<string, any>

export const getSchema = async (): Promise<JSONSchema7> => {
const latestSchema = (await getAppDataSchema(LATEST_APP_DATA_VERSION)).default as JSONSchema7
const latestSchema = (await getAppDataSchema(LATEST_APP_DATA_VERSION)) as JSONSchema7
deleteAllPropertiesByName(latestSchema, 'examples')
deleteAllPropertiesByName(latestSchema, '$id')
return formatSchema(latestSchema)
Expand Down
4 changes: 2 additions & 2 deletions src/components/AppData/DecodeAppData.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useCallback, useEffect } from 'react'
import AppDataWrapper from 'components/common/AppDataWrapper'
import { AnyAppDataDocVersion } from '@cowprotocol/cow-sdk'
import { AnyAppDataDocVersion } from '@cowprotocol/app-data'
import { RowWithCopyButton } from 'components/common/RowWithCopyButton'
import { Notification } from 'components/Notification'
import Spinner from 'components/common/Spinner'
Expand All @@ -9,7 +9,7 @@ import { getCidHashFromAppData, getDecodedAppData } from 'hooks/useAppData'
import useSafeState from 'hooks/useSafeState'

type Props = {
appData: number
appData: string
showExpanded?: boolean
}

Expand Down
3 changes: 1 addition & 2 deletions src/components/common/TradeOrderType.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React from 'react'
import styled from 'styled-components'
import { OrderKind } from '@cowprotocol/contracts'

import { capitalize } from 'utils'
import { OrderKind } from '@cowprotocol/cow-sdk'

const TradeTypeWrapper = styled.div`
span {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ONE_BIG_NUMBER } from 'const'
import { FilledProgress, Props } from '.'

import { RICH_ORDER } from '../../../../test/data'
import { OrderKind } from '@cowprotocol/contracts'
import { OrderKind } from '@cowprotocol/cow-sdk'

export default {
title: 'Orders/FilledProgress',
Expand Down
3 changes: 2 additions & 1 deletion src/components/orders/OrderDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export const OrderDetails: React.FC<Props> = (props) => {

// Only set txHash for fillOrKill orders, if any
// Partially fillable order will have a tab only for the trades
const txHash = order && !order.partiallyFillable && trades && trades.length === 1 ? trades[0].txHash : undefined
const txHash =
(order && !order.partiallyFillable && trades && trades.length === 1 ? trades[0].txHash : undefined) || undefined

// Avoid redirecting until another network is searched again
useEffect(() => {
Expand Down
Loading