-
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.
feat(hooks-store): new design & refactoring (#4859)
* chore: update eslint * refactor: align hook dapp files structure * refactor: fix files structure * refactor: fix dependency inversion (hooksStore -> swap) * refactor: separate hooks store modal from buttons * chore: fix circular dependency * refactor: rename HooksStoreModal to HookRegistryList * refactor: make hook dapp context specific to dapp * refactor: extract pure components * refactor: remove outputTokens * feat(hooks-store): persist hooks into localStorage * feat(hooks-store): add styles * feat(hooks-store): style hook dapps * feat(hooks-store): style applied hook item * chore: fix code style * chore: fix circular deps * chore: fix code style * fix(trade): hide top content for wrap flow * fix(hooks-store): split state by chainId * fix(hooks-store): skip custom hooks in swap widget * chore(hooks-store): add uid to hook item title * fix(hooks-store): fix appData module dependencies * fix(hooks-store): bind state to account * fix(hooks-store): allow hooks in smart-contract wallets * chore: fix typo * refactor: move hooks types to the module * chore: fix lint * fix: permit data loading * feat(hooks-store): general hooks widget styling and DnD (#4868) * chore: test commit * chore: test commit --------- Co-authored-by: fairlight <[email protected]>
- Loading branch information
1 parent
8cfd70b
commit 1b989fa
Showing
81 changed files
with
1,789 additions
and
1,067 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
54 changes: 54 additions & 0 deletions
54
apps/cowswap-frontend/src/modules/hooksStore/containers/HookDappContainer/index.tsx
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,54 @@ | ||
import { useMemo } from 'react' | ||
|
||
import { Command } from '@cowprotocol/types' | ||
import { useWalletInfo } from '@cowprotocol/wallet' | ||
|
||
import { useAddHook } from '../../hooks/useAddHook' | ||
import { useEditHook } from '../../hooks/useEditHook' | ||
import { useHookById } from '../../hooks/useHookById' | ||
import { HookDapp, HookDappContext as HookDappContextType } from '../../types/hooks' | ||
import { isHookDappIframe } from '../../utils' | ||
|
||
interface HookDappContainerProps { | ||
dapp: HookDapp | ||
isPreHook: boolean | ||
onDismiss: Command | ||
onDismissModal: Command | ||
hookToEdit?: string | ||
} | ||
|
||
export function HookDappContainer({ dapp, isPreHook, onDismiss, onDismissModal, hookToEdit }: HookDappContainerProps) { | ||
const { chainId, account } = useWalletInfo() | ||
const addHook = useAddHook(dapp, isPreHook) | ||
const editHook = useEditHook() | ||
|
||
const hookToEditDetails = useHookById(hookToEdit, isPreHook) | ||
|
||
const context = useMemo<HookDappContextType>(() => { | ||
return { | ||
chainId, | ||
account, | ||
hookToEdit: hookToEditDetails, | ||
editHook: (...args) => { | ||
editHook(...args) | ||
onDismiss() | ||
}, | ||
addHook: (hookToAdd) => { | ||
const hook = addHook(hookToAdd) | ||
onDismiss() | ||
|
||
return hook | ||
}, | ||
close: onDismissModal, | ||
} | ||
}, [addHook, editHook, onDismiss, onDismissModal, chainId, account, hookToEditDetails]) | ||
|
||
const dappProps = useMemo(() => ({ context, dapp, isPreHook }), [context, dapp, isPreHook]) | ||
|
||
if (isHookDappIframe(dapp)) { | ||
// TODO: Create iFrame | ||
return <>{dapp.name}</> | ||
} | ||
|
||
return dapp.component(dappProps) | ||
} |
Oops, something went wrong.