Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(quote): make settlement time dynamic #3834

Merged
merged 7 commits into from
Jun 6, 2023

Conversation

anthonydaoud
Copy link
Contributor

@anthonydaoud anthonydaoud commented Jun 2, 2023

Description

Currently, the time estimation for a FiatConnect quote is set to fixed values. This PR makes it so that the time estimation is dynamic and based on data sent from the quote provider.

SelectPaymentDynamicTime

Test plan

Added unit tests and modified existing unit test

Related issues

Backwards compatibility

Yes.

@codecov
Copy link

codecov bot commented Jun 2, 2023

Codecov Report

Merging #3834 (f32130e) into main (5ce0048) will increase coverage by 0.02%.
The diff coverage is 96.15%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3834      +/-   ##
==========================================
+ Coverage   82.29%   82.32%   +0.02%     
==========================================
  Files         702      703       +1     
  Lines       26168    26229      +61     
  Branches     3544     3561      +17     
==========================================
+ Hits        21535    21593      +58     
- Misses       4567     4570       +3     
  Partials       66       66              
Impacted Files Coverage Δ
src/fiatExchanges/quotes/NormalizedQuote.ts 100.00% <ø> (ø)
src/fiatExchanges/quotes/utils.ts 82.35% <82.35%> (ø)
src/fiatExchanges/PaymentMethodSection.tsx 95.74% <100.00%> (+0.18%) ⬆️
src/fiatExchanges/quotes/ExternalQuote.ts 93.10% <100.00%> (ø)
src/fiatExchanges/quotes/FiatConnectQuote.ts 100.00% <100.00%> (ø)
src/fiatExchanges/quotes/constants.ts 100.00% <100.00%> (ø)
src/fiatconnect/TransferStatusScreen.tsx 95.49% <100.00%> (+0.16%) ⬆️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5ce0048...f32130e. Read the comment docs.

@anthonydaoud anthonydaoud marked this pull request as ready for review June 2, 2023 16:41
Copy link
Contributor

@cajubelt cajubelt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks close-- see my comment in slack about syncing with product teammates on this though

src/fiatExchanges/PaymentMethodSection.tsx Outdated Show resolved Hide resolved
it('returns default for bank account when no bounds are present', () => {
const quoteData = _.cloneDeep(mockFiatConnectQuotes[1]) as FiatConnectQuoteSuccess
quoteData.fiatAccount.BankAccount = {
...quoteData.fiatAccount.BankAccount!,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
...quoteData.fiatAccount.BankAccount!,
...(quoteData.fiatAccount.BankAccount ?? {}),

nit (it's a test so it doesn't actually matter very much)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gives a typescript error, so I'll stick with the ! operator

src/fiatExchanges/quotes/FiatConnectQuote.ts Outdated Show resolved Hide resolved
const daysToSettlementEstimation = (
lowerBound: number,
upperBound: number
): SettlementEstimation => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it might make sense to be more defensive against the cases where lowerBound > upperBound or lowerBound < 0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently I think those would produce nonsensical outputs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the checks to the start of the getTimeEstimation function, which should ensure the days/hours to settlement estimation functions receive good inputs

Comment on lines 176 to 187
if (lowerBound === upperBound || lowerBound === 0) {
return {
settlementTime: SettlementTime.LESS_THAN_X_DAYS,
upperBound,
}
}

return {
settlementTime: SettlementTime.X_TO_Y_DAYS,
lowerBound,
upperBound,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it may not be worth the effort, but this does look almost identical between the two functions. There's probably a way to make it more DRY

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not that concerned about it though

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was struggling to cleanly make it more DRY, so am sticking with this for now

src/fiatExchanges/quotes/FiatConnectQuote.ts Outdated Show resolved Hide resolved
src/fiatExchanges/quotes/FiatConnectQuote.ts Outdated Show resolved Hide resolved
src/fiatExchanges/quotes/FiatConnectQuote.ts Outdated Show resolved Hide resolved
src/fiatExchanges/quotes/constants.ts Outdated Show resolved Hide resolved
src/fiatconnect/TransferStatusScreen.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

@cajubelt cajubelt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks close-- see my comment in slack about syncing with product teammates on this though

src/fiatExchanges/quotes/FiatConnectQuote.ts Outdated Show resolved Hide resolved
lowerBound > upperBound
) {
// payment method can only be bank or fc mobile money
return this.getPaymentMethod() === PaymentMethod.Bank
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more of a nit, but I get a little nervous when assumptions are made about what type a value would be in a way that won't be caught by the TS compiler if that value were able to take on more types; e.g., once getPaymentMethod can plausibly return payment types other than Bank and FiatConnectMobileMoney, it's very probable that this line wouldn't get updated to reflect that.

Kind of a pain to deal with since PaymentMethod encompasses payment types that could never be on a FiatConnectQuote, and I'm not sure the best way to do this such that TS will complain if a value was added to the PaymentMethod enum and wasn't explicitly dealt with here. For now maybe add a TODO: to ensure that this gets updated once more payment types are possible?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one option is to define a default that is not payment method-specific, and default to that if the payment method is not bank or mobile money

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah makes sense to me. out of curiosity, i wanted to see if it were possible, if we narrowed the enum type to FC-specific payment types, to write a switch with compile-time guarantees that all cases were covered. turns out it is possible, though the approach is a little bizarre.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to just write a TODO for now. I think the default approach works too but requires a small design discussion on what the default message should be

src/fiatconnect/TransferStatusScreen.tsx Outdated Show resolved Hide resolved
src/fiatconnect/TransferStatusScreen.tsx Outdated Show resolved Hide resolved
src/fiatconnect/TransferStatusScreen.tsx Outdated Show resolved Hide resolved
lowerBound > upperBound
) {
// payment method can only be bank or fc mobile money
return this.getPaymentMethod() === PaymentMethod.Bank
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one option is to define a default that is not payment method-specific, and default to that if the payment method is not bank or mobile money

@anthonydaoud anthonydaoud enabled auto-merge (squash) June 6, 2023 14:37
@anthonydaoud anthonydaoud merged commit 69b3295 into main Jun 6, 2023
@anthonydaoud anthonydaoud deleted the adaoud/dynamic-quote-time branch June 6, 2023 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants