-
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.
- Loading branch information
Showing
7 changed files
with
104 additions
and
40 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 |
---|---|---|
@@ -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'] |
40 changes: 40 additions & 0 deletions
40
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,40 @@ | ||
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) | ||
|
||
// const formattedParams = JSON.stringify(sanitizeParameters(params), 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