Skip to content
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(hooks-store): add dapp id to hook callData #4920

Merged
merged 95 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
cbd8fa0
feat(hooks-store): add order params and signer to hook dapp context
shoom3301 Sep 12, 2024
d02ed5b
feat(hooks-store): setup blank app for iframe hook
shoom3301 Sep 12, 2024
56e303d
refactor: generalise CowEventEmitter in order to reuse it in hook dapps
shoom3301 Sep 12, 2024
21b4c01
feat: iframe transport library
shoom3301 Sep 13, 2024
87c424f
feat: use iframe-transport lib for widget
shoom3301 Sep 13, 2024
f1a256a
feat: hook-dapp-lib for hook-dapps in iframe
shoom3301 Sep 13, 2024
f0f438a
feat(hooks-store): add omnibridge hook-dapp via iframe
shoom3301 Sep 13, 2024
21c194a
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 Sep 13, 2024
e000886
Merge branch 'feat/hooks-iframe-app' of https://github.com/cowprotoco…
shoom3301 Sep 13, 2024
46544e0
Merge branch 'feat/hooks-iframe-app-1' of https://github.com/cowproto…
shoom3301 Sep 13, 2024
086ad26
Merge branch 'feat/hooks-iframe-app-2' of https://github.com/cowproto…
shoom3301 Sep 13, 2024
5990bbd
Merge branch 'feat/hooks-iframe-app-3' of https://github.com/cowproto…
shoom3301 Sep 13, 2024
4ae2f76
Merge branch 'feat/hooks-iframe-app-4' of https://github.com/cowproto…
shoom3301 Sep 13, 2024
ffeb18c
Merge branch 'feat/hooks-iframe-app-5' of https://github.com/cowproto…
shoom3301 Sep 13, 2024
ecbe52b
Merge branch 'feat/hooks-iframe-app-6' of https://github.com/cowproto…
shoom3301 Sep 13, 2024
64ef4c6
Merge branch 'feat/hooks-iframe-app-7' of https://github.com/cowproto…
shoom3301 Sep 13, 2024
896a856
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 Sep 17, 2024
5a610da
Merge branch 'feat/hooks-iframe-app' of https://github.com/cowprotoco…
shoom3301 Sep 17, 2024
e5b74c5
Merge branch 'feat/hooks-iframe-app-1' of https://github.com/cowproto…
shoom3301 Sep 17, 2024
50fa90a
chore: specify key
shoom3301 Sep 17, 2024
1158709
Merge branch 'feat/hooks-iframe-app-3' of https://github.com/cowproto…
shoom3301 Sep 17, 2024
7ebe545
Merge branch 'feat/hooks-iframe-app-4' of https://github.com/cowproto…
shoom3301 Sep 17, 2024
d594f60
docs: doc @cowprotocol/hook-dapp-lib
shoom3301 Sep 17, 2024
d88b805
chore: revert ff
shoom3301 Sep 17, 2024
6939abf
Merge branch 'feat/hooks-iframe-app-6' of https://github.com/cowproto…
shoom3301 Sep 17, 2024
5baf090
refactor: simplify hooks store state
shoom3301 Sep 17, 2024
2ce7906
chore: fix build
shoom3301 Sep 17, 2024
313e53f
chore: fix build
shoom3301 Sep 17, 2024
66a93b3
chore: remove boilerplate
shoom3301 Sep 18, 2024
3bc7a22
Update libs/hook-dapp-lib/README.md
shoom3301 Sep 18, 2024
6bfde94
chore: fix package json
shoom3301 Sep 18, 2024
adb1ef4
Merge branch 'feat/hooks-iframe-app-6' of https://github.com/cowproto…
shoom3301 Sep 18, 2024
c09c864
chore: remove wrong permit check
shoom3301 Sep 18, 2024
d4bb6eb
feat: add isSmartContract to hook dapp context
shoom3301 Sep 18, 2024
f6790b6
refactor: fix WidgetEthereumProvider deps
shoom3301 Sep 18, 2024
7f54a1f
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 Sep 18, 2024
6166835
Merge branch 'feat/hooks-iframe-app' of https://github.com/cowprotoco…
shoom3301 Sep 18, 2024
bc5a0c3
Merge branch 'feat/hooks-iframe-app-1' of https://github.com/cowproto…
shoom3301 Sep 18, 2024
c6d4b86
Merge branch 'feat/hooks-iframe-app-3' of https://github.com/cowproto…
shoom3301 Sep 18, 2024
29f4aae
Merge branch 'feat/hooks-iframe-app-4' of https://github.com/cowproto…
shoom3301 Sep 18, 2024
ef9fedc
Merge branch 'feat/hooks-iframe-app-6' of https://github.com/cowproto…
shoom3301 Sep 18, 2024
352a7b4
chore: pull develop
shoom3301 Sep 18, 2024
3c761df
chore: hook dapp lib deps
shoom3301 Sep 18, 2024
82b3bce
chore: fix permit hook adding
shoom3301 Sep 19, 2024
ca81b37
feat(hooks-store): callbacks to changes sell buy tokens
shoom3301 Sep 19, 2024
2b424da
feat(hooks-store): import external hook-dapps
shoom3301 Sep 19, 2024
193f54b
fix: rpc bridge duplication
shoom3301 Sep 19, 2024
6d3cdb6
chore: make conditions optional
shoom3301 Sep 19, 2024
f02d802
chore: polish UI
shoom3301 Sep 19, 2024
6b4295a
chore: fix lint
shoom3301 Sep 20, 2024
77a875a
refactor(events): generalise SimpleCowEventEmitter for reusing porpos…
shoom3301 Sep 20, 2024
f9efacc
Merge branch 'feat/hooks-iframe-app' of https://github.com/cowprotoco…
shoom3301 Sep 20, 2024
54f8982
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 Sep 20, 2024
16890ef
chore: fix lint
shoom3301 Sep 20, 2024
d3c1451
feat: styling tabs + counter
fairlighteth Sep 20, 2024
d60e66d
chore: fix merge
shoom3301 Sep 20, 2024
535cc93
chore: up version
shoom3301 Sep 20, 2024
c099ad4
chore: remove unused hook
shoom3301 Sep 20, 2024
ddee335
feat: styling tabs + counter
fairlighteth Sep 20, 2024
5d5f3cc
feat: add inline search
fairlighteth Sep 20, 2024
47fe066
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 Sep 23, 2024
dc207ad
Merge branch 'feat/hooks-iframe-app-9' of https://github.com/cowproto…
shoom3301 Sep 23, 2024
6570564
chore: fix build
shoom3301 Sep 23, 2024
f7676c6
chore: fix build
shoom3301 Sep 23, 2024
0af4b4e
Merge branch 'feat/hooks-iframe-app-9' into feat/hooks-iframe-styling1
fairlighteth Sep 23, 2024
1c80f3c
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 Sep 23, 2024
d5dd9fb
feat: style inline search and custom hooks add
fairlighteth Sep 23, 2024
e74b30b
Merge branch 'feat/hooks-iframe-styling1' of github.com:cowprotocol/c…
fairlighteth Sep 23, 2024
41afb7e
feat: add simulatin styling
fairlighteth Sep 23, 2024
f17a5a8
Merge branch 'feat/hooks-iframe-app-9' into feat/hooks-iframe-styling1
fairlighteth Sep 23, 2024
43d4c2e
feat: merge conflic fixes
fairlighteth Sep 23, 2024
1d48955
feat: handle walletcompat undefined
fairlighteth Sep 23, 2024
0e234a6
fix: missing property
fairlighteth Sep 23, 2024
5e342f2
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 Sep 24, 2024
442283a
fix(hooks-store): use recipient override only in hooks page
shoom3301 Sep 24, 2024
526a7fc
chore: trim hook url
shoom3301 Sep 24, 2024
f48ebe1
Merge branch 'feat/hooks-iframe-app-9' of https://github.com/cowproto…
shoom3301 Sep 24, 2024
08a4a84
refactor: simlify hooks-store code
shoom3301 Sep 24, 2024
cf9c15a
refactor: rename externalHooks to customHooks
shoom3301 Sep 24, 2024
1b9a781
refactor: separate pre/post custom hooks
shoom3301 Sep 24, 2024
5254326
chore: fix UI
shoom3301 Sep 24, 2024
f01b2b4
chore: fix tenderly simulation
shoom3301 Sep 24, 2024
c09691a
chore: fix build
shoom3301 Sep 24, 2024
bc74a2a
Merge branch 'feat/hooks-iframe-app-9' of https://github.com/cowproto…
shoom3301 Sep 24, 2024
a06204a
chore: fix styles
shoom3301 Sep 24, 2024
b48b030
chore: fix styles
shoom3301 Sep 24, 2024
bec4d12
chore: fix recipient resetting
shoom3301 Sep 25, 2024
34a2d05
chore: fix hooks-store ui issues
shoom3301 Sep 25, 2024
1228308
feat(hook-dapp-lib): add isDarkMode parameter to context
shoom3301 Sep 25, 2024
13e5649
fix(hooks-store): always display SwapWidget to keep updaters active
shoom3301 Sep 25, 2024
55a62ae
refactor(hooks-store): add hook-dapps registry to match hooks with dapps
shoom3301 Sep 25, 2024
38685d5
feat(hooks-store): match hooks with their dapps
shoom3301 Sep 26, 2024
8b51161
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 Sep 27, 2024
5f17875
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 Oct 2, 2024
1cf305f
chore: refactor useInternalHookDapps
shoom3301 Oct 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { useCallback, useEffect, useMemo, useState } from 'react'
import ICON_HOOK from '@cowprotocol/assets/cow-swap/hook.svg'
import { Command } from '@cowprotocol/types'
import { BannerOrientation, DismissableInlineBanner } from '@cowprotocol/ui'
import { useIsSmartContractWallet, useWalletInfo } from '@cowprotocol/wallet'
import { useIsSmartContractWallet } from '@cowprotocol/wallet'

