Skip to content

Commit

Permalink
Merge pull request #2812 from JoinColony/fix/meta-tx-checks
Browse files Browse the repository at this point in the history
Hotfix for metatransaction checks
  • Loading branch information
chmanie authored Jul 31, 2024
2 parents 8260d6b + 91c8058 commit bea8109
Show file tree
Hide file tree
Showing 14 changed files with 19 additions and 58 deletions.
4 changes: 0 additions & 4 deletions amplify/backend/api/colonycdapp/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1812,10 +1812,6 @@ type Transaction @model {
sortKeyFields: ["from"]
)
"""
True if the transaction is a metatransaction
"""
metatransaction: Boolean!
"""
A title to show in the UI
"""
title: String # JSON string
Expand Down
1 change: 0 additions & 1 deletion scripts/create-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ const addTxToDb = async ({
methodContext: null,
methodName,
status: 'SUCCEEDED',
metatransaction: false,
title: null,
titleValues: null,
params: JSON.stringify(params),
Expand Down
1 change: 0 additions & 1 deletion src/graphql/fragments/transactions.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ fragment Transaction on Transaction {
methodContext
methodName
status
metatransaction
title
titleValues
options
Expand Down
18 changes: 5 additions & 13 deletions src/graphql/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1681,7 +1681,6 @@ export type CreateTransactionInput = {
id?: InputMaybe<Scalars['ID']>;
identifier?: InputMaybe<Scalars['String']>;
loadingRelated?: InputMaybe<Scalars['Boolean']>;
metatransaction: Scalars['Boolean'];
methodContext?: InputMaybe<Scalars['String']>;
methodName: Scalars['String'];
options?: InputMaybe<Scalars['String']>;
Expand Down Expand Up @@ -4164,7 +4163,6 @@ export type ModelSubscriptionTransactionFilterInput = {
id?: InputMaybe<ModelSubscriptionIdInput>;
identifier?: InputMaybe<ModelSubscriptionStringInput>;
loadingRelated?: InputMaybe<ModelSubscriptionBooleanInput>;
metatransaction?: InputMaybe<ModelSubscriptionBooleanInput>;
methodContext?: InputMaybe<ModelSubscriptionStringInput>;
methodName?: InputMaybe<ModelSubscriptionStringInput>;
options?: InputMaybe<ModelSubscriptionStringInput>;
Expand Down Expand Up @@ -4267,7 +4265,6 @@ export type ModelTransactionConditionInput = {
hash?: InputMaybe<ModelStringInput>;
identifier?: InputMaybe<ModelStringInput>;
loadingRelated?: InputMaybe<ModelBooleanInput>;
metatransaction?: InputMaybe<ModelBooleanInput>;
methodContext?: InputMaybe<ModelStringInput>;
methodName?: InputMaybe<ModelStringInput>;
not?: InputMaybe<ModelTransactionConditionInput>;
Expand Down Expand Up @@ -4304,7 +4301,6 @@ export type ModelTransactionFilterInput = {
id?: InputMaybe<ModelIdInput>;
identifier?: InputMaybe<ModelStringInput>;
loadingRelated?: InputMaybe<ModelBooleanInput>;
metatransaction?: InputMaybe<ModelBooleanInput>;
methodContext?: InputMaybe<ModelStringInput>;
methodName?: InputMaybe<ModelStringInput>;
not?: InputMaybe<ModelTransactionFilterInput>;
Expand Down Expand Up @@ -8145,8 +8141,6 @@ export type Transaction = {
identifier?: Maybe<Scalars['String']>;
/** True if a related transaction is loading */
loadingRelated?: Maybe<Scalars['Boolean']>;
/** True if the transaction is a metatransaction */
metatransaction: Scalars['Boolean'];
/** Context in which method is used e.g. setOneTxRole */
methodContext?: Maybe<Scalars['String']>;
/** The name of the contract method used */
Expand Down Expand Up @@ -8658,7 +8652,6 @@ export type UpdateTransactionInput = {
id: Scalars['ID'];
identifier?: InputMaybe<Scalars['String']>;
loadingRelated?: InputMaybe<Scalars['Boolean']>;
metatransaction?: InputMaybe<Scalars['Boolean']>;
methodContext?: InputMaybe<Scalars['String']>;
methodName?: InputMaybe<Scalars['String']>;
options?: InputMaybe<Scalars['String']>;
Expand Down Expand Up @@ -8992,7 +8985,7 @@ export type UserTokenBalanceDataFragment = { __typename?: 'GetUserTokenBalanceRe

export type NativeTokenStatusFragment = { __typename?: 'NativeTokenStatus', mintable?: boolean | null, unlockable?: boolean | null, unlocked?: boolean | null };

export type TransactionFragment = { __typename?: 'Transaction', id: string, context: ClientType, createdAt: string, from: string, colonyAddress: string, identifier?: string | null, params?: string | null, groupId: string, hash?: string | null, methodContext?: string | null, methodName: string, status: TransactionStatus, metatransaction: boolean, title?: string | null, titleValues?: string | null, options?: string | null, error?: { __typename?: 'TransactionError', type: TransactionErrors, message: string } | null, group: { __typename?: 'TransactionGroup', id: string, groupId: string, key: string, index: number, description?: string | null, descriptionValues?: string | null, title?: string | null, titleValues?: string | null } };
export type TransactionFragment = { __typename?: 'Transaction', id: string, context: ClientType, createdAt: string, from: string, colonyAddress: string, identifier?: string | null, params?: string | null, groupId: string, hash?: string | null, methodContext?: string | null, methodName: string, status: TransactionStatus, title?: string | null, titleValues?: string | null, options?: string | null, error?: { __typename?: 'TransactionError', type: TransactionErrors, message: string } | null, group: { __typename?: 'TransactionGroup', id: string, groupId: string, key: string, index: number, description?: string | null, descriptionValues?: string | null, title?: string | null, titleValues?: string | null } };

export type UserFragment = { __typename?: 'User', bridgeCustomerId?: string | null, walletAddress: string, profile?: { __typename?: 'Profile', avatar?: string | null, bio?: string | null, displayName?: string | null, displayNameChanged?: string | null, email?: string | null, location?: string | null, thumbnail?: string | null, website?: string | null, preferredCurrency?: SupportedCurrencies | null, isAutoOfframpEnabled?: boolean | null, meta?: { __typename?: 'ProfileMetadata', metatransactionsEnabled?: boolean | null, decentralizedModeEnabled?: boolean | null, customRpc?: string | null } | null } | null, privateBetaInviteCode?: { __typename?: 'PrivateBetaInviteCode', id: string, shareableInvites?: number | null } | null };

Expand Down Expand Up @@ -9173,7 +9166,7 @@ export type CreateTransactionMutationVariables = Exact<{
}>;


export type CreateTransactionMutation = { __typename?: 'Mutation', createTransaction?: { __typename?: 'Transaction', id: string, context: ClientType, createdAt: string, from: string, colonyAddress: string, identifier?: string | null, params?: string | null, groupId: string, hash?: string | null, methodContext?: string | null, methodName: string, status: TransactionStatus, metatransaction: boolean, title?: string | null, titleValues?: string | null, options?: string | null, error?: { __typename?: 'TransactionError', type: TransactionErrors, message: string } | null, group: { __typename?: 'TransactionGroup', id: string, groupId: string, key: string, index: number, description?: string | null, descriptionValues?: string | null, title?: string | null, titleValues?: string | null } } | null };
export type CreateTransactionMutation = { __typename?: 'Mutation', createTransaction?: { __typename?: 'Transaction', id: string, context: ClientType, createdAt: string, from: string, colonyAddress: string, identifier?: string | null, params?: string | null, groupId: string, hash?: string | null, methodContext?: string | null, methodName: string, status: TransactionStatus, title?: string | null, titleValues?: string | null, options?: string | null, error?: { __typename?: 'TransactionError', type: TransactionErrors, message: string } | null, group: { __typename?: 'TransactionGroup', id: string, groupId: string, key: string, index: number, description?: string | null, descriptionValues?: string | null, title?: string | null, titleValues?: string | null } } | null };

export type UpdateTransactionMutationVariables = Exact<{
input: UpdateTransactionInput;
Expand Down Expand Up @@ -9530,22 +9523,22 @@ export type GetUserTransactionsQueryVariables = Exact<{
}>;


export type GetUserTransactionsQuery = { __typename?: 'Query', getTransactionsByUser?: { __typename?: 'ModelTransactionConnection', nextToken?: string | null, items: Array<{ __typename?: 'Transaction', id: string, context: ClientType, createdAt: string, from: string, colonyAddress: string, identifier?: string | null, params?: string | null, groupId: string, hash?: string | null, methodContext?: string | null, methodName: string, status: TransactionStatus, metatransaction: boolean, title?: string | null, titleValues?: string | null, options?: string | null, error?: { __typename?: 'TransactionError', type: TransactionErrors, message: string } | null, group: { __typename?: 'TransactionGroup', id: string, groupId: string, key: string, index: number, description?: string | null, descriptionValues?: string | null, title?: string | null, titleValues?: string | null } } | null> } | null };
export type GetUserTransactionsQuery = { __typename?: 'Query', getTransactionsByUser?: { __typename?: 'ModelTransactionConnection', nextToken?: string | null, items: Array<{ __typename?: 'Transaction', id: string, context: ClientType, createdAt: string, from: string, colonyAddress: string, identifier?: string | null, params?: string | null, groupId: string, hash?: string | null, methodContext?: string | null, methodName: string, status: TransactionStatus, title?: string | null, titleValues?: string | null, options?: string | null, error?: { __typename?: 'TransactionError', type: TransactionErrors, message: string } | null, group: { __typename?: 'TransactionGroup', id: string, groupId: string, key: string, index: number, description?: string | null, descriptionValues?: string | null, title?: string | null, titleValues?: string | null } } | null> } | null };

export type GetTransactionsByGroupQueryVariables = Exact<{
userAddress: Scalars['ID'];
groupId: Scalars['ID'];
}>;


export type GetTransactionsByGroupQuery = { __typename?: 'Query', getTransactionsByUserAndGroup?: { __typename?: 'ModelTransactionConnection', items: Array<{ __typename?: 'Transaction', id: string, context: ClientType, createdAt: string, from: string, colonyAddress: string, identifier?: string | null, params?: string | null, groupId: string, hash?: string | null, methodContext?: string | null, methodName: string, status: TransactionStatus, metatransaction: boolean, title?: string | null, titleValues?: string | null, options?: string | null, error?: { __typename?: 'TransactionError', type: TransactionErrors, message: string } | null, group: { __typename?: 'TransactionGroup', id: string, groupId: string, key: string, index: number, description?: string | null, descriptionValues?: string | null, title?: string | null, titleValues?: string | null } } | null> } | null };
export type GetTransactionsByGroupQuery = { __typename?: 'Query', getTransactionsByUserAndGroup?: { __typename?: 'ModelTransactionConnection', items: Array<{ __typename?: 'Transaction', id: string, context: ClientType, createdAt: string, from: string, colonyAddress: string, identifier?: string | null, params?: string | null, groupId: string, hash?: string | null, methodContext?: string | null, methodName: string, status: TransactionStatus, title?: string | null, titleValues?: string | null, options?: string | null, error?: { __typename?: 'TransactionError', type: TransactionErrors, message: string } | null, group: { __typename?: 'TransactionGroup', id: string, groupId: string, key: string, index: number, description?: string | null, descriptionValues?: string | null, title?: string | null, titleValues?: string | null } } | null> } | null };

export type GetTransactionQueryVariables = Exact<{
id: Scalars['ID'];
}>;


export type GetTransactionQuery = { __typename?: 'Query', getTransaction?: { __typename?: 'Transaction', id: string, context: ClientType, createdAt: string, from: string, colonyAddress: string, identifier?: string | null, params?: string | null, groupId: string, hash?: string | null, methodContext?: string | null, methodName: string, status: TransactionStatus, metatransaction: boolean, title?: string | null, titleValues?: string | null, options?: string | null, error?: { __typename?: 'TransactionError', type: TransactionErrors, message: string } | null, group: { __typename?: 'TransactionGroup', id: string, groupId: string, key: string, index: number, description?: string | null, descriptionValues?: string | null, title?: string | null, titleValues?: string | null } } | null };
export type GetTransactionQuery = { __typename?: 'Query', getTransaction?: { __typename?: 'Transaction', id: string, context: ClientType, createdAt: string, from: string, colonyAddress: string, identifier?: string | null, params?: string | null, groupId: string, hash?: string | null, methodContext?: string | null, methodName: string, status: TransactionStatus, title?: string | null, titleValues?: string | null, options?: string | null, error?: { __typename?: 'TransactionError', type: TransactionErrors, message: string } | null, group: { __typename?: 'TransactionGroup', id: string, groupId: string, key: string, index: number, description?: string | null, descriptionValues?: string | null, title?: string | null, titleValues?: string | null } } | null };

export type GetPendingTransactionsQueryVariables = Exact<{
userAddress: Scalars['ID'];
Expand Down Expand Up @@ -10564,7 +10557,6 @@ export const TransactionFragmentDoc = gql`
methodContext
methodName
status
metatransaction
title
titleValues
options
Expand Down
5 changes: 1 addition & 4 deletions src/redux/actionCreators/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export const createTransactionAction = (
options,
params = [],
ready,
metatransaction = false,
title,
titleValues,
}: TxConfig,
Expand All @@ -45,7 +44,6 @@ export const createTransactionAction = (
params,
status:
ready === false ? TransactionStatus.Created : TransactionStatus.Ready,
metatransaction,
title,
titleValues,
},
Expand Down Expand Up @@ -124,11 +122,10 @@ export const transactionHashReceived = (
export const transactionSucceeded = (
id: string,
payload: TransactionSucceededPayload,
metatransaction = false,
): AllActions => ({
type: ActionTypes.TRANSACTION_SUCCEEDED,
payload,
meta: { id, metatransaction },
meta: { id },
});

export const transactionPending = (id: string): AllActions => ({
Expand Down
1 change: 0 additions & 1 deletion src/redux/immutable/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ interface TransactionRecordProps {
receipt?: TransactionReceipt;
status: TransactionStatus;
loadingRelated?: boolean;
metatransaction: boolean;
title?: MessageDescriptor;
titleValues?: SimpleMessageValues;
}
Expand Down
20 changes: 2 additions & 18 deletions src/redux/sagas/transactions/createTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import { filterUniqueAction } from '~utils/actions.ts';

import { createTransactionAction } from '../../actionCreators/index.ts';
import { ActionTypes } from '../../actionTypes.ts';
import { takeFrom, getCanUserSendMetatransactions } from '../utils/index.ts';
import { takeFrom, metatransactionsEnabled } from '../utils/index.ts';

import estimateGasCost from './estimateGasCost.ts';
import sendTransaction from './sendTransaction.ts';

export function* createTransaction(id: string, config: TxConfig) {
const { address: walletAddress } = getContext(ContextModule.Wallet);
const shouldSendMetatransaction = yield getCanUserSendMetatransactions();
const shouldSendMetatransaction = yield metatransactionsEnabled();

if (!walletAddress) {
throw new Error(
Expand All @@ -46,7 +46,6 @@ export function* createTransaction(id: string, config: TxConfig) {
identifier: config.identifier,
methodContext: config.methodContext,
methodName: config.methodName,
metatransaction: config.metatransaction || false,
options: config.options,
params: config.params,
status:
Expand All @@ -61,21 +60,6 @@ export function* createTransaction(id: string, config: TxConfig) {
yield put(
createTransactionAction(id, walletAddress, {
...config,
metatransaction:
/*
* This allows us to manually "force" a transaction to never be executed
* as a Metatransaction
*
* This is useful in places where we have transactions we don't want to
* pay for ourselves.
*
* However this is VERY DANGEROUS, so must be treated with the utmost care
* as it has very serious gas cost implications if the user is not aware
* they are sending a transaction on mainnet !!!
*/
typeof config.metatransaction === 'boolean'
? config.metatransaction
: true,
}),
);
} else {
Expand Down
11 changes: 6 additions & 5 deletions src/redux/sagas/transactions/sendTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { mergePayload } from '~utils/actions.ts';
import { transactionSendError } from '../../actionCreators/index.ts';
import { type ActionTypes } from '../../actionTypes.ts';
import { type Action } from '../../types/actions/index.ts';
import { getColonyManager } from '../utils/index.ts';
import { getColonyManager, metatransactionsEnabled } from '../utils/index.ts';

import getMetatransactionPromise from './getMetatransactionPromise.ts';
import getTransactionPromise from './getTransactionPromise.ts';
Expand All @@ -19,14 +19,15 @@ export default function* sendTransaction({
meta: { id },
}: Action<ActionTypes.TRANSACTION_SEND>) {
const transaction = yield getTransaction(id, 'cache-first');
const { status, context, identifier, metatransaction, methodName } =
transaction;
const { status, context, identifier, methodName } = transaction;

if (status !== TransactionStatus.Ready) {
throw new Error(`Transaction ${id} is not ready to send.`);
}
const colonyManager = yield getColonyManager();

const metaTxEnabled = yield metatransactionsEnabled();

let contextClient: any; // Disregard the `any`. The new ColonyJS messed up all the types
if (context === ClientType.TokenClient) {
contextClient = yield colonyManager.getTokenClient(identifier as string);
Expand All @@ -35,7 +36,7 @@ export default function* sendTransaction({
identifier as string,
);
} else if (
metatransaction &&
metaTxEnabled &&
methodName === TRANSACTION_METHODS.DeployTokenAuthority
) {
contextClient = colonyManager.networkClient;
Expand All @@ -50,7 +51,7 @@ export default function* sendTransaction({
throw new Error('Context client failed to instantiate');
}

const promiseMethod = metatransaction
const promiseMethod = metaTxEnabled
? getMetatransactionPromise
: getTransactionPromise;

Expand Down
4 changes: 2 additions & 2 deletions src/redux/sagas/transactions/transactionChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const channelGetTransactionReceipt = async ({
};

const channelGetEventData = async ({
tx: { id, params = [], metatransaction },
tx: { id, params = [] },
receipt,
client,
emit,
Expand All @@ -144,7 +144,7 @@ const channelGetEventData = async ({
if (receipt.contractAddress) {
txSucceededEvent.deployedContractAddress = receipt.contractAddress;
}
emit(transactionSucceeded(id, txSucceededEvent, metatransaction));
emit(transactionSucceeded(id, txSucceededEvent));
return eventData;
} catch (caughtError) {
console.error(caughtError);
Expand Down
4 changes: 2 additions & 2 deletions src/redux/sagas/utils/effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
type Action,
} from '../../types/actions/index.ts';

import { getCanUserSendMetatransactions } from './getCanUserSendMetatransactions.ts';
import { metatransactionsEnabled } from './getCanUserSendMetatransactions.ts';

/*
* Effect to take a specific action from a channel.
Expand Down Expand Up @@ -100,7 +100,7 @@ export const takeLatestCancellable = (
};

export function* initiateTransaction(id: string) {
const shouldSendMetatransaction = yield getCanUserSendMetatransactions();
const shouldSendMetatransaction = yield metatransactionsEnabled();

yield transactionSetReady(id);

Expand Down
2 changes: 1 addition & 1 deletion src/redux/sagas/utils/getCanUserSendMetatransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '~gql';
import { canUseMetatransactions } from '~utils/checks/index.ts';

export function* getCanUserSendMetatransactions() {
export function* metatransactionsEnabled() {
const metatransactionsAvailable = canUseMetatransactions();

if (!metatransactionsAvailable) {
Expand Down
1 change: 0 additions & 1 deletion src/redux/types/actions/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export type TransactionCreatedPayload = Pick<
| 'identifier'
| 'methodContext'
| 'methodName'
| 'metatransaction'
| 'options'
| 'params'
| 'status'
Expand Down
4 changes: 0 additions & 4 deletions src/state/transactionState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export const convertTransactionType = ({
hash,
id,
identifier,
metatransaction,
methodContext,
methodName,
params,
Expand Down Expand Up @@ -77,7 +76,6 @@ export const convertTransactionType = ({
from,
id,
identifier: identifier as AddressOrENSName,
metatransaction,
methodName,
status,
group: txGroup,
Expand Down Expand Up @@ -258,7 +256,6 @@ export const addTransactionToDb = async (
status,
title,
titleValues,
metatransaction,
}: TransactionCreatedPayload,
) => {
let colonyAddress = '0x';
Expand Down Expand Up @@ -302,7 +299,6 @@ export const addTransactionToDb = async (
methodContext: methodContext || null,
methodName,
status,
metatransaction,
title: JSON.stringify(title) || null,
titleValues: JSON.stringify(titleValues) || null,
params: txParams,
Expand Down
Loading

0 comments on commit bea8109

Please sign in to comment.