-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(permit): fetch token name from chain (#3374)
* chore: add PermitUtils type `unsupported` * chore: apply PermitInfo type to consumers * feat: add helper method to only check whether token is permittable useTokenSupportsPermit * refactor: rename useIsTokenPermittable to usePermitInfo * feat: add utils fn isSupportedPermitInfo * refactor: move inner private method getContract to external utils fn * feat: add minimal erc20 `name` method abi * feat: add utils fn `getTokenName` * feat: fetch token name when fetching permit info * feat: make tokenName optional on GetTokenPermitInfoParams * feat: migrate preGenerated permit info to new format * chore: more tokenName optional changes * chore: add TODOs * refactor: return error rather than throwing * chore: bump permit-utils package version * chore: bump permittableTokens atom version to v2 * refactor: use isSupportedPermitInfo in a few places * chore: do a type guard in the helper fn so there's no need for casting * chore: return error when name fetching fails due to network issues * chore: identify earlier when token is not dai-like and return received error * chore: only log debug msg if not dai-like * chore: mark some known error types as permanent errors * chore: log also tokenName when possible * chore: use a regex to catch connection issues * chore: use const for default obj return to avoid re-renders * refactor: remove redundant check. It's covered by isSupportedPermitInfo * chore: set permit-utils version to 0.0.1
- Loading branch information
1 parent
24601df
commit 578df82
Showing
28 changed files
with
245 additions
and
90 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
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
20 changes: 20 additions & 0 deletions
20
apps/cowswap-frontend/src/modules/permit/hooks/useTokenSupportsPermit.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,20 @@ | ||
import { isSupportedPermitInfo } from '@cowprotocol/permit-utils' | ||
import { Currency } from '@uniswap/sdk-core' | ||
|
||
import { Nullish } from 'types' | ||
|
||
import { TradeType } from 'modules/trade' | ||
|
||
import { usePermitInfo } from './usePermitInfo' | ||
|
||
/** | ||
* Whether the token supports permit for given trade type | ||
* | ||
* @param token | ||
* @param tradeType | ||
*/ | ||
export function useTokenSupportsPermit(token: Nullish<Currency>, tradeType: Nullish<TradeType>): boolean { | ||
const permitInfo = usePermitInfo(token, tradeType) | ||
|
||
return isSupportedPermitInfo(permitInfo) | ||
} |
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,8 +1,9 @@ | ||
export * from './hooks/useAccountAgnosticPermitHookData' | ||
export * from './hooks/useGeneratePermitHook' | ||
export * from './hooks/useIsTokenPermittable' | ||
export * from './hooks/usePermitInfo' | ||
export * from './hooks/useOrdersPermitStatus' | ||
export * from './hooks/usePermitCompatibleTokens' | ||
export * from './hooks/useTokenSupportsPermit' | ||
export * from './types' | ||
export * from './updaters/PendingPermitUpdater' | ||
export * from './utils/handlePermit' |
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
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,16 @@ | ||
[ | ||
{ | ||
"constant": true, | ||
"inputs": [], | ||
"name": "name", | ||
"outputs": [ | ||
{ | ||
"name": "", | ||
"type": "string" | ||
} | ||
], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
} | ||
] |
Oops, something went wrong.