import { NewModal } from 'common/pure/NewModal'

import { EmptyList, HookDappsList, Wrapper } from './styled'

import { POST_HOOK_REGISTRY, PRE_HOOK_REGISTRY } from '../../hookRegistry'
import { useAddCustomHookDapp } from '../../hooks/useAddCustomHookDapp'
import { useCustomHookDapps } from '../../hooks/useCustomHookDapps'
import { useHookById } from '../../hooks/useHookById'
import { useInternalHookDapps } from '../../hooks/useInternalHookDapps'
import { useRemoveCustomHookDapp } from '../../hooks/useRemoveCustomHookDapp'
import { AddCustomHookForm } from '../../pure/AddCustomHookForm'
import { HookDappDetails } from '../../pure/HookDappDetails'
Expand All @@ -31,7 +31,6 @@ interface HookStoreModal {
}

export function HookRegistryList({ onDismiss, isPreHook, hookToEdit }: HookStoreModal) {
const { chainId } = useWalletInfo()
const [selectedDapp, setSelectedDapp] = useState<HookDapp | null>(null)
const [dappDetails, setDappDetails] = useState<HookDapp | null>(null)

Expand All @@ -51,9 +50,7 @@ export function HookRegistryList({ onDismiss, isPreHook, hookToEdit }: HookStore
setSearchQuery('')
}, [])

