Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased (develop)

- added: Remote enable/disable of gift card providers via the info server's giftCardInfo config, supporting whole-provider disabling for Phaze and Bitrefill and per-brand disabling for Phaze.
- changed: Use the new `makeMaxSpend` wallet API to build max-spend transactions atomically when sending the maximum and when migrating token balances.

## 4.49.0 (staging)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16078,6 +16078,7 @@ exports[`SendScene2 Render SendScene 1`] = `
"opacity": 1,
}
}
testID="sendAddressEnter"
>
<Text
allowFontScaling={false}
Expand Down
20 changes: 9 additions & 11 deletions src/components/scenes/MigrateWalletCompletionScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,22 +242,17 @@ const MigrateWalletCompletionComponent: React.FC<Props> = props => {
const hasError = false
const successfullyTransferredTokenIds: string[] = []
for (const item of tokenItems) {
let tokenSpendInfo: EdgeSpendInfo = {
const tokenSpendInfo: EdgeSpendInfo = {
tokenId: item.tokenId,
spendTargets: [{ publicAddress: newPublicAddress }],
networkFeeOption: 'standard'
}
try {
const maxAmount = await oldWallet.getMaxSpendable(tokenSpendInfo)
tokenSpendInfo = {
...tokenSpendInfo,
spendTargets: [
{ ...tokenSpendInfo.spendTargets[0], nativeAmount: maxAmount }
]
}
// Build and send the full token balance atomically:
const tx = await makeSpendSignAndBroadcast(
oldWallet,
tokenSpendInfo
tokenSpendInfo,
true
)
successfullyTransferredTokenIds.push(item.tokenId)
const txFee = tx.parentNetworkFee ?? tx.networkFee
Expand Down Expand Up @@ -454,9 +449,12 @@ const MigrateWalletCompletionComponent: React.FC<Props> = props => {

const makeSpendSignAndBroadcast = async (
wallet: EdgeCurrencyWallet,
spendInfo: EdgeSpendInfo
spendInfo: EdgeSpendInfo,
max: boolean = false
): Promise<EdgeTransaction> => {
const edgeUnsignedTransaction = await wallet.makeSpend(spendInfo)
const edgeUnsignedTransaction = max
? await wallet.makeMaxSpend(spendInfo)
: await wallet.makeSpend(spendInfo)
const edgeSignedTransaction = await wallet.signTx(edgeUnsignedTransaction)
const edgeBroadcastedTransaction = await wallet.broadcastTx(
edgeSignedTransaction
Expand Down
13 changes: 10 additions & 3 deletions src/components/scenes/SendScene2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1584,10 +1584,15 @@ const SendComponent: React.FC<Props> = props => {
setProcessingAmountChanged(false)
return
}
let maxEdgeTransaction: EdgeTransaction | undefined
if (maxSpendSetter === 0) {
spendInfo.spendTargets[0].nativeAmount = '0' // Some currencies error without a nativeAmount
const maxSpendable = await coreWallet.getMaxSpendable(spendInfo)
spendInfo.spendTargets[0].nativeAmount = maxSpendable
// Build the max-spend transaction atomically, then reflect its amount
// back onto the spendInfo so the spending-limit / minimum checks and
// the flip input display use the real max amount:
maxEdgeTransaction = await coreWallet.makeMaxSpend(spendInfo)
spendInfo.spendTargets[0].nativeAmount =
maxEdgeTransaction.spendTargets?.[0]?.nativeAmount ?? '0'
}
if (spendInfo.spendTargets[0].nativeAmount == null) {
flipInputModalRef.current?.setFees({
Expand Down Expand Up @@ -1650,7 +1655,9 @@ const SendComponent: React.FC<Props> = props => {

makeSpendCounter.current++
const localMakeSpendCounter = makeSpendCounter.current
const edgeTx = await coreWallet.makeSpend(spendInfo)
// Reuse the max-spend transaction when it was already built above:
const edgeTx =
maxEdgeTransaction ?? (await coreWallet.makeSpend(spendInfo))
if (localMakeSpendCounter < makeSpendCounter.current) {
// This makeSpend result is out of date. Throw it away since a newer one is in flight.
// This is not REALLY needed since useAsyncEffect seems to serialize calls into the effect
Expand Down
6 changes: 5 additions & 1 deletion src/components/themed/ExchangedFlipInput2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,11 @@ const ExchangedFlipInput2Component = React.forwardRef<
/>
</View>
{showMaxButton ? (
<EdgeTouchableOpacity style={styles.maxButton} onPress={onMaxPress}>
<EdgeTouchableOpacity
style={styles.maxButton}
onPress={onMaxPress}
testID="flipInputMaxButton"
>
<EdgeText style={styles.maxButtonText}>
{lstrings.string_max_cap}
</EdgeText>
Expand Down
1 change: 1 addition & 0 deletions src/components/tiles/AddressTile2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ export const AddressTile2 = React.forwardRef(
<EdgeTouchableOpacity
style={styles.buttonContainer}
onPress={handleChangeAddress}
testID="sendAddressEnter"
>
<FontAwesome
name="edit"
Expand Down
Loading