Skip to content

Commit

Permalink
Pass quoteId down to appData
Browse files Browse the repository at this point in the history
  • Loading branch information
alfetopito committed Jun 27, 2022
1 parent 4563ae4 commit ed623b0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/custom/hooks/useAppData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export function useAppData(chainId?: SupportedChainId, trade?: TradeGp): AppData
// Sell and buy amounts, from trade param
const sellAmount = trade?.inputAmountWithFee.quotient.toString()
const buyAmount = trade?.outputAmount.quotient.toString()
const quoteId = trade?.quoteId

useEffect(() => {
if (!chainId || !sellAmount || !buyAmount) {
Expand All @@ -37,7 +38,7 @@ export function useAppData(chainId?: SupportedChainId, trade?: TradeGp): AppData
return
}

const params: Parameters<typeof buildAppData> = [chainId, sellAmount, buyAmount, referrerAccount, appCode]
const params: Parameters<typeof buildAppData> = [chainId, sellAmount, buyAmount, quoteId, referrerAccount, appCode]

const updateAppData = async (): Promise<void> => {
try {
Expand All @@ -58,7 +59,7 @@ export function useAppData(chainId?: SupportedChainId, trade?: TradeGp): AppData
}

updateAppData()
}, [appCode, buyAmount, chainId, referrerAccount, sellAmount, setAppDataInfo])
}, [appCode, buyAmount, chainId, quoteId, referrerAccount, sellAmount, setAppDataInfo])

return appDataInfo
}
7 changes: 4 additions & 3 deletions src/custom/utils/appData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ export async function buildAppData(
chainId: SupportedChainId,
sellAmount: string,
buyAmount: string,
quoteId: number | undefined,
referrerAccount: string | undefined,
appCode: string
) {
const sdk = COW_SDK[chainId]

// build quote metadata, not required in the schema but always present
const quoteMetadata = _buildQuoteMetadata(sellAmount, buyAmount)
const quoteMetadata = _buildQuoteMetadata(sellAmount, buyAmount, quoteId)
const metadata: MetadataDoc = { quote: quoteMetadata }

// build referrer metadata, optional
Expand All @@ -30,9 +31,9 @@ export async function buildAppData(
return { doc, calculatedAppData }
}

function _buildQuoteMetadata(sellAmount: string, buyAmount: string): QuoteMetadata {
function _buildQuoteMetadata(sellAmount: string, buyAmount: string, quoteId: number | undefined): QuoteMetadata {
return {
// id: quoteId, TODO: add quoteId here when available
id: quoteId?.toString(), // Comes from the api as number|null, metadata expects a string|undefined
sellAmount,
buyAmount,
version: QUOTE_METADATA_VERSION,
Expand Down

0 comments on commit ed623b0

Please sign in to comment.