forked from cowprotocol/cowswap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(appzi): new appzi survey for limit orders (cowprotocol#3918)
* feat: add optional appzi data: account and pendingOrderIds * feat: use new appzi survey for limit orders * refactor: rename appzi trigger fn * refactor: create const with orderType * feat: trigger appzi limit orders survey when limit orders widget is loaded * fix: do not trigger when there are no pending LIMIT orders * fix: pendingOrderIds was returning order objs instead of ids * refactor: add fn getSurveyType
- Loading branch information
1 parent
55b5e22
commit 99e004a
Showing
7 changed files
with
99 additions
and
24 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
40 changes: 40 additions & 0 deletions
40
apps/cowswap-frontend/src/modules/limitOrders/updaters/TriggerAppziUpdater.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 { useEffect, useMemo } from 'react' | ||
|
||
import { triggerAppziSurvey } from '@cowprotocol/common-utils' | ||
import { UiOrderType } from '@cowprotocol/types' | ||
import { useWalletInfo } from '@cowprotocol/wallet' | ||
|
||
import { useOnlyPendingOrders } from 'legacy/state/orders/hooks' | ||
|
||
import { getUiOrderType } from 'utils/orderUtils/getUiOrderType' | ||
|
||
/** | ||
* Updater for triggering Appzi Limit Orders survey | ||
* | ||
* Should trigger only when there are pending orders on load | ||
* Not a problem if triggered more than once. Appzi controls the form display rules | ||
*/ | ||
export function TriggerAppziLimitOrdersSurveyUpdater(): null { | ||
const { account, chainId } = useWalletInfo() | ||
const orders = useOnlyPendingOrders(chainId) | ||
|
||
const pendingOrderIds = useMemo(() => { | ||
return orders | ||
.reduce<string[]>((acc, order) => { | ||
if (getUiOrderType(order) === UiOrderType.LIMIT) { | ||
acc.push(order.id) | ||
} | ||
|
||
return acc | ||
}, []) | ||
.join(',') | ||
}, [orders]) | ||
|
||
useEffect(() => { | ||
if (account && chainId && pendingOrderIds) { | ||
triggerAppziSurvey({ account, chainId, pendingOrderIds, openedLimitPage: true }, 'limit') | ||
} | ||
}, [account, chainId, pendingOrderIds]) | ||
|
||
return null | ||
} |
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