const internalHookDapps = useMemo(() => {
return (isPreHook ? PRE_HOOK_REGISTRY[chainId] : POST_HOOK_REGISTRY[chainId]) || []
}, [isPreHook, chainId])
const internalHookDapps = useInternalHookDapps(isPreHook)

const currentDapps = useMemo(() => {
return isAllHooksTab ? internalHookDapps.concat(customHookDapps) : customHookDapps
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
import { SBCDepositContract as SBCDepositContractType, SBCDepositContractAbi } from '@cowprotocol/abis'
import { Contract } from '@ethersproject/contracts'

export const SBC_DEPOSIT_CONTRACT_ADDRESS = '0x0B98057eA310F4d31F2a452B414647007d1645d9'

export const SBCDepositContract = new Contract(
SBC_DEPOSIT_CONTRACT_ADDRESS,
SBCDepositContractAbi,
) as SBCDepositContractType

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { useCallback, useEffect, useMemo, useState } from 'react'

import { SupportedChainId } from '@cowprotocol/cow-sdk'
import { ButtonPrimary } from '@cowprotocol/ui'
import { UI } from '@cowprotocol/ui'
import { useWalletProvider } from '@cowprotocol/wallet-provider'
import { BigNumber } from '@ethersproject/bignumber'

import { formatUnits } from 'ethers/lib/utils'

import { SBC_DEPOSIT_CONTRACT_ADDRESS } from './const'
import { useSBCDepositContract } from './useSBCDepositContract'
import { SBC_DEPOSIT_CONTRACT_ADDRESS, SBCDepositContract } from './const'

import { HookDappProps } from '../../types/hooks'
import { ContentWrapper, Text, LoadingLabel, Wrapper } from '../styled'

const SbcDepositContractInterface = SBCDepositContract.interface

/**
* Dapp that creates the hook to the connected wallet GNO Rewards.
*
Expand All @@ -20,42 +23,44 @@ import { ContentWrapper, Text, LoadingLabel, Wrapper } from '../styled'
* - Master: 0x4fef25519256e24a1fc536f7677152da742fe3ef
*/
export function ClaimGnoHookApp({ context }: HookDappProps) {
const SbcDepositContract = useSBCDepositContract()
const provider = useWalletProvider()
const [claimable, setClaimable] = useState<BigNumber | undefined>(undefined)
const [gasLimit, setGasLimit] = useState<BigNumber | undefined>(undefined)
const [error, setError] = useState<boolean>(false)

const loading = (!gasLimit || !claimable) && !error

const SbcDepositContractInterface = SbcDepositContract?.interface
const account = context?.account

const callData = useMemo(() => {
if (!SbcDepositContractInterface || !context?.account) {
if (!account) {
return null
}

return SbcDepositContractInterface.encodeFunctionData('claimWithdrawal', [context.account])
}, [SbcDepositContractInterface, context])
return SbcDepositContractInterface.encodeFunctionData('claimWithdrawal', [account])
}, [context])

useEffect(() => {
if (!SbcDepositContract || !context?.account) {
if (!account || !provider) {
return
}

const handleError = (e: any) => {
console.error('[ClaimGnoHookApp] Error getting balance/gasEstimation', e)
setError(true)
}

// Get balance
SbcDepositContract.withdrawableAmount(context.account)
SBCDepositContract.connect(provider)
.withdrawableAmount(account)
.then((claimable) => {
console.log('[ClaimGnoHookApp] get claimable', claimable)
setClaimable(claimable)
})
.catch(handleError)

// Get gas estimation
SbcDepositContract.estimateGas.claimWithdrawal(context.account).then(setGasLimit).catch(handleError)
}, [SbcDepositContract, setClaimable, context])
SBCDepositContract.connect(provider).estimateGas.claimWithdrawal(account).then(setGasLimit).catch(handleError)
}, [setClaimable, account, provider])

const clickOnAddHook = useCallback(() => {
if (!callData || !gasLimit || !context || !claimable) {
Expand Down Expand Up @@ -85,9 +90,9 @@ export function ClaimGnoHookApp({ context }: HookDappProps) {
return (
<Wrapper>
<ContentWrapper>
{!SbcDepositContractInterface ? (
{context.chainId !== SupportedChainId.GNOSIS_CHAIN ? (
'Unsupported network. Please change to Gnosis Chain'
) : !context?.account ? (
) : !account ? (
'Connect your wallet first'
) : (
<>
Expand Down

This file was deleted.

This file was deleted.

41 changes: 23 additions & 18 deletions apps/cowswap-frontend/src/modules/hooksStore/hookRegistry.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import { SupportedChainId } from '@cowprotocol/cow-sdk'
import { hookDappsRegistry } from '@cowprotocol/hook-dapp-lib'

import { AIRDROP_HOOK_APP } from './dapps/AirdropHookApp/hook'
import { PRE_BUILD, POST_BUILD } from './dapps/BuildHookApp/hook'
import { PRE_CLAIM_GNO } from './dapps/ClaimGnoHookApp/hook'
import { PERMIT_HOOK } from './dapps/PermitHookApp/hook'
import { AirdropHookApp } from './dapps/AirdropHookApp'
import { BuildHookApp } from './dapps/BuildHookApp'
import { ClaimGnoHookApp } from './dapps/ClaimGnoHookApp'
import { PermitHookApp } from './dapps/PermitHookApp'
import { HookDapp } from './types/hooks'

export const PRE_HOOK_REGISTRY: Record<SupportedChainId, HookDapp[]> = {
[SupportedChainId.MAINNET]: [PRE_BUILD],
[SupportedChainId.GNOSIS_CHAIN]: [PRE_CLAIM_GNO, PRE_BUILD],
[SupportedChainId.SEPOLIA]: [PRE_BUILD, PERMIT_HOOK, AIRDROP_HOOK_APP],
[SupportedChainId.ARBITRUM_ONE]: [PRE_BUILD],
}

export const POST_HOOK_REGISTRY: Record<SupportedChainId, HookDapp[]> = {
[SupportedChainId.MAINNET]: [POST_BUILD],
[SupportedChainId.GNOSIS_CHAIN]: [POST_BUILD],
[SupportedChainId.SEPOLIA]: [POST_BUILD, AIRDROP_HOOK_APP, PERMIT_HOOK],
[SupportedChainId.ARBITRUM_ONE]: [POST_BUILD],
}
export const ALL_HOOK_DAPPS = [
{
...hookDappsRegistry.BUILD_CUSTOM_HOOK,
component: (props) => <BuildHookApp {...props} />,
},
{
...hookDappsRegistry.CLAIM_GNO_FROM_VALIDATORS,
component: (props) => <ClaimGnoHookApp {...props} />,
},
{
...hookDappsRegistry.PERMIT_TOKEN,
component: (props) => <PermitHookApp {...props} />,
},
{
...hookDappsRegistry.CLAIM_COW_AIRDROP,
component: (props) => <AirdropHookApp {...props} />,
},
] as HookDapp[]
13 changes: 10 additions & 3 deletions apps/cowswap-frontend/src/modules/hooksStore/hooks/useAddHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { v4 as uuidv4 } from 'uuid'

import { setHooksAtom } from '../state/hookDetailsAtom'
import { AddHook, CowHookDetailsSerialized, HookDapp } from '../types/hooks'
import { getHookDappId } from '../utils'
import { appendDappIdToCallData } from '../utils'

export function useAddHook(dapp: HookDapp, isPreHook: boolean): AddHook {
const updateHooks = useSetAtom(setHooksAtom)
Expand All @@ -16,8 +16,15 @@ export function useAddHook(dapp: HookDapp, isPreHook: boolean): AddHook {

const uuid = uuidv4()
const hookDetails: CowHookDetailsSerialized = {
hookDetails: { ...hookToAdd, uuid },
dappId: getHookDappId(dapp),
hookDetails: {
...hookToAdd,
uuid,
hook: {
...hookToAdd.hook,
callData: appendDappIdToCallData(hookToAdd.hook.callData, dapp.id),
},
},
dappId: dapp.id,
}

updateHooks((hooks) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { useMemo } from 'react'

import { useWalletInfo } from '@cowprotocol/wallet'

import { useCustomHookDapps } from './useCustomHookDapps'
import { useInternalHookDapps } from './useInternalHookDapps'

import { POST_HOOK_REGISTRY, PRE_HOOK_REGISTRY } from '../hookRegistry'
import { HookDapp } from '../types/hooks'

export function useAllHookDapps(isPreHook: boolean): HookDapp[] {
const { chainId } = useWalletInfo()
const internalHookDapps = useInternalHookDapps(isPreHook)
const customHookDapps = useCustomHookDapps(isPreHook)

return useMemo(() => {
return (isPreHook ? PRE_HOOK_REGISTRY : POST_HOOK_REGISTRY)[chainId].concat(customHookDapps)
}, [customHookDapps, chainId])
return internalHookDapps.concat(customHookDapps)
}, [customHookDapps, internalHookDapps])
}
13 changes: 11 additions & 2 deletions apps/cowswap-frontend/src/modules/hooksStore/hooks/useEditHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CowHookDetails } from '@cowprotocol/hook-dapp-lib'

import { setHooksAtom } from '../state/hookDetailsAtom'
import { EditHook } from '../types/hooks'
import { appendDappIdToCallData } from '../utils'

export function useEditHook(isPreHook: boolean): EditHook {
const updateHooks = useSetAtom(setHooksAtom)
Expand All @@ -18,9 +19,17 @@ export function useEditHook(isPreHook: boolean): EditHook {
if (hookIndex < 0) return state

const typeState = [...state[type]]
const hookDetails = typeState[hookIndex]

typeState[hookIndex] = {
...typeState[hookIndex],
hookDetails: update,
...hookDetails,
hookDetails: {
...update,
hook: {
...update.hook,
callData: appendDappIdToCallData(update.hook.callData, hookDetails.dappId),
},
},
}

return {
Expand Down
Loading
Loading