Skip to content

Commit f3cb17f

Browse files
committed
Auto populate multiout amount if similar to previous
1 parent dec0a29 commit f3cb17f

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
- added: Multiple memo support to `SendScene2`
1010
- added: Add os version to the "OS" line of logs
1111
- changed: "MAX" button in `FlipInput` restyled to tertiary and moved next to the text input field
12+
- changed: Auto launch QR scanner for multi-out payments if previously used
13+
- changed: Auto populate amount for multi-out payments if prior amounts are similar
1214
- fixed: Primary button transforming on the animation on `GettingStartedScene`
1315
- fixed: `NotificationCenterScene` could crash if there was an undismissed new token notification and the associated wallet no longer existed
1416
- removed: Disable Fantom transaction list

src/components/scenes/SendScene2.tsx

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { add, div, gte, lt, mul } from 'biggystring'
1+
import { abs, add, div, gte, lt, lte, mul, sub } from 'biggystring'
22
import {
33
asMaybeInsufficientFundsError,
44
asMaybeNoAmountSpecifiedError,
@@ -110,12 +110,15 @@ interface FioSenderInfo {
110110
skipRecord?: boolean
111111
}
112112

113-
// TODO: For now, do not allow multiple targets to be added via GUI. UX is very poor until
114-
// animation is added. Waiting for reanimated v3 which fixes crashes in Layout animations.
115-
// Note: multiple targets can be added via JSON payment protocol to fix payments to Anypay
116-
// invoices.
117113
const ALLOW_MULTIPLE_TARGETS = true
118114

115+
/**
116+
* If the prior two spend targets of a multi-out payment have the same amount
117+
* within 0.5%, then use the same amount for the new spend target.
118+
* This makes it MUCH easier to load many gift cards without having to enter
119+
* amounts manually.
120+
*/
121+
const MULTI_OUT_DIFF_PERCENT = '0.005'
119122
const PIN_MAX_LENGTH = 4
120123
const INFINITY_STRING = '999999999999999999999999999999999999999'
121124

@@ -242,6 +245,20 @@ const SendComponent = (props: Props) => {
242245
spendTarget.uniqueIdentifier = parsedUri?.uniqueIdentifier
243246
spendTarget.publicAddress = parsedUri?.publicAddress
244247
spendTarget.nativeAmount = parsedUri?.nativeAmount
248+
249+
if (spendInfo.spendTargets.length > 2 && spendTarget.nativeAmount == null) {
250+
// Check if the last two spend targets have the same amount within 0.5%
251+
const prevAmount = spendInfo.spendTargets[spendInfo.spendTargets.length - 2].nativeAmount
252+
const pprevAmount = spendInfo.spendTargets[spendInfo.spendTargets.length - 3].nativeAmount
253+
254+
if (prevAmount != null && pprevAmount != null) {
255+
const diff = abs(sub(prevAmount, pprevAmount))
256+
const diffPercent = div(diff, prevAmount, DECIMAL_PRECISION)
257+
if (lte(diffPercent, MULTI_OUT_DIFF_PERCENT)) {
258+
spendTarget.nativeAmount = prevAmount
259+
}
260+
}
261+
}
245262
spendTarget.otherParams = {
246263
fioAddress
247264
}

0 commit comments

Comments
 (0)