-
Notifications
You must be signed in to change notification settings - Fork 101
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 #3351 from cowprotocol/release/1.49.0
chore: pull changes from 1.49.0 into develop
- Loading branch information
Showing
11 changed files
with
137 additions
and
49 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
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,27 @@ | ||
import { CowSwapWidgetParams } from '@cowprotocol/widget-lib' | ||
|
||
export const COMMENTS_BEFORE_PARAMS = ` Fill this form https://cowprotocol.typeform.com/to/rONXaxHV once you pick your "appKey"` | ||
|
||
export const COMMENTS_BY_PARAM_NAME: Record<string, string> = { | ||
appKey: 'Name of your app (max 50 characters, e.g. "Pig Swap")', | ||
width: 'Width in pixels (or 100% to use all available space)', | ||
provider: | ||
'Ethereum EIP-1193 provider. For a quick test, you can pass `window.ethereum`, but consider using something like https://web3modal.com', | ||
chainId: '1 (Mainnet), 5 (Goerli), 100 (Gnosis)', | ||
theme: 'light or dark', | ||
tradeType: 'swap, limit or advanced', | ||
tradeAssets: 'Selected assets and amounts (e.g. COW-USDC)', | ||
enabledTradeTypes: 'swap, limit and/or advanced', | ||
partnerFeeBips: 'Fill the form above if you are interested', | ||
} | ||
|
||
export const VALUES_BY_PARAM_NAME: Record<string, string> = { | ||
provider: 'window.ethereum', | ||
} | ||
|
||
export const SANITIZE_PARAMS = { | ||
provider: 'EIP-1271 Provider', | ||
partnerFeeBips: '50', | ||
} | ||
|
||
export const REMOVE_PARAMS: (keyof CowSwapWidgetParams)[] = ['env'] |
38 changes: 38 additions & 0 deletions
38
apps/widget-configurator/src/app/embedDialog/utils/formatParameters.ts
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,38 @@ | ||
import { CowSwapWidgetParams } from '@cowprotocol/widget-lib' | ||
|
||
import { sanitizeParameters } from './sanitizeParameters' | ||
|
||
import { COMMENTS_BY_PARAM_NAME, REMOVE_PARAMS, VALUES_BY_PARAM_NAME } from '../const' | ||
|
||
export function formatParameters(params: CowSwapWidgetParams, padLeft = 0): string { | ||
const paramsSanitized = sanitizeParameters(params) | ||
REMOVE_PARAMS.forEach((propName) => { | ||
delete paramsSanitized[propName] | ||
}) | ||
const formattedParams = JSON.stringify(paramsSanitized, null, 4) | ||
|
||
// Add comments | ||
const resultWithComments = Object.keys(COMMENTS_BY_PARAM_NAME).reduce((acc, propName) => { | ||
return acc.replace(new RegExp(`"${propName}".*$`, 'gm'), `$& // ${COMMENTS_BY_PARAM_NAME[propName]}`) | ||
}, formattedParams) | ||
|
||
// Add values | ||
const resultWithValues = Object.keys(VALUES_BY_PARAM_NAME).reduce((acc, propName) => { | ||
return acc.replace(new RegExp(`("${propName}".* )(".*")(.*)$`, 'gm'), `$1${VALUES_BY_PARAM_NAME[propName]}$3`) | ||
}, resultWithComments) | ||
|
||
if (padLeft === 0) { | ||
return resultWithValues | ||
} | ||
|
||
// Add indentation | ||
const lines = resultWithValues.split('\n') | ||
return ( | ||
lines[0] + | ||
'\n' + | ||
lines | ||
.slice(1) | ||
.map((line) => `${' '.repeat(padLeft)}${line}`) | ||
.join('\n') | ||
) | ||
} |
12 changes: 6 additions & 6 deletions
12
apps/widget-configurator/src/app/embedDialog/utils/reactExample.ts
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
10 changes: 10 additions & 0 deletions
10
apps/widget-configurator/src/app/embedDialog/utils/sanitizeParameters.ts
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,10 @@ | ||
import { CowSwapWidgetParams } from '@cowprotocol/widget-lib' | ||
|
||
import { SANITIZE_PARAMS } from '../const' | ||
|
||
export function sanitizeParameters(params: CowSwapWidgetParams) { | ||
return { | ||
...params, | ||
...SANITIZE_PARAMS, | ||
} | ||
} |
12 changes: 6 additions & 6 deletions
12
apps/widget-configurator/src/app/embedDialog/utils/vanilaNpmExample.ts
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