Skip to content

Commit

Permalink
Pass currency and do not pass transaction_ids parameter to create ins…
Browse files Browse the repository at this point in the history
…tant deposit (#7828)
  • Loading branch information
shendy-a8c authored Jan 15, 2024
1 parent 6bf63af commit 48c3a5d
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 23 deletions.
4 changes: 4 additions & 0 deletions changelog/add-7711-instant-deposit-currency
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: update

Pass currency parameter and not transaction_ids parameter when creating instant deposit.
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 @@ -145,7 +145,6 @@ const createMockOverview = (
fee: 0,
net: 0,
fee_percentage: 0,
transaction_ids: [],
},
};
};
Expand Down
1 change: 0 additions & 1 deletion client/components/deposits-overview/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ const createMockOverview = (
fee: 0,
net: 0,
fee_percentage: 0,
transaction_ids: [],
},
};
};
Expand Down
8 changes: 4 additions & 4 deletions client/data/deposits/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,18 @@ export function updateInstantDeposit( data ) {
};
}

export function* submitInstantDeposit( transactionIds ) {
export function* submitInstantDeposit( currency ) {
try {
yield dispatch( STORE_NAME ).startResolution( 'getInstantDeposit', [
transactionIds,
currency,
] );

const deposit = yield apiFetch( {
path: '/wc/v3/payments/deposits',
method: 'POST',
data: {
type: 'instant',
transaction_ids: transactionIds,
currency,
},
} );

Expand Down Expand Up @@ -153,7 +153,7 @@ export function* submitInstantDeposit( transactionIds ) {
);
} finally {
yield dispatch( STORE_NAME ).finishResolution( 'getInstantDeposit', [
transactionIds,
currency,
] );
}
}
8 changes: 4 additions & 4 deletions client/data/deposits/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,18 +235,18 @@ export const useDepositsSummary = ( {
};

export const useInstantDeposit = (
transactionIds: string[]
currency: string
): { inProgress: boolean; submit: () => void; deposit: unknown } => {
const { deposit, inProgress } = useSelect( ( select ) => {
const { getInstantDeposit, isResolving } = select( STORE_NAME );

return {
deposit: getInstantDeposit( [ transactionIds ] ),
inProgress: isResolving( 'getInstantDeposit', [ transactionIds ] ),
deposit: getInstantDeposit( [ currency ] ),
inProgress: isResolving( 'getInstantDeposit', [ currency ] ),
};
} );
const { submitInstantDeposit } = useDispatch( STORE_NAME );
const submit = () => submitInstantDeposit( transactionIds );
const submit = () => submitInstantDeposit( currency );

return { deposit, inProgress, submit };
};
3 changes: 1 addition & 2 deletions client/data/deposits/test/overviews.fixture.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@
"amount": 12345,
"fee": 185.175,
"net": 12159.83,
"fee_percentage": 1.5,
"transaction_ids": [ "txn_XYZ", "txn_ZXY" ]
"fee_percentage": 1.5
}
]
},
Expand Down
4 changes: 1 addition & 3 deletions client/deposits/instant-deposits/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ const InstantDepositButton: React.FC< InstantDepositButtonProps > = ( {
} ) => {
const [ isModalOpen, setModalOpen ] = useState( false );
const buttonDisabled = isButtonDisabled( instantBalance );
const { inProgress, submit } = useInstantDeposit(
instantBalance.transaction_ids
);
const { inProgress, submit } = useInstantDeposit( instantBalance.currency );
const onClose = () => {
setModalOpen( false );
};
Expand Down
2 changes: 0 additions & 2 deletions client/deposits/instant-deposits/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const mockInstantBalance = {
fee: 123.45,
net: 12221.55,
fee_percentage: 1.5,
transaction_ids: [ 'txn_ABC123', 'txn_DEF456' ],
currency: 'USD',
} as AccountOverview.InstantBalance;

Expand All @@ -37,7 +36,6 @@ const mockZeroInstantBalance = {
fee: 0,
net: 0,
fee_percentage: 1.5,
transaction_ids: [],
currency: 'USD',
} as AccountOverview.InstantBalance;

Expand Down
1 change: 0 additions & 1 deletion client/types/account-overview.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export interface InstantBalance {
fee: number;
net: number;
fee_percentage: number;
transaction_ids: Array< string >;
}

export interface Overview {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,6 @@ static function ( $filter ) {
*/
public function manual_deposit( $request ) {
$params = $request->get_params();
return $this->forward_request( 'manual_deposit', [ $params['type'], $params['transaction_ids'] ] );
return $this->forward_request( 'manual_deposit', [ $params['type'], $params['currency'] ] );
}
}
8 changes: 4 additions & 4 deletions includes/wc-payment-api/class-wc-payments-api-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,15 @@ public function get_deposits_summary( array $filters = [] ) {
* Trigger a manual deposit.
*
* @param string $type Type of deposit. Only "instant" is supported for now.
* @param string $transaction_ids Comma-separated list of transaction IDs that will be associated with this deposit.
* @param string $currency The deposit currency.
* @return array The new deposit object.
* @throws API_Exception - Exception thrown on request failure.
*/
public function manual_deposit( $type, $transaction_ids ) {
public function manual_deposit( $type, $currency ) {
return $this->request(
[
'type' => $type,
'transaction_ids' => $transaction_ids,
'type' => $type,
'currency' => $currency,
],
self::DEPOSITS_API,
self::POST
Expand Down

0 comments on commit 48c3a5d

Please sign in to comment.