From 7f34671c92576ac4fe5ef15b526639fa7460c078 Mon Sep 17 00:00:00 2001 From: Dave Creaser Date: Thu, 16 May 2024 11:17:08 +0100 Subject: [PATCH 1/3] Create saga to modify stake fraction --- .../ExtensionDetails/ExtensionDetails.tsx | 27 ++++++++ src/i18n/en.json | 6 ++ src/redux/actionTypes.ts | 3 + src/redux/sagas/expenditures/index.ts | 2 + .../sagas/expenditures/setStakeFraction.ts | 68 +++++++++++++++++++ src/redux/types/actions/expenditures.ts | 12 +++- 6 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 src/redux/sagas/expenditures/setStakeFraction.ts diff --git a/src/components/frame/Extensions/pages/ExtensionDetailsPage/partials/ExtensionDetails/ExtensionDetails.tsx b/src/components/frame/Extensions/pages/ExtensionDetailsPage/partials/ExtensionDetails/ExtensionDetails.tsx index 5dacf23c68..b17d46570c 100644 --- a/src/components/frame/Extensions/pages/ExtensionDetailsPage/partials/ExtensionDetails/ExtensionDetails.tsx +++ b/src/components/frame/Extensions/pages/ExtensionDetailsPage/partials/ExtensionDetails/ExtensionDetails.tsx @@ -1,9 +1,14 @@ import { ColonyRole, Id } from '@colony/colony-js'; +import { BigNumber } from 'ethers'; import React, { type FC } from 'react'; import SpecificSidePanel from '~common/Extensions/SpecificSidePanel/index.ts'; +import { DEFAULT_TOKEN_DECIMALS } from '~constants'; import { useAppContext } from '~context/AppContext/AppContext.ts'; import { useColonyContext } from '~context/ColonyContext/ColonyContext.ts'; +import useAsyncFunction from '~hooks/useAsyncFunction.ts'; +import { ActionTypes } from '~redux'; +import { type SetStakeFractionPayload } from '~redux/sagas/expenditures/setStakeFraction.ts'; import { addressHasRoles } from '~utils/checks/index.ts'; import { isInstalledExtensionData } from '~utils/extensions.ts'; @@ -43,6 +48,25 @@ const ExtensionDetails: FC = ({ extensionData }) => { extensionData.uninstallable ); + const setStakeFraction = useAsyncFunction({ + submit: ActionTypes.SET_STAKE_FRACTION, + error: ActionTypes.SET_STAKE_FRACTION_ERROR, + success: ActionTypes.SET_STAKE_FRACTION_SUCCESS, + }); + + const handleSetStakeFraction = async () => { + const DEFAULT_STAKE_FRACTION = BigNumber.from(2) + .mul(BigNumber.from(10).pow(DEFAULT_TOKEN_DECIMALS)) + .div(100); // 2% in wei + + const payload: SetStakeFractionPayload = { + colonyAddress: colony.colonyAddress, + stakeFraction: DEFAULT_STAKE_FRACTION.toString(), + }; + + await setStakeFraction(payload); + }; + return (
@@ -53,6 +77,9 @@ const ExtensionDetails: FC = ({ extensionData }) => { {canExtensionBeUninstalled && ( )} +
); diff --git a/src/i18n/en.json b/src/i18n/en.json index a196e2363a..894b49f475 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -402,6 +402,8 @@ "transaction.StakedExpenditureClient.cancelAndReclaimStake.description": "Cancel and Reclaim Stake", "transaction.StakedExpenditureClient.cancelAndPunish.title": "Cancel Staked Expenditure", "transaction.StakedExpenditureClient.cancelAndPunish.description": "Cancel Staked Expenditure", + "transaction.StakedExpenditureClient.setStakeFraction.title": "Set Stake Fraction", + "transaction.StakedExpenditureClient.setStakeFraction.description": "Set Stake Fraction", "transaction.StreamingPaymentsClient.create.title": "Create Streaming Payment", "transaction.StreamingPaymentsClient.create.description": "Create Streaming Payment", "transaction.group.addExistingSafe.title": "Add Existing Safe", @@ -422,6 +424,10 @@ "transaction.group.addVerifiedMembers.description": "Add verified members", "transaction.group.removeVerifiedMembers.title": "Remove verified members", "transaction.group.removeVerifiedMembers.description": "Remove verified members", + "transaction.group.setStakeFraction.title": "Set Stake Fraction", + "transaction.group.setStakeFraction.description": "Set Stake Fraction", + "transaction.ColonyClient.installExtension.title": "Install extension", + "transaction.ColonyClient.installExtension.description": "Install extension", "metatransaction.debug.description": "DEBUG: context: {context} methodName: {methodName}", "metatransaction.group.deposit.title": "Activate tokens", "metatransaction.group.deposit.description": "Activate tokens", diff --git a/src/redux/actionTypes.ts b/src/redux/actionTypes.ts index d9c576b581..a4cdc412ab 100644 --- a/src/redux/actionTypes.ts +++ b/src/redux/actionTypes.ts @@ -281,4 +281,7 @@ export enum ActionTypes { STREAMING_PAYMENT_CREATE = 'STREAMING_PAYMENT_CREATE', STREAMING_PAYMENT_CREATE_SUCCESS = 'STREAMING_PAYMENT_CREATE_SUCCESS', STREAMING_PAYMENT_CREATE_ERROR = 'STREAMING_PAYMENT_CREATE_ERROR', + SET_STAKE_FRACTION = 'SET_STAKE_FRACTION', + SET_STAKE_FRACTION_SUCCESS = 'SET_STAKE_FRACTION_SUCCESS', + SET_STAKE_FRACTION_ERROR = 'SET_STAKE_FRACTION_ERROR', } diff --git a/src/redux/sagas/expenditures/index.ts b/src/redux/sagas/expenditures/index.ts index 1813fc2d9e..c1b8d0a21e 100644 --- a/src/redux/sagas/expenditures/index.ts +++ b/src/redux/sagas/expenditures/index.ts @@ -12,6 +12,7 @@ import fundExpenditureSaga from './fundExpenditure.ts'; import lockExpenditureSaga from './lockExpenditure.ts'; import reclaimExpenditureStakeSaga from './reclaimExpenditureStake.ts'; import releaseExpenditureStageSaga from './releaseExpenditureStage.ts'; +import setStakeFractionSaga from './setStakeFraction.ts'; export default function* expendituresSagas() { yield all([ @@ -27,5 +28,6 @@ export default function* expendituresSagas() { call(releaseExpenditureStageSaga), call(cancelStakedExpenditureSaga), call(createStreamingPaymentSaga), + call(setStakeFractionSaga), ]); } diff --git a/src/redux/sagas/expenditures/setStakeFraction.ts b/src/redux/sagas/expenditures/setStakeFraction.ts new file mode 100644 index 0000000000..cbf063df89 --- /dev/null +++ b/src/redux/sagas/expenditures/setStakeFraction.ts @@ -0,0 +1,68 @@ +import { ClientType } from '@colony/colony-js'; +import { fork, put, takeEvery } from 'redux-saga/effects'; + +import { ActionTypes } from '~redux/actionTypes.ts'; +import { type AllActions, type Action } from '~redux/types/index.ts'; + +import { + type ChannelDefinition, + createTransaction, + createTransactionChannels, + waitForTxResult, +} from '../transactions/index.ts'; +import { initiateTransaction, putError, takeFrom } from '../utils/index.ts'; + +export type SetStakeFractionPayload = + Action['payload']; + +function* setStakeFractionAction({ + payload: { colonyAddress, stakeFraction }, + meta, +}: Action) { + // const apolloClient = getContext(ContextModule.ApolloClient); + + const batchKey = 'setStakeFraction'; + + const { setStakeFraction }: Record = + yield createTransactionChannels(meta.id, ['setStakeFraction']); + + try { + yield fork(createTransaction, setStakeFraction.id, { + context: ClientType.StakedExpenditureClient, + methodName: 'setStakeFraction', + identifier: colonyAddress, + group: { + key: batchKey, + id: meta.id, + index: 0, + }, + params: [stakeFraction], + }); + + yield takeFrom(setStakeFraction.channel, ActionTypes.TRANSACTION_CREATED); + + yield initiateTransaction({ id: setStakeFraction.id }); + yield takeFrom( + setStakeFraction.channel, + ActionTypes.TRANSACTION_HASH_RECEIVED, + ); + + yield waitForTxResult(setStakeFraction.channel); + + yield put({ + type: ActionTypes.SET_STAKE_FRACTION_SUCCESS, + payload: {}, + meta, + }); + } catch (error) { + return yield putError(ActionTypes.SET_STAKE_FRACTION_ERROR, error, meta); + } + + setStakeFraction.channel.close(); + + return null; +} + +export default function* setStakeFractionSaga() { + yield takeEvery(ActionTypes.SET_STAKE_FRACTION, setStakeFractionAction); +} diff --git a/src/redux/types/actions/expenditures.ts b/src/redux/types/actions/expenditures.ts index fc911d087a..ce432bf374 100644 --- a/src/redux/types/actions/expenditures.ts +++ b/src/redux/types/actions/expenditures.ts @@ -207,4 +207,14 @@ export type ExpendituresActionTypes = ActionTypes.STREAMING_PAYMENT_CREATE_SUCCESS, object, object - >; + > + | UniqueActionType< + ActionTypes.SET_STAKE_FRACTION, + { + colonyAddress: Address; + stakeFraction: string; + }, + MetaWithSetter + > + | ErrorActionType + | UniqueActionType; From 64327e4f5f703cd7380634cecb38d53c55352c64 Mon Sep 17 00:00:00 2001 From: Dave Creaser Date: Thu, 16 May 2024 15:58:56 +0100 Subject: [PATCH 2/3] Update block ingestor hash and remove testing code --- docker/colony-cdapp-dev-env-block-ingestor | 2 +- .../ExtensionDetails/ExtensionDetails.tsx | 27 ------------------- 2 files changed, 1 insertion(+), 28 deletions(-) diff --git a/docker/colony-cdapp-dev-env-block-ingestor b/docker/colony-cdapp-dev-env-block-ingestor index 72e9bceaf9..75242901c0 100644 --- a/docker/colony-cdapp-dev-env-block-ingestor +++ b/docker/colony-cdapp-dev-env-block-ingestor @@ -1,6 +1,6 @@ FROM colony-cdapp-dev-env/base:latest -ENV BLOCK_INGESTOR_HASH=68cee46ff28c4a24054e87633172e51cf406be7f +ENV BLOCK_INGESTOR_HASH=d224a8c6430ad5022d12f13dc7a47453f686c071 # Declare volumes to set up metadata VOLUME [ "/colonyCDapp/amplify/mock-data" ] diff --git a/src/components/frame/Extensions/pages/ExtensionDetailsPage/partials/ExtensionDetails/ExtensionDetails.tsx b/src/components/frame/Extensions/pages/ExtensionDetailsPage/partials/ExtensionDetails/ExtensionDetails.tsx index b17d46570c..5dacf23c68 100644 --- a/src/components/frame/Extensions/pages/ExtensionDetailsPage/partials/ExtensionDetails/ExtensionDetails.tsx +++ b/src/components/frame/Extensions/pages/ExtensionDetailsPage/partials/ExtensionDetails/ExtensionDetails.tsx @@ -1,14 +1,9 @@ import { ColonyRole, Id } from '@colony/colony-js'; -import { BigNumber } from 'ethers'; import React, { type FC } from 'react'; import SpecificSidePanel from '~common/Extensions/SpecificSidePanel/index.ts'; -import { DEFAULT_TOKEN_DECIMALS } from '~constants'; import { useAppContext } from '~context/AppContext/AppContext.ts'; import { useColonyContext } from '~context/ColonyContext/ColonyContext.ts'; -import useAsyncFunction from '~hooks/useAsyncFunction.ts'; -import { ActionTypes } from '~redux'; -import { type SetStakeFractionPayload } from '~redux/sagas/expenditures/setStakeFraction.ts'; import { addressHasRoles } from '~utils/checks/index.ts'; import { isInstalledExtensionData } from '~utils/extensions.ts'; @@ -48,25 +43,6 @@ const ExtensionDetails: FC = ({ extensionData }) => { extensionData.uninstallable ); - const setStakeFraction = useAsyncFunction({ - submit: ActionTypes.SET_STAKE_FRACTION, - error: ActionTypes.SET_STAKE_FRACTION_ERROR, - success: ActionTypes.SET_STAKE_FRACTION_SUCCESS, - }); - - const handleSetStakeFraction = async () => { - const DEFAULT_STAKE_FRACTION = BigNumber.from(2) - .mul(BigNumber.from(10).pow(DEFAULT_TOKEN_DECIMALS)) - .div(100); // 2% in wei - - const payload: SetStakeFractionPayload = { - colonyAddress: colony.colonyAddress, - stakeFraction: DEFAULT_STAKE_FRACTION.toString(), - }; - - await setStakeFraction(payload); - }; - return (
@@ -77,9 +53,6 @@ const ExtensionDetails: FC = ({ extensionData }) => { {canExtensionBeUninstalled && ( )} -
); From 7e12e5db7328a6de086f21d938e1ab39970ab8dc Mon Sep 17 00:00:00 2001 From: Dave Creaser Date: Thu, 16 May 2024 16:01:14 +0100 Subject: [PATCH 3/3] Remove comment --- src/redux/sagas/expenditures/setStakeFraction.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/redux/sagas/expenditures/setStakeFraction.ts b/src/redux/sagas/expenditures/setStakeFraction.ts index cbf063df89..9c82b0e4b8 100644 --- a/src/redux/sagas/expenditures/setStakeFraction.ts +++ b/src/redux/sagas/expenditures/setStakeFraction.ts @@ -19,8 +19,6 @@ function* setStakeFractionAction({ payload: { colonyAddress, stakeFraction }, meta, }: Action) { - // const apolloClient = getContext(ContextModule.ApolloClient); - const batchKey = 'setStakeFraction'; const { setStakeFraction }: Record =