-
Notifications
You must be signed in to change notification settings - Fork 0
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
(govern) feat: migrate donate to govern #84
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons'; | ||
import { Button, Form, Grid, InputNumber, Space, Typography } from 'antd'; | ||
import styled from 'styled-components'; | ||
import { useAccount } from 'wagmi'; | ||
|
||
const { Text } = Typography; | ||
const { useBreakpoint } = Grid; | ||
|
||
export const DynamicFormContainer = styled.div` | ||
max-width: 720px; | ||
.ant-input-number { | ||
width: 200px; | ||
} | ||
`; | ||
|
||
type DonateFormProps = { | ||
isLoading: boolean; | ||
onSubmit: ({ unitIds, amounts }: { unitIds: number[]; amounts: number[] }) => Promise<void>; | ||
}; | ||
|
||
export const DonateForm = ({ isLoading, onSubmit }: DonateFormProps) => { | ||
const { address: account } = useAccount(); | ||
const [form] = Form.useForm(); | ||
|
||
const screens = useBreakpoint(); | ||
const inputStyle = screens.xs ? { width: '140px' } : { width: 'auto' }; | ||
|
||
const onFinish = async (values: { units: { unitId: number; amount: number }[] }) => { | ||
try { | ||
await onSubmit({ | ||
unitIds: values.units.map((unit) => unit.unitId), | ||
amounts: values.units.map((unit) => unit.amount), | ||
}); | ||
|
||
form.resetFields(); | ||
} catch (error) { | ||
window.console.error(error); | ||
} | ||
}; | ||
|
||
return ( | ||
<DynamicFormContainer> | ||
<Form form={form} name="dynamic_form_complex" onFinish={onFinish} autoComplete="off"> | ||
<Form.List | ||
name="units" | ||
initialValue={[{ unitId: undefined, unitType: undefined }]} | ||
rules={[ | ||
{ | ||
validator: async (_, units) => { | ||
if (!units || units?.length === 0) { | ||
return Promise.reject(new Error('At least 1 unit is required')); | ||
} | ||
return Promise.resolve(); | ||
}, | ||
}, | ||
]} | ||
> | ||
{(fields, { add, remove }, { errors }) => ( | ||
<> | ||
{fields.map((field) => ( | ||
<Space key={field.key} align="baseline"> | ||
<Form.Item | ||
noStyle | ||
shouldUpdate={(prevValues, curValues) => prevValues.units !== curValues.units} | ||
> | ||
{() => ( | ||
<Form.Item | ||
{...field} | ||
label="Service ID" | ||
name={[field.name, 'unitId']} | ||
rules={[ | ||
{ | ||
required: true, | ||
message: 'Please add Service ID', | ||
}, | ||
]} | ||
> | ||
<InputNumber | ||
min={0} | ||
className="mr-24" | ||
placeholder="Eg. 1" | ||
style={inputStyle} | ||
/> | ||
</Form.Item> | ||
)} | ||
</Form.Item> | ||
|
||
<Form.Item | ||
{...field} | ||
label="Amount (ETH)" | ||
name={[field.name, 'amount']} | ||
rules={[{ required: true, message: 'Please add Amount (ETH)' }]} | ||
> | ||
<InputNumber min={0} placeholder="Eg. 0.065" style={inputStyle} /> | ||
</Form.Item> | ||
|
||
{fields.length > 1 && <MinusCircleOutlined onClick={() => remove(field.name)} />} | ||
</Space> | ||
))} | ||
|
||
<Form.ErrorList errors={errors} /> | ||
|
||
<Form.Item wrapperCol={{ span: 6 }}> | ||
<Button size="large" onClick={add} block icon={<PlusOutlined />}> | ||
Add row | ||
</Button> | ||
</Form.Item> | ||
</> | ||
)} | ||
</Form.List> | ||
|
||
<Form.Item className="mb-0"> | ||
<Button | ||
size="large" | ||
type="primary" | ||
htmlType="submit" | ||
loading={isLoading} | ||
disabled={!account} | ||
> | ||
Donate | ||
</Button> | ||
|
||
{!account && ( | ||
<Text className="ml-8" type="secondary"> | ||
To donate, connect a wallet | ||
</Text> | ||
)} | ||
</Form.Item> | ||
</Form> | ||
</DynamicFormContainer> | ||
); | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add "AbiItem[]" directly in
TOKENOMICS
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually not that easy, there are difficulties with providing the correct type for abi. I just realised that if I don't specify the type (I did it for some contracts as
Abi
from viem, see libs/util-contracts/src/lib/abiAndAddresses/types.ts), wagmi hooks recognise returned values correctly, e.g. as number or bigint, or string, etc. Ideally would be good to allocate some time to resolve this properly