-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3624 from JoinColony/feat/3532-motion-arbitrary-txs
feat: create simple Arbitrary Txs action
- Loading branch information
Showing
41 changed files
with
664 additions
and
28 deletions.
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; |
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>; |
36 changes: 36 additions & 0 deletions
36
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,36 @@ | ||
import { Id } from '@colony/colony-js'; | ||
import { 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, | ||
}), | ||
[], | ||
), | ||
transform: 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.