-
Notifications
You must be signed in to change notification settings - Fork 4
fix: add quickpay daily spend limit #672
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
Draft
ovitrif
wants to merge
32
commits into
master
Choose a base branch
from
fix/670-quickpay-day-limit
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
ea2cccd
feat: persist QuickPay daily spend
ovitrif 01d36ca
feat: add QuickPay daily limit setting
ovitrif fb49623
fix: skip QuickPay over the daily cap
ovitrif ed1ab25
chore: rename changelog fragment
ovitrif f0fbf80
Merge branch 'master' into fix/670-quickpay-day-limit
ovitrif dc407b3
fix: port Android QuickPay follow-ups
ovitrif f158cd5
Merge branch 'master' into fix/670-quickpay-day-limit
ovitrif 9d63bf1
fix: QuickPay pending spend and Confirm race
ovitrif f322977
fix: account QuickPay daily spend in sats
ovitrif bd45c79
Merge branch 'master' into fix/670-quickpay-day-limit
ovitrif 8039526
fix: port QuickPay cents spend ledger
ovitrif ba1b26f
fix: remount QuickPay on Try Again
ovitrif afb6294
fix: restore QuickPay spend from metadata backup
ovitrif 73e48f3
fix: count sub-cent quickpay as 1 cent
ovitrif 224a729
fix: restore quickpay cap across backup and pending events
ovitrif b3bb5d4
fix: restore android quickpay backup payloads
ovitrif ca69d1f
Merge remote-tracking branch 'origin/master' into fix/670-quickpay-da…
ovitrif 6c79029
fix: drop intro from settings backup mapping
ovitrif 7d79080
fix: map quickpay intro to android settings key
ovitrif b80be42
fix: keep settings quickpay intro over cache
ovitrif 58fb64b
refactor: shrink quickpay backup restore helpers
ovitrif 4723c38
fix: keep production backup keys plus android aliases
ovitrif 9cffd1b
fix: restore production AppCacheData decoder
ovitrif c33a00f
chore: drop unused QuickPay leftovers
ovitrif d56dc63
chore: restore QuickpaySettings preview
ovitrif a0c208e
chore: drop QuickpaySettings preview
ovitrif 8d390f1
fix: settle QuickPay spend through one ledger
ovitrif 40112d8
refactor: drop unused QuickPay ledger fields
ovitrif 4a4aa9a
refactor: drop intra-PR QuickPay spend migrate
ovitrif 673309c
Merge branch 'master' into fix/670-quickpay-day-limit
ovitrif 7f57bc6
fix: map QuickPay threshold to Android backup key
ovitrif 111d828
refactor: drop Paykit from QuickPay hard-reject
ovitrif File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import Foundation | ||
|
|
||
| enum QuickPayLimits { | ||
| static let usdCurrencyCode = "USD" | ||
| static let thresholdSteps: [Double] = [1, 5, 10, 20, 50] | ||
| static let dailyMultiplierSteps: [Double] = [1, 3, 5, 10, 50] | ||
| static let defaultDailyMultiplier: Double = 5 | ||
|
|
||
| static func amountWithFeeSats(amountSats: UInt64, feePaidSats: UInt64) -> UInt64 { | ||
| let (total, overflow) = amountSats.addingReportingOverflow(feePaidSats) | ||
| return overflow ? UInt64.max : total | ||
| } | ||
|
|
||
| static func sanitizedMultiplier(_ value: Double) -> Double { | ||
| dailyMultiplierSteps.contains(value) ? value : defaultDailyMultiplier | ||
| } | ||
|
|
||
| static func dailyCapUsdDisplay(thresholdUsd: Double, multiplier: Double) -> Int { | ||
| Int(thresholdUsd) * Int(sanitizedMultiplier(multiplier)) | ||
| } | ||
|
|
||
| static func thresholdCents(_ thresholdUsd: Double) -> Int64 { | ||
| Int64(Int(thresholdUsd)) * 100 | ||
| } | ||
|
|
||
| static func capCents(thresholdUsd: Double, multiplier: Double) -> Int64 { | ||
| thresholdCents(thresholdUsd) * Int64(Int(sanitizedMultiplier(multiplier))) | ||
| } | ||
|
|
||
| static func reserveCents(convertedCents: Int64, thresholdUsd: Double, amountSats: UInt64) -> Int64 { | ||
| let clamped = min(convertedCents, thresholdCents(thresholdUsd)) | ||
| if amountSats == 0 { | ||
| return clamped | ||
| } | ||
| return max(clamped, 1) | ||
| } | ||
|
|
||
| static func usdCents(from converted: ConvertedAmount) -> Int64 { | ||
| var cents = converted.value * 100 | ||
| var rounded = Decimal() | ||
| NSDecimalRound(&rounded, ¢s, 0, .plain) | ||
| return NSDecimalNumber(decimal: rounded).int64Value | ||
| } | ||
|
|
||
| @MainActor | ||
| static func paymentAmountSats(app: AppViewModel) -> UInt64? { | ||
| if let lnurlPayData = app.lnurlPayData { | ||
| guard lnurlPayData.isFixedAmount else { return nil } | ||
| return lnurlPayData.minSendableSat | ||
| } | ||
|
|
||
| return app.scannedLightningInvoice?.amountSatoshis | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.