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:add cow limit order core action #324

Draft
wants to merge 18 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 22 additions & 3 deletions apps/davi/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
"theRemovalCannotBeReverted": "The removal cannot be reverted",
"removeAction": "Remove Action",
"remove": "Remove",
"edit": "Edit"
"edit": "Edit",
"executeLimitOrder": "Execute limit order"
},
"options": {
"against": "Against",
Expand All @@ -105,7 +106,14 @@
"ethereumAddress": "Ethereum Address",
"toAddress": "To Address",
"address": "Address",
"contract": "Contract"
"contract": "Contract",
"sellToken": "Sell Token",
"buyToken": "Buy Token",
"sellAmount": "Sell Amount",
"buyAmount": "Buy Amount",
"unitBuyPrice": "Unit Buy Price",
"pricePerToken": "Price Per {{token}} ",
"atLeastAmount": "You receive at least"
},
"permissions": {
"permissions": "Permissions",
Expand Down Expand Up @@ -171,9 +179,11 @@
"approveSpendingCall": "Approve spending call",
"addressToWhichTheExpenseIsBeingAuthorized": "Address to which the expense is being authorized",
"amountBeingApproved": "Amount being approved",
"approveTokenSpending": "Approve {{tokenSymbol}} token spending"
"approveTokenSpending": "Approve {{tokenSymbol}} token spending",
"erc20Approval": "ERC20 Approval for {{tokenSymbol}}"
},
"config": {
"limitOrder": "Limit Order",
"setGuildConfig": "Set Guild Config",
"noValueHasBeenUpdatedFromCurrentGuildConfig": "No value has been updated from current guild config",
"proposalTimeHasToBeMoreThanZero": "Proposal time has to be more than 0",
Expand Down Expand Up @@ -405,10 +415,19 @@
"inputValidation": {
"recipientAddressIsRequired": "Recipient address is required",
"amountIsRequired": "Amount is required",
"buyAmountIsRequired": "Buy amount is required",
"sellAmountIsRequired": "Sell amount is required",
"invalidRecipientAddress": "Invalid recipient address",
"tokenIsRequired": "Token is required",
"buyTokenIsRequired": "Buy token is required",
"sellTokenIsRequired": "Sell token is required",
"invalidBuyTokenAddress": "Invalid buy token address",
"invalidSellTokenAddress": "Invalid sell token address",
"buyAndSellTokensCannotBeTheSame": "Buy and sell tokens cannot be the same",
"amountCannotBeZero": "Amount cannot be zero",
"sellAmountCannotBeZero": "Sell amount cannot be zero",
"invalidAmount": "Invalid amount",
"invalidSellAmount": "Invalid sell amount",
"invalidValue": "Invalid value",
"invalidTokenAddress": "Invalid token address",
"dataIsNotAHexString": "Data is not a hex string",
Expand Down
9 changes: 7 additions & 2 deletions apps/davi/src/components/ActionsBuilder/Option/Option.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ActionRow } from '../Action';
import { AddButton, DataTag, EditButton, Grip } from '../common';
import { ProposalOptionTag } from '../common';
import { DecodedAction, Option } from '../types';
import { DecodedAction, Option, SupportedAction } from '../types';
import {
SortableContext,
useSortable,
Expand Down Expand Up @@ -134,7 +134,12 @@ export const OptionRow: React.FC<OptionRowProps> = ({
return (
<ActionRow
key={index}
isEditable={true}
isEditable={
!(
action?.decodedCall?.callType ===
SupportedAction.ERC20_APPROVE
)
}
decodedAction={option?.decodedActions?.[index]}
permissionArgs={permissionsArgs}
onEdit={updatedAction => updateAction(updatedAction)}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import styled from 'styled-components';
import { ErrorLabel } from 'components/primitives/Forms/ErrorLabel';
import { Box } from 'components/primitives/Layout';

export const FieldError = styled(ErrorLabel)`
margin-top: 0.5rem;
`;

export const SwapQuoteError = styled(ErrorLabel)`
margin: 1rem 0;
font-size: 14px;
`;

export const Spacer = styled(Box)`
margin-right: 1rem;
`;

export const UnitPriceContainer = styled(Box)`
display: flex;
justify-content: space-between;
cursor: pointer;
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { BigNumber } from 'ethers';
import { render } from 'utils/tests';
import CowLimitOrderEditor from './CowLimitOrderEditor';
import { MOCK_ADDRESS } from 'hooks/Guilds/ens/fixtures';
import { limitOrderDecodedCallMock } from './fixtures';

const mockBigNumber = BigNumber.from(100000000);

jest.mock('utils', () => ({
getNetworkById: () => ({
nativeAsset: {
symbol: 'TST',
},
}),
usePrevious: () => undefined,
}));

jest.mock('hooks/Guilds/ens/useENSAvatar', () => ({
__esModule: true,
default: () => ({
imageUrl: 'wagmi',
}),
}));

jest.mock('hooks/Guilds/erc20/useERC20Info', () => ({
useERC20Info: () => ({
name: 'Test ERC20',
symbol: 'TEST',
decimals: 18,
totalSupply: mockBigNumber,
}),
}));

jest.mock('hooks/Guilds/erc20/useAllERC20Balances', () => ({
useAllERC20Balances: () => ({
data: [],
}),
}));

const mockChainId = 123456;
jest.mock('wagmi', () => ({
useNetwork: () => ({ chain: { id: mockChainId } }),
useAccount: () => ({ address: MOCK_ADDRESS }),
}));

jest.mock('hooks/Guilds/tokens/useTokenList', () => ({
useTokenList: () => ({
tokens: [],
}),
}));

describe('CowLimitOrderEditor', () => {
it('Should match snapshot', () => {
const { container } = render(
<CowLimitOrderEditor
decodedCall={limitOrderDecodedCallMock}
onSubmit={jest.fn()}
/>
);
expect(container).toMatchSnapshot();
});
});
Loading