-
Notifications
You must be signed in to change notification settings - Fork 15
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: create simple Arbitrary Txs action #3624
Changes from 8 commits
a684e81
d3e2d4b
3663e65
162f6c1
041c358
a31ec3b
9f70138
2f4da3b
ae319b3
325ec20
eed7927
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from 'react'; | ||
import { FormattedMessage } from 'react-intl'; | ||
|
||
import { ColonyActionType } from '~gql'; | ||
|
||
import CurrentUser from './CurrentUser.tsx'; | ||
|
||
const displayName = | ||
'v5.common.ActionsSidebar.partials.ActionSidebarDescription.partials.ArbitraryTxsDescription'; | ||
|
||
export const ArbitraryTxsDescription = () => { | ||
return ( | ||
<FormattedMessage | ||
id="action.title" | ||
values={{ | ||
actionType: ColonyActionType.ArbitraryTxs, | ||
initiator: <CurrentUser />, | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
ArbitraryTxsDescription.displayName = displayName; | ||
export default ArbitraryTxsDescription; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React, { type FC } from 'react'; | ||
|
||
import CreatedIn from '~v5/common/ActionSidebar/partials/CreatedIn/index.ts'; | ||
import DecisionMethodField from '~v5/common/ActionSidebar/partials/DecisionMethodField/index.ts'; | ||
import Description from '~v5/common/ActionSidebar/partials/Description/index.ts'; | ||
import { useIsFieldDisabled } from '~v5/common/ActionSidebar/partials/hooks.ts'; | ||
import { type ActionFormBaseProps } from '~v5/common/ActionSidebar/types.ts'; | ||
|
||
import { useCreateArbitraryTxs } from './hooks.ts'; | ||
import ArbitraryTransactionsTable from './partials/ArbitraryTransactionsTable/ArbitraryTransactionsTable.tsx'; | ||
|
||
const displayName = 'v5.common.ActionSidebar.partials.ArbitraryTxsForm'; | ||
|
||
const ArbitraryTxsForm: FC<ActionFormBaseProps> = ({ getFormOptions }) => { | ||
const isFieldDisabled = useIsFieldDisabled(); | ||
|
||
useCreateArbitraryTxs(getFormOptions); | ||
|
||
return ( | ||
<> | ||
<DecisionMethodField disabled={isFieldDisabled} /> | ||
<CreatedIn /> | ||
<Description /> | ||
<ArbitraryTransactionsTable name="transactions" /> | ||
</> | ||
); | ||
}; | ||
|
||
ArbitraryTxsForm.displayName = displayName; | ||
|
||
export default ArbitraryTxsForm; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { array, type InferType, object, string } from 'yup'; | ||
|
||
import { ACTION_BASE_VALIDATION_SCHEMA } from '~v5/common/ActionSidebar/consts.ts'; | ||
|
||
export const validationSchema = object() | ||
.shape({ | ||
title: string() | ||
.trim() | ||
.required(() => 'Please enter a title.'), | ||
decisionMethod: string().defined(), | ||
transactions: array() | ||
.of( | ||
object() | ||
.shape({ | ||
contract: string().defined(), | ||
json: string().defined(), | ||
method: string().defined(), | ||
amount: string().defined(), | ||
to: string().defined(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is temporary, in the next iterations we will update these fields to be dynamic (according to ABI from the contract) |
||
}) | ||
.defined(), | ||
) | ||
.required(), | ||
}) | ||
.defined() | ||
.concat(ACTION_BASE_VALIDATION_SCHEMA); | ||
|
||
export type CreateArbitraryTxsFormValues = InferType<typeof validationSchema>; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Id } from '@colony/colony-js'; | ||
import { useCallback, useMemo } from 'react'; | ||
|
||
import { ActionTypes } from '~redux/index.ts'; | ||
import { mapPayload, pipe } from '~utils/actions.ts'; | ||
import { sanitizeHTML } from '~utils/strings.ts'; | ||
import useActionFormBaseHook from '~v5/common/ActionSidebar/hooks/useActionFormBaseHook.ts'; | ||
import { type ActionFormBaseProps } from '~v5/common/ActionSidebar/types.ts'; | ||
|
||
import { validationSchema } from './consts.ts'; | ||
|
||
export const useCreateArbitraryTxs = ( | ||
getFormOptions: ActionFormBaseProps['getFormOptions'], | ||
) => { | ||
useActionFormBaseHook({ | ||
actionType: ActionTypes.CREATE_ARBITRARY_TRANSACTION, | ||
validationSchema, | ||
getFormOptions, | ||
defaultValues: useMemo( | ||
() => ({ | ||
createdIn: Id.RootDomain, | ||
}), | ||
[], | ||
), | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
transform: useCallback( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we try and remove |
||
pipe( | ||
Nortsova marked this conversation as resolved.
Show resolved
Hide resolved
|
||
mapPayload((payload) => { | ||
// console.log('payload', payload); | ||
const safeDescription = sanitizeHTML(payload.description || ''); | ||
|
||
return { | ||
decisionMethod: payload.decisionMethod, | ||
description: safeDescription, | ||
customActionTitle: payload.title, | ||
transactions: payload.transactions, | ||
}; | ||
}), | ||
), | ||
[], | ||
), | ||
}); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './ArbitraryTxsForm.tsx'; |
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.
@arrenv Is there a preference regarding which group arbitrary transaction should show under?