Skip to content

Commit

Permalink
fix: stonks qa findings
Browse files Browse the repository at this point in the history
  • Loading branch information
katamarinaki committed Apr 4, 2024
1 parent 9242d5e commit 20a9ee1
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion modules/stonks/hooks/useStonksData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ export function useStonksData() {
marginInBasisPoints: marginInBasisPoints.toNumber(),
orderDurationInSeconds: orderDurationInSeconds.toNumber(),
priceToleranceInBasisPoints: priceToleranceInBasisPoints.toNumber(),
currentBalanceBn: currentBalance,
currentBalance: isEnoughBalance
? formatUnits(currentBalance, tokenFromDecimals)
: '0',
expectedOutput: Number(
formatUnits(expectedOutput, tokenToDecimals),
),
tokenToDecimals: tokenToDecimals,
isBalanceZero: !isEnoughBalance,
}
}),
)
Expand Down
6 changes: 2 additions & 4 deletions modules/stonks/ui/StonksOrderForm/StonksOrderForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ export function StonksOrderForm() {
return <MessageBox>Stonks pair not found</MessageBox>
}

const isBalanceZero = selectedStonksPair.currentBalanceBn.isZero()

return (
<Form formMethods={formMethods} onSubmit={handleSubmit}>
<Title
Expand All @@ -95,7 +93,7 @@ export function StonksOrderForm() {
label="Minimum acceptable amount"
name="minAcceptableAmount"
rules={{ required: 'Field is required' }}
disabled={isBalanceZero}
disabled={selectedStonksPair.isBalanceZero}
/>
</InputRow>
</MotionInfoBox>
Expand Down Expand Up @@ -143,7 +141,7 @@ export function StonksOrderForm() {
<Button
type="submit"
fullwidth
disabled={isBalanceZero}
disabled={selectedStonksPair.isBalanceZero}
children="Create Order"
loading={isSubmitting}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export function StonksOrderResolverForm() {
fullwidth
name="txHashOrAddress"
placeholder="Order creation tx hash or order address"
autoComplete="off"
id="search-address"
rules={{
required: 'Field is required',
validate: value => {
Expand Down
4 changes: 2 additions & 2 deletions modules/stonks/utils/fetchCowApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const fetchCowApi = async <T extends unknown>({
const cowApiEndpoint = COWSWAP_API_ENDPOINTS[parsedChainId]

if (!cowApiEndpoint) {
throw new Error(`CoW API has no endpoint for chain ${parsedChainId}`)
throw new Error(`NO_CHAIN_${parsedChainId}`)
}

const requested = await fetch(`${cowApiEndpoint}${url}`, {
Expand All @@ -41,5 +41,5 @@ export const fetchCowApi = async <T extends unknown>({
return data as T
}

throw new Error(data?.description || 'Something went wrong')
throw new Error(data?.description || 'UNKNOWN_ERROR')
}
11 changes: 5 additions & 6 deletions pages/api/stonks/orders/[orderAddress].ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ export default async function getOrder(
})

res.status(200).json(orderData)
} catch (error) {
console.error(
error instanceof Error ? error.message : FALLBACK_ERROR,
error,
)
res.status(500).json({ error: FALLBACK_ERROR })
} catch (error: any) {
const code =
error?.message && error.message.startsWith('NO_CHAIN_') ? 404 : 500
const message = error?.message || FALLBACK_ERROR
res.status(code).json({ error: message })
}
}

0 comments on commit 20a9ee1

Please sign in to comment.