-
Notifications
You must be signed in to change notification settings - Fork 14
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
Open
Nortsova
wants to merge
10
commits into
feat/arbitrary-txs
Choose a base branch
from
feat/3532-motion-arbitrary-txs
base: feat/arbitrary-txs
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a684e81
feat: create simple Arbitrary Txs motion
Nortsova d3e2d4b
feat: add transactions table and modal
Nortsova 3663e65
fix: create basic form validation
Nortsova 162f6c1
feat: implement transaction validation and throw data to the saga
Nortsova 041c358
fix: align select and textarea to the design
Nortsova a31ec3b
feat: update styles for Modal and transaction table
Nortsova 9f70138
fix: refactor some small ui issues in textarea
Nortsova 2f4da3b
feat: mobile alignment
Nortsova ae319b3
fix: refactor function naming and fixing minor issues
Nortsova 325ec20
fix: textarea height issue
Nortsova 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
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
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,29 @@ | ||
import { isAddress } from 'ethers/lib/utils'; | ||
|
||
import { splitAddress, type AddressElements } from '~utils/strings.ts'; | ||
|
||
interface GetMaskedAddressParams { | ||
address: string; | ||
isFull?: boolean; | ||
mask?: string; | ||
} | ||
interface GetMaskedAddressResult { | ||
result: string; | ||
cutAddress: AddressElements | null; | ||
} | ||
const getMaskedAddress = ({ | ||
address, | ||
isFull = false, | ||
mask = '...', | ||
}: GetMaskedAddressParams): GetMaskedAddressResult => { | ||
const isValidAddress = isAddress(address); | ||
if (!isValidAddress) return { result: address, cutAddress: null }; | ||
|
||
const cutAddress: AddressElements = splitAddress(address); | ||
|
||
const result = `${cutAddress.header}${cutAddress.start}${isFull ? cutAddress.middle : mask}${cutAddress.end}`; | ||
|
||
return { result, cutAddress }; | ||
}; | ||
|
||
export default getMaskedAddress; |
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
24 changes: 24 additions & 0 deletions
24
...mmon/ActionSidebar/partials/ActionSidebarDescription/partials/ArbitraryTxsDescription.tsx
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,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.ArbitraryTx, | ||
initiator: <CurrentUser />, | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
ArbitraryTxsDescription.displayName = displayName; | ||
export default ArbitraryTxsDescription; |
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
31 changes: 31 additions & 0 deletions
31
src/components/v5/common/ActionSidebar/partials/forms/ArbitraryTxsForm/ArbitraryTxsForm.tsx
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,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; |
28 changes: 28 additions & 0 deletions
28
src/components/v5/common/ActionSidebar/partials/forms/ArbitraryTxsForm/consts.ts
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,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({ | ||
contractAddress: string().defined(), | ||
jsonAbi: string().defined(), | ||
method: string().defined(), | ||
amount: string().defined(), | ||
to: string().defined(), | ||
}) | ||
.defined(), | ||
) | ||
.required(), | ||
}) | ||
.defined() | ||
.concat(ACTION_BASE_VALIDATION_SCHEMA); | ||
|
||
export type CreateArbitraryTxsFormValues = InferType<typeof validationSchema>; |
40 changes: 40 additions & 0 deletions
40
src/components/v5/common/ActionSidebar/partials/forms/ArbitraryTxsForm/hooks.ts
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,40 @@ | ||
import { Id } from '@colony/colony-js'; | ||
import { useCallback, useMemo } from 'react'; | ||
|
||
import { ActionTypes } from '~redux/index.ts'; | ||
import { mapPayload } 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( | ||
mapPayload((payload) => { | ||
const safeDescription = sanitizeHTML(payload.description || ''); | ||
|
||
return { | ||
decisionMethod: payload.decisionMethod, | ||
description: safeDescription, | ||
customActionTitle: payload.title, | ||
transactions: payload.transactions, | ||
}; | ||
}), | ||
[], | ||
), | ||
}); | ||
}; |
1 change: 1 addition & 0 deletions
1
src/components/v5/common/ActionSidebar/partials/forms/ArbitraryTxsForm/index.ts
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 @@ | ||
export { default } from './ArbitraryTxsForm.tsx'; |
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.
@arrenv Is there a preference regarding which group arbitrary transaction should show under?