Skip to content

Commit

Permalink
Refactored Fufil to American spelling
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamoftrees committed Sep 28, 2023
1 parent 53025db commit 8f062af
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
Checkout,
ERC20ItemRequirement,
ERC721ItemRequirement,
FulfilmentTransaction,
FulfillmentTransaction,
GasAmount,
GasTokenType,
ItemType,
Expand All @@ -27,7 +27,7 @@ interface SmartCheckoutProps {
export const SmartCheckoutForm = ({ checkout, provider }: SmartCheckoutProps) => {
const [itemRequirements, setItemRequirements] = useState<(NativeItemRequirement | ERC20ItemRequirement | ERC721ItemRequirement)[]>([]);
const [itemRequirementsError, setItemRequirementsError] = useState<string>('');
const [transactionOrGasAmount, setTransactionOrGasAmount] = useState<FulfilmentTransaction | GasAmount>(
const [transactionOrGasAmount, setTransactionOrGasAmount] = useState<FulfillmentTransaction | GasAmount>(
{
type: TransactionOrGasType.GAS,
gasToken: {
Expand Down Expand Up @@ -340,7 +340,7 @@ export const SmartCheckoutForm = ({ checkout, provider }: SmartCheckoutProps) =>
<Option optionKey="erc721">
<Option.Label>ERC721</Option.Label>
</Option>
</Select>
</Select>
</td>
<td>
<FormControl validationStatus={amountError ? 'error' : 'success'}>
Expand Down
2 changes: 1 addition & 1 deletion packages/checkout/sdk/src/errors/checkoutError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export enum CheckoutErrorType {
GET_ERC20_ALLOWANCE_ERROR = 'GET_ERC20_ALLOWANCE_ERROR',
GET_ERC721_ALLOWANCE_ERROR = 'GET_ERC721_ALLOWANCE_ERROR',
EXECUTE_APPROVAL_TRANSACTION_ERROR = 'EXECUTE_APPROVAL_TRANSACTION_ERROR',
EXECUTE_FULFILMENT_TRANSACTION_ERROR = 'EXECUTE_FULFILMENT_TRANSACTION_ERROR',
EXECUTE_FULFILLMENT_TRANSACTION_ERROR = 'EXECUTE_FULFILLMENT_TRANSACTION_ERROR',
SIGN_MESSAGE_ERROR = 'SIGN_MESSAGE_ERROR',
BRIDGE_GAS_ESTIMATE_ERROR = 'BRIDGE_GAS_ESTIMATE_ERROR',
ORDER_FEE_ERROR = 'ORDER_FEE_ERROR',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PopulatedTransaction, TypedDataDomain } from 'ethers';
import {
getUnsignedERC20ApprovalTransactions,
getUnsignedERC721Transactions,
getUnsignedFulfilmentTransactions,
getUnsignedFulfillmentTransactions,
getUnsignedMessage,
} from './getUnsignedActions';

Expand Down Expand Up @@ -55,7 +55,7 @@ describe('getUnsignedActions', () => {

await expect(getUnsignedERC721Transactions(actions)).resolves.toEqual({
approvalTransactions: [{ from: '0xAPPROVAL1' }, { from: '0xAPPROVAL2' }],
fulfilmentTransactions: [{ from: '0xTRANSACTION1' }, { from: '0xTRANSACTION2' }],
fulfillmentTransactions: [{ from: '0xTRANSACTION1' }, { from: '0xTRANSACTION2' }],
});
});

Expand All @@ -64,7 +64,7 @@ describe('getUnsignedActions', () => {

await expect(getUnsignedERC721Transactions(actions)).resolves.toEqual({
approvalTransactions: [],
fulfilmentTransactions: [],
fulfillmentTransactions: [],
});
});
});
Expand Down Expand Up @@ -100,8 +100,8 @@ describe('getUnsignedActions', () => {
});
});

describe('getUnsignedFulfilmentTransactions', () => {
it('should get the unsigned fulfil transactions', async () => {
describe('getUnsignedFulfillmentTransactions', () => {
it('should get the unsigned fulfill transactions', async () => {
const actions: Action[] = [
{
type: ActionType.TRANSACTION,
Expand All @@ -120,14 +120,14 @@ describe('getUnsignedActions', () => {
},
];

await expect(getUnsignedFulfilmentTransactions(actions)).resolves
await expect(getUnsignedFulfillmentTransactions(actions)).resolves
.toEqual([{ from: '0xTRANSACTION1' }, { from: '0xTRANSACTION2' }]);
});

it('should return an empty arrays if no transactions', async () => {
const actions: Action[] = [];

await expect(getUnsignedFulfilmentTransactions(actions)).resolves.toEqual([]);
await expect(getUnsignedFulfillmentTransactions(actions)).resolves.toEqual([]);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ export const getUnsignedERC721Transactions = async (
actions: Action[],
): Promise<UnsignedTransactions> => {
let approvalTransactions: TransactionRequest[] = [];
let fulfilmentTransactions: TransactionRequest[] = [];
let fulfillmentTransactions: TransactionRequest[] = [];

const approvalPromises: Promise<TransactionRequest>[] = [];
const fulfilmentPromises: Promise<TransactionRequest>[] = [];
const fulfillmentPromises: Promise<TransactionRequest>[] = [];
for (const action of actions) {
if (action.type !== ActionType.TRANSACTION) continue;
if (action.purpose === TransactionPurpose.APPROVAL) {
approvalPromises.push(action.buildTransaction());
}
if (action.purpose === TransactionPurpose.FULFILL_ORDER) {
fulfilmentPromises.push(action.buildTransaction());
fulfillmentPromises.push(action.buildTransaction());
}
}
approvalTransactions = await Promise.all(approvalPromises);
fulfilmentTransactions = await Promise.all(fulfilmentPromises);
fulfillmentTransactions = await Promise.all(fulfillmentPromises);

return {
approvalTransactions,
fulfilmentTransactions,
fulfillmentTransactions,
};
};

Expand All @@ -50,21 +50,21 @@ export const getUnsignedERC20ApprovalTransactions = async (
return approvalTransactions;
};

export const getUnsignedFulfilmentTransactions = async (
export const getUnsignedFulfillmentTransactions = async (
actions: Action[],
): Promise<TransactionRequest[]> => {
let fulfilmentTransactions: TransactionRequest[] = [];
let fulfillmentTransactions: TransactionRequest[] = [];

const fulfilmentPromises: Promise<TransactionRequest>[] = [];
const fulfillmentPromises: Promise<TransactionRequest>[] = [];
for (const action of actions) {
if (action.type !== ActionType.TRANSACTION) continue;
if (action.purpose === TransactionPurpose.FULFILL_ORDER) {
fulfilmentPromises.push(action.buildTransaction());
fulfillmentPromises.push(action.buildTransaction());
}
}
fulfilmentTransactions = await Promise.all(fulfilmentPromises);
fulfillmentTransactions = await Promise.all(fulfillmentPromises);

return fulfilmentTransactions;
return fulfillmentTransactions;
};

export const getUnsignedMessage = (
Expand Down
36 changes: 18 additions & 18 deletions packages/checkout/sdk/src/smartCheckout/actions/signActions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* eslint-disable no-underscore-dangle */
import { TransactionRequest, Web3Provider } from '@ethersproject/providers';
import { TypedDataDomain } from 'ethers';
import { signApprovalTransactions, signFulfilmentTransactions, signMessage } from './signActions';
import { signApprovalTransactions, signFulfillmentTransactions, signMessage } from './signActions';
import { CheckoutErrorType } from '../../errors';
import { SignTransactionStatusType, UnsignedMessage } from './types';

Expand Down Expand Up @@ -108,8 +108,8 @@ describe('signActions', () => {
});
});

describe('signFulfilmentTransactions', () => {
it('should sign fulfilment transactions', async () => {
describe('signFulfillmentTransactions', () => {
it('should sign fulfillment transactions', async () => {
mockProvider = {
getSigner: jest.fn().mockReturnValue({
sendTransaction: jest.fn().mockResolvedValue({
Expand All @@ -123,22 +123,22 @@ describe('signActions', () => {
const approvalTransactions: TransactionRequest[] = [
{
to: '0x123',
data: '0xFULFILMENT1',
data: '0xFULFILLMENT1',
},
{
to: '0x123',
data: '0xFULFILMENT2',
data: '0xFULFILLMENT2',
},
];

await signFulfilmentTransactions(mockProvider, approvalTransactions);
await signFulfillmentTransactions(mockProvider, approvalTransactions);
expect(mockProvider.getSigner().sendTransaction).toHaveBeenCalledTimes(2);
expect(mockProvider.getSigner().sendTransaction).toHaveBeenCalledWith({
data: '0xFULFILMENT1',
data: '0xFULFILLMENT1',
to: '0x123',
});
expect(mockProvider.getSigner().sendTransaction).toHaveBeenCalledWith({
data: '0xFULFILMENT2',
data: '0xFULFILLMENT2',
to: '0x123',
});
});
Expand All @@ -155,32 +155,32 @@ describe('signActions', () => {
}),
} as unknown as Web3Provider;

const fulfilmentTransactions: TransactionRequest[] = [
const fulfillmentTransactions: TransactionRequest[] = [
{
to: '0x123',
data: '0xAPPROVAL1',
},
];

const result = await signFulfilmentTransactions(mockProvider, fulfilmentTransactions);
const result = await signFulfillmentTransactions(mockProvider, fulfillmentTransactions);
expect(result).toEqual({
type: SignTransactionStatusType.FAILED,
transactionHash: '0xHASH',
reason: 'Fulfilment transaction failed and was reverted',
reason: 'Fulfillment transaction failed and was reverted',
});
});

it('should throw error when sending the fulfilment transaction errors', async () => {
it('should throw error when sending the fulfillment transaction errors', async () => {
mockProvider = {
getSigner: jest.fn().mockReturnValue({
sendTransaction: jest.fn().mockRejectedValue(new Error('fulfilment error')),
sendTransaction: jest.fn().mockRejectedValue(new Error('fulfillment error')),
}),
} as unknown as Web3Provider;

const approvalTransactions: TransactionRequest[] = [
{
to: '0x123',
data: '0xFULFILMENT1',
data: '0xFULFILLMENT1',
},
];

Expand All @@ -189,17 +189,17 @@ describe('signActions', () => {
let data;

try {
await signFulfilmentTransactions(mockProvider, approvalTransactions);
await signFulfillmentTransactions(mockProvider, approvalTransactions);
} catch (err: any) {
message = err.message;
type = err.type;
data = err.data;
}

expect(message).toEqual('An error occurred while executing the fulfilment transaction');
expect(type).toEqual(CheckoutErrorType.EXECUTE_FULFILMENT_TRANSACTION_ERROR);
expect(message).toEqual('An error occurred while executing the fulfillment transaction');
expect(type).toEqual(CheckoutErrorType.EXECUTE_FULFILLMENT_TRANSACTION_ERROR);
expect(data).toEqual({
message: 'fulfilment error',
message: 'fulfillment error',
});
});
});
Expand Down
12 changes: 6 additions & 6 deletions packages/checkout/sdk/src/smartCheckout/actions/signActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,21 @@ export const signApprovalTransactions = async (
};
};

export const signFulfilmentTransactions = async (
export const signFulfillmentTransactions = async (
provider: Web3Provider,
fulfilmentTransactions: TransactionRequest[],
fulfillmentTransactions: TransactionRequest[],
): Promise<SignTransactionResult> => {
let receipts: TransactionReceipt[] = [];

try {
const response = await Promise.all(fulfilmentTransactions.map(
const response = await Promise.all(fulfillmentTransactions.map(
(transaction) => provider.getSigner().sendTransaction(transaction),
));
receipts = await Promise.all(response.map((transaction) => transaction.wait()));
} catch (err: any) {
throw new CheckoutError(
'An error occurred while executing the fulfilment transaction',
CheckoutErrorType.EXECUTE_FULFILMENT_TRANSACTION_ERROR,
'An error occurred while executing the fulfillment transaction',
CheckoutErrorType.EXECUTE_FULFILLMENT_TRANSACTION_ERROR,
{
message: err.message,
},
Expand All @@ -70,7 +70,7 @@ export const signFulfilmentTransactions = async (
return {
type: SignTransactionStatusType.FAILED,
transactionHash: receipt.transactionHash,
reason: 'Fulfilment transaction failed and was reverted',
reason: 'Fulfillment transaction failed and was reverted',
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/checkout/sdk/src/smartCheckout/actions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { TypedDataDomain, TypedDataField } from 'ethers';

export type UnsignedTransactions = {
approvalTransactions: TransactionRequest[];
fulfilmentTransactions: TransactionRequest[];
fulfillmentTransactions: TransactionRequest[];
};

export type UnsignedMessage = {
Expand Down
Loading

0 comments on commit 8f062af

Please sign in to comment.