diff --git a/src/core/pay.ts b/src/core/pay.ts index 5cda844..2bfe033 100644 --- a/src/core/pay.ts +++ b/src/core/pay.ts @@ -220,6 +220,7 @@ export const pay = async ( challengePeriodExtension: paymentProps.challengePeriodExtension, tokenAddress, amount, + buyer: walletUser, }); const _arbitrator = addrs.common.arbitrator || ADDRESS_ZERO; diff --git a/src/helpers/__tests__/validPayment.test.tsx b/src/helpers/__tests__/validPayment.test.tsx index e3fcf67..5a55150 100644 --- a/src/helpers/__tests__/validPayment.test.tsx +++ b/src/helpers/__tests__/validPayment.test.tsx @@ -1,8 +1,9 @@ -import { IPaymentProps } from "../../typing"; +import { IValidateProps } from "../../typing"; import { validateParameters } from "../validateParameters"; -const params: IPaymentProps = { +const params: IValidateProps = { seller: "0x7bD733DBc10A1cD04e1e51cC89450941c928ee62", + buyer: "0x484Ee4Eb8CB165F4FBFd897f84283142C8f1fD3a", arbitrator: "0x7bD733DBc10A1cD04e1e51cC89450941c928ee62", marketplace: "0x7bD733DBc10A1cD04e1e51cC89450941c928ee62", amount: 1, diff --git a/src/helpers/validateParameters.ts b/src/helpers/validateParameters.ts index f5018c5..657c2a6 100644 --- a/src/helpers/validateParameters.ts +++ b/src/helpers/validateParameters.ts @@ -1,4 +1,4 @@ -import { IPaymentProps } from "../typing"; +import { IValidateProps } from "../typing"; import { ETH_ADDRESS } from "./constants"; import { validateAddress, @@ -13,7 +13,7 @@ export interface AddressesToCheck { tokenAddress?: string; } -export const validateParameters = async (data: IPaymentProps) => { +export const validateParameters = async (data: IValidateProps) => { const { seller, arbitrator, @@ -24,6 +24,7 @@ export const validateParameters = async (data: IPaymentProps) => { arbitratorFee, marketplaceFee, tokenAddress = ETH_ADDRESS, + buyer, } = data; const addrs: AddressToReturn = await validateEns({ @@ -38,6 +39,10 @@ export const validateParameters = async (data: IPaymentProps) => { throw new Error(e.message); } + if (buyer.toLowerCase() === seller.toLowerCase()) { + throw new Error("Buyer cannot be the same as the seller"); + } + if (amount <= 0) { throw new Error("Invalid amount"); } diff --git a/src/typing/index.ts b/src/typing/index.ts index 1180edc..b49a628 100644 --- a/src/typing/index.ts +++ b/src/typing/index.ts @@ -45,6 +45,10 @@ export interface IPaymentProps { challengePeriodExtension?: number; } +export interface IValidateProps extends IPaymentProps { + buyer: string; +} + export interface IPaymentPropsData extends IPaymentProps { ensAddresses?: IEnsAddresses; } diff --git a/src/ui/render/pay.ts b/src/ui/render/pay.ts index fcc35d7..c6b1e30 100644 --- a/src/ui/render/pay.ts +++ b/src/ui/render/pay.ts @@ -9,6 +9,7 @@ import { import { toast } from "ui/internal/notification/toast"; import { renderModal } from "ui/internal/config/render"; import { PayModal } from "ui/internal/modals"; +import { getWalletAccount } from "wallet"; /** * Opens a payment modal, which summarizes the escrow parameters for the user (buyer) and displays a button to Pay. @@ -122,7 +123,8 @@ export const pay = async ( const data: IPaymentPropsData = paymentProps; try { - const addrs = await validateParameters(data); + const walletUser = await getWalletAccount(); + const addrs = await validateParameters({ ...data, buyer: walletUser }); Object.entries(addrs.common).forEach(([key, value]) => { paymentProps[key] = value;