-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3638 from cowprotocol/develop
chore: add three fixes to the release
- Loading branch information
Showing
7 changed files
with
83 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
# Explorer | ||
# CoW Protocol Explorer | ||
|
||
Allows you to explore the protocol orders and trades. | ||
|
||
## 🏃♀️ Run it locally | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { AnyAppDataDocVersion } from '@cowprotocol/app-data' | ||
|
||
/** | ||
* Decode appData from a string to a AnyAppDataDocVersion instance | ||
* Keep in mind it can be a valid JSON but not necessarily a valid AppDataDoc | ||
* | ||
* Returns undefined if the given appData is not a valid JSON | ||
* When `throwOnError` is true, it will throw an error if the given appData is not a valid JSON | ||
*/ | ||
export function decodeFullAppData( | ||
appData: string | null | undefined, | ||
throwOnError?: true, | ||
): AnyAppDataDocVersion | undefined { | ||
if (!appData) { | ||
return undefined | ||
} | ||
|
||
try { | ||
return JSON.parse(appData) | ||
} catch (e) { | ||
if (throwOnError) { | ||
throw e | ||
} | ||
|
||
console.info('[decodeFullAppData] given appData is not a valid JSON', appData) | ||
return undefined | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { latest } from '@cowprotocol/app-data' | ||
import { OrderClass } from '@cowprotocol/cow-sdk' | ||
import { Order } from 'api/operator' | ||
import { decodeFullAppData } from 'utils/decodeFullAppData' | ||
|
||
/** | ||
* UiOrderType based on appData, falling back to backend order class. | ||
* | ||
* Similar to CoW Swap, but not exactly like it. | ||
* | ||
* Here, MARKET remains as MARKET, while on CoW Swap it's translated to SWAP. | ||
* Also, we keep the LIQUIDITY order type as it, while there it's translated to LIMIT. | ||
* | ||
* In summary, it matches 1:1 appData.metadata.orderClass.orderClass enum | ||
*/ | ||
export enum UiOrderType { | ||
MARKET = 'MARKET', | ||
LIMIT = 'LIMIT', | ||
LIQUIDITY = 'LIQUIDITY', | ||
TWAP = 'TWAP', | ||
} | ||
|
||
const API_ORDER_CLASS_TO_UI_ORDER_TYPE_MAP: Record<OrderClass, UiOrderType> = { | ||
[OrderClass.MARKET]: UiOrderType.MARKET, | ||
[OrderClass.LIMIT]: UiOrderType.LIMIT, | ||
[OrderClass.LIQUIDITY]: UiOrderType.LIQUIDITY, | ||
} | ||
|
||
export function getUiOrderType({ fullAppData, class: orderClass }: Order): UiOrderType { | ||
const appData = decodeFullAppData(fullAppData) | ||
|
||
const appDataOrderClass = appData?.metadata?.orderClass as latest.OrderClass | undefined | ||
const typeFromAppData = UiOrderType[appDataOrderClass?.orderClass.toUpperCase() || ''] | ||
|
||
// 1. AppData info has priority as it's what's more precise | ||
if (typeFromAppData) { | ||
return typeFromAppData | ||
} | ||
|
||
// 3. Fallback to API classification. | ||
// Least precise as it doesn't distinguish twap type and uses backend logic which doesn't match frontend's classification | ||
return API_ORDER_CLASS_TO_UI_ORDER_TYPE_MAP[orderClass] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0d3547b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
widget-configurator – ./
widget-configurator-cowswap.vercel.app
widget-configurator-seven.vercel.app
widget-configurator-git-main-cowswap.vercel.app
widget.cow.fi
0d3547b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
cosmos – ./
cosmos.cow.fi
cosmos-git-main-cowswap.vercel.app
cosmos-cowswap.vercel.app
cowswap-seven.vercel.app