Skip to content

Commit

Permalink
Remove redundant estimated deposit code (#8057)
Browse files Browse the repository at this point in the history
Co-authored-by: Shendy <[email protected]>
Co-authored-by: Rua Haszard <[email protected]>
  • Loading branch information
3 people authored Jan 25, 2024
1 parent e2a1732 commit 6f0f602
Show file tree
Hide file tree
Showing 21 changed files with 30 additions and 121 deletions.
5 changes: 5 additions & 0 deletions changelog/fix-7850-remove-redundant-estimated-deposits-code
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: Not user-facing: remove redundant code related to decoupling of transactions from deposits


1 change: 0 additions & 1 deletion client/components/account-balances/test/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ const createMockOverview = (
fee_percentage: 0,
status: 'paid',
},
nextScheduled: undefined,
instant: {
currency: currencyCode,
amount: instantAmount,
Expand Down
1 change: 0 additions & 1 deletion client/components/deposits-overview/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ interface RecentDeposits {

const useRecentDeposits = ( currency?: string ): RecentDeposits => {
const query = {
status_is_not: 'estimated',
store_currency_is: currency,
orderby: 'date',
order: 'desc',
Expand Down
27 changes: 4 additions & 23 deletions client/components/deposits-overview/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
useDeposits,
useAllDepositsOverviews,
} from 'wcpay/data';
import type { CachedDeposit, DepositStatus } from 'wcpay/types/deposits';
import type { CachedDeposit } from 'wcpay/types/deposits';
import type * as AccountOverview from 'wcpay/types/account-overview';

jest.mock( 'wcpay/data', () => ( {
Expand Down Expand Up @@ -87,10 +87,7 @@ const mockDeposits = [

// Creates a mock Overview object for the given currency code and balance amounts.
const createMockOverview = (
currencyCode: string,
depositAmount: number,
depositDate: number,
depositStatus: DepositStatus
currencyCode: string
): AccountOverview.Overview => {
return {
currency: currencyCode,
Expand All @@ -117,19 +114,6 @@ const createMockOverview = (
fee_percentage: 0,
status: 'paid',
},
nextScheduled: {
id: '456',
type: 'deposit',
amount: depositAmount,
automatic: true,
currency: currencyCode,
bankAccount: null,
created: Date.now(),
date: depositDate,
fee: 0,
fee_percentage: 0,
status: depositStatus,
},
instant: {
currency: currencyCode,
amount: 0,
Expand Down Expand Up @@ -158,7 +142,6 @@ const createMockNewAccountOverview = (
source_types: [],
},
lastPaid: undefined,
nextScheduled: undefined,
instant: undefined,
};
};
Expand Down Expand Up @@ -249,7 +232,7 @@ describe( 'Deposits Overview information', () => {
} );

test( 'Component Renders', () => {
mockOverviews( [ createMockOverview( 'usd', 100, 0, 'pending' ) ] );
mockOverviews( [ createMockOverview( 'usd' ) ] );
mockUseDeposits.mockReturnValue( {
depositsCount: 0,
deposits: mockDeposits,
Expand Down Expand Up @@ -310,9 +293,7 @@ describe( 'Deposits Overview information', () => {

test( 'Confirm notice renders if deposits blocked', () => {
mockAccount.deposits_blocked = true;
mockOverviews( [
createMockOverview( 'usd', 30000, 50000, 'pending' ),
] );
mockOverviews( [ createMockOverview( 'usd' ) ] );
mockUseDeposits.mockReturnValue( {
depositsCount: 0,
deposits: mockDeposits,
Expand Down
12 changes: 0 additions & 12 deletions client/data/deposits/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,6 @@ export const useDeposits = ( {
status_is: statusIs,
status_is_not: statusIsNot,
}: Query ): CachedDeposits => {
// Temporarily default to excluding estimated deposits.
// Client components can (temporarily) opt-in by passing `status_is=estimated`.
// When we remove estimated deposits from server / APIs we can remove this default.
if ( ! statusIsNot && statusIs !== 'estimated' ) {
statusIsNot = 'estimated';
}
return useSelect(
( select ) => {
const {
Expand Down Expand Up @@ -197,12 +191,6 @@ export const useDepositsSummary = ( {
status_is: statusIs,
status_is_not: statusIsNot,
}: Query ): DepositsSummaryCache => {
// Temporarily default to excluding estimated deposits.
// Client components can (temporarily) opt-in by passing `status_is=estimated`.
// When we remove estimated deposits from server / APIs we can remove this default.
if ( ! statusIsNot && statusIs !== 'estimated' ) {
statusIsNot = 'estimated';
}
return useSelect(
( select ) => {
const { getDepositsSummary, isResolving } = select( STORE_NAME );
Expand Down
2 changes: 0 additions & 2 deletions client/data/deposits/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export const getAllDepositsOverviews = ( state ) => {

const groups = {
lastPaid: deposit.last_paid,
nextScheduled: deposit.next_scheduled,
pending: balance.pending,
available: balance.available,
instant: balance.instant,
Expand All @@ -86,7 +85,6 @@ export const getAllDepositsOverviews = ( state ) => {
currencies[ currency ] = {
currency,
lastPaid: undefined,
nextScheduled: undefined,
pending: undefined,
available: undefined,
instant: undefined,
Expand Down
29 changes: 0 additions & 29 deletions client/data/deposits/test/overviews.fixture.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,6 @@
"fee_percentage": 0,
"created": 1619395200
}
],
"next_scheduled": [
{
"id": "wcpay_estimated_weekly_eur_1622678400",
"date": 1622678400000,
"type": "deposit",
"amount": 3343,
"status": "estimated",
"bankAccount": null,
"currency": "eur",
"automatic": true,
"fee": 0,
"fee_percentage": 0,
"created": 1622678400
},
{
"id": "wcpay_estimated_weekly_usd_1622678400",
"date": 1622678400000,
"type": "deposit",
"amount": 1656,
"status": "estimated",
"bankAccount": null,
"currency": "usd",
"automatic": true,
"fee": 0,
"fee_percentage": 0,
"created": 1622678400
}
]
},
"balance": {
Expand All @@ -69,7 +41,6 @@
{
"amount": 1656,
"currency": "usd",
"deposits_count": 2,
"source_types": {
"card": 1656
}
Expand Down
1 change: 0 additions & 1 deletion client/data/deposits/test/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ describe( 'Deposits reducer tests', () => {
};
const mockOverview = {
last_deposit: mockDeposits[ 0 ],
next_deposit: mockDeposits[ 1 ],
balance: { object: 'balance' },
deposits_schedule: { interval: 'daily' },
};
Expand Down
7 changes: 3 additions & 4 deletions client/data/deposits/test/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,13 @@ const filterQuery = {
dateAfter: '2020-04-29 23:59:59',
dateBetween: [ '2020-04-28 00:00:00', '2020-04-29 23:59:59' ],
statusIs: 'paid',
statusIsNot: 'estimated',
statusIsNot: 'failed',
storeCurrencyIs: 'gbp',
};

describe( 'getDepositsOverview resolver', () => {
const successfulResponse = {
last_deposit: depositsResponse.data[ 0 ],
next_deposit: depositsResponse.data[ 1 ],
balance: { pending: { amount: 5500 }, available: { amount: 0 } },
deposits_schedule: { interval: 'daily' },
};
Expand Down Expand Up @@ -149,7 +148,7 @@ describe( 'getDeposits resolver', () => {

const expectedQueryString =
// eslint-disable-next-line max-len
'page=1&pagesize=25&match=all&store_currency_is=gbp&date_before=2020-04-29%2003%3A59%3A59&date_after=2020-04-29%2004%3A00%3A00&date_between%5B0%5D=2020-04-28%2004%3A00%3A00&date_between%5B1%5D=2020-04-30%2003%3A59%3A59&status_is=paid&status_is_not=estimated';
'page=1&pagesize=25&match=all&store_currency_is=gbp&date_before=2020-04-29%2003%3A59%3A59&date_after=2020-04-29%2004%3A00%3A00&date_between%5B0%5D=2020-04-28%2004%3A00%3A00&date_between%5B1%5D=2020-04-30%2003%3A59%3A59&status_is=paid&status_is_not=failed';

beforeEach( () => {
generator = getDeposits( query );
Expand Down Expand Up @@ -208,7 +207,7 @@ describe( 'getDepositsSummary resolver', () => {
const query = filterQuery;
const expectedQueryString =
// eslint-disable-next-line max-len
'match=all&store_currency_is=gbp&date_before=2020-04-29%2003%3A59%3A59&date_after=2020-04-29%2004%3A00%3A00&date_between%5B0%5D=2020-04-28%2004%3A00%3A00&date_between%5B1%5D=2020-04-30%2003%3A59%3A59&status_is=paid&status_is_not=estimated';
'match=all&store_currency_is=gbp&date_before=2020-04-29%2003%3A59%3A59&date_after=2020-04-29%2004%3A00%3A00&date_between%5B0%5D=2020-04-28%2004%3A00%3A00&date_between%5B1%5D=2020-04-30%2003%3A59%3A59&status_is=paid&status_is_not=failed';
let generator = null;

beforeEach( () => {
Expand Down
3 changes: 0 additions & 3 deletions client/data/deposits/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ describe( 'Deposits overview selectors', () => {
overview: {
data: {
last_deposit: null,
next_deposit: null,
balance: { object: 'balance' },
deposits_schedule: { interval: 'daily' },
},
Expand Down Expand Up @@ -221,13 +220,11 @@ describe( 'Deposits overviews selectors', () => {

// Check the grouping
checkResult( first.lastPaid, 'deposit.last_paid', first );
checkResult( first.nextScheduled, 'deposit.next_scheduled', first );
checkResult( first.pending, 'balance.pending', first );
checkResult( first.available, 'balance.available', first );
checkResult( first.instant, 'balance.instant', first );

checkResult( second.lastPaid, 'deposit.last_paid', second );
checkResult( second.nextScheduled, 'deposit.next_scheduled', second );
checkResult( second.pending, 'balance.pending', second );
checkResult( second.available, 'balance.available', second );
checkResult( second.instant, 'balance.instant', second );
Expand Down
4 changes: 2 additions & 2 deletions client/payment-details/timeline/map-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const getDepositTimelineItem = (
body = []
) => {
let headline = '';
if ( event.deposit && ! event.deposit.id.includes( 'wcpay_estimated_' ) ) {
if ( event.deposit ) {
headline = sprintf(
isPositive
? // translators: %1$s - formatted amount, %2$s - deposit arrival date, <a> - link to the deposit
Expand Down Expand Up @@ -135,7 +135,7 @@ const getDepositTimelineItem = (
*/
const getFinancingPaydownTimelineItem = ( event, formattedAmount, body ) => {
let headline = '';
if ( event.deposit && ! event.deposit.id.includes( 'wcpay_estimated_' ) ) {
if ( event.deposit ) {
headline = sprintf(
// translators: %1$s - formatted amount, %2$s - deposit arrival date, <a> - link to the deposit
__(
Expand Down
6 changes: 1 addition & 5 deletions client/transactions/list/deposit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ interface DepositProps {
}

const Deposit: React.FC< DepositProps > = ( { depositId, dateAvailable } ) => {
if (
depositId &&
dateAvailable &&
! depositId.includes( 'wcpay_estimated_' )
) {
if ( depositId && dateAvailable ) {
const depositUrl = getAdminUrl( {
page: 'wc-admin',
path: '/payments/deposits/details',
Expand Down
2 changes: 0 additions & 2 deletions client/types/account-overview.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export interface Account {
export interface Balance {
amount: number;
currency: string;
deposits_count?: number;
source_types: Record< string, never >[];
}

Expand Down Expand Up @@ -59,7 +58,6 @@ export interface InstantBalance {
export interface Overview {
currency: string;
lastPaid: Deposit | undefined;
nextScheduled: Deposit | undefined;
pending: Balance | undefined;
available: Balance | undefined;
instant: InstantBalance | undefined;
Expand Down
5 changes: 1 addition & 4 deletions tests/fixtures/captured-payments/foreign-card.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@
},
"currency": "CAD",
"datetime": 1651997332,
"deposit": {
"id": "wcpay_estimated_daily_usd_1652572800",
"arrival_date": "1652572800"
},
"deposit": null,
"transaction_id": "txn_3Kx5Ae2EFxam75ai0P2BCbp0",
"transaction_details": {
"customer_currency": "CAD",
Expand Down
5 changes: 1 addition & 4 deletions tests/fixtures/captured-payments/fx-decimal.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
},
"currency": "EUR",
"datetime": 1651215495,
"deposit": {
"id": "wcpay_estimated_daily_usd_1651795200",
"arrival_date": "1651795200"
},
"deposit": null,
"transaction_id": "txn_3Ktnm22EFxam75ai0Sr9SR5A",
"transaction_details": {
"customer_currency": "EUR",
Expand Down
5 changes: 1 addition & 4 deletions tests/fixtures/captured-payments/fx-foreign-card.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@
},
"currency": "USD",
"datetime": 1651996460,
"deposit": {
"id": "wcpay_estimated_daily_usd_1652572800",
"arrival_date": "1652572800"
},
"deposit": null,
"transaction_id": "txn_3Kx4w12EFxam75ai0W5q4669",
"transaction_details": {
"customer_currency": "USD",
Expand Down
5 changes: 1 addition & 4 deletions tests/fixtures/captured-payments/fx-with-capped-fee.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@
},
"currency": "EUR",
"datetime": 1651998676,
"deposit": {
"id": "wcpay_estimated_weekly_usd_1652659200",
"arrival_date": "1652659200"
},
"deposit": null,
"transaction_id": "txn_3Kx5WG2HDHuit9Eg0ZrUH90z",
"transaction_details": {
"customer_currency": "EUR",
Expand Down
5 changes: 1 addition & 4 deletions tests/fixtures/captured-payments/fx.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@
},
"currency": "VND",
"datetime": 1651215552,
"deposit": {
"id": "wcpay_estimated_daily_usd_1651795200",
"arrival_date": "1651795200"
},
"deposit": null,
"transaction_id": "txn_3KtnnI2EFxam75ai06EEZYXQ",
"transaction_details": {
"customer_currency": "VND",
Expand Down
5 changes: 1 addition & 4 deletions tests/fixtures/captured-payments/only-base-fee.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
},
"currency": "USD",
"datetime": 1651997740,
"deposit": {
"id": "wcpay_estimated_daily_usd_1652572800",
"arrival_date": "1652572800"
},
"deposit": null,
"transaction_id": "txn_3Kx5HD2EFxam75ai1FerGksO",
"transaction_details": {
"customer_currency": "USD",
Expand Down
5 changes: 1 addition & 4 deletions tests/fixtures/captured-payments/subscription.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@
},
"currency": "EUR",
"datetime": 1651999249,
"deposit": {
"id": "wcpay_estimated_weekly_usd_1652659200",
"arrival_date": "1652659200"
},
"deposit": null,
"transaction_id": "txn_3Kx5fY2HDHuit9Eg0fQ402Ee",
"transaction_details": {
"customer_currency": "EUR",
Expand Down
Loading

0 comments on commit 6f0f602

Please sign in to comment.