-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add comment to config #3345
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -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') | ||
) | ||
} |
9 changes: 5 additions & 4 deletions
9
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
14 changes: 4 additions & 10 deletions
14
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 |
---|---|---|
@@ -1,16 +1,10 @@ | ||
import { CowSwapWidgetParams } from '@cowprotocol/widget-lib' | ||
|
||
const PARTNER_FEE_COMMENT = 'Please contact https://cowprotocol.typeform.com/to/rONXaxHV to enable your partner fee.' | ||
import { SANITIZE_PARAMS } from '../const' | ||
|
||
export function sanitizeParameters(params: CowSwapWidgetParams): string { | ||
const sanitizedParams = { | ||
export function sanitizeParameters(params: CowSwapWidgetParams) { | ||
return { | ||
...params, | ||
provider: `<eip-1193 provider>`, | ||
partnerFeeBips: '50', | ||
...SANITIZE_PARAMS, | ||
} | ||
|
||
return JSON.stringify(sanitizedParams, null, 4).replace( | ||
'"partnerFeeBips', | ||
`// ${PARTNER_FEE_COMMENT}\n "partnerFeeBips` | ||
) | ||
} |
9 changes: 5 additions & 4 deletions
9
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
this helps to solve the issue serialising the provider, see description of the PR