Skip to content

Commit

Permalink
Merge pull request #1702 from p2p-org/bugfix/pwn-949
Browse files Browse the repository at this point in the history
[ETH-949] Swap state fee bugs
  • Loading branch information
lisemyon authored Feb 15, 2024
2 parents e5ade8f + 8e89b10 commit 41dc5ea
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
4 changes: 2 additions & 2 deletions p2p_wallet/Resources/Base.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,6 @@
"Mint signature" = "Mint signature";
"Unstake signature" = "Unstake signature";
"Stake signature" = "Stake signature";
"Explorer" = "Explorer";
"Buy with Moonpay" = "Buy with Moonpay";
"License" = "License";
"Cashout with Moonpay" = "Cashout with Moonpay";
Expand Down Expand Up @@ -596,7 +595,6 @@
"Share my link" = "Share my link";
"Open details" = "Open details";
"Token 2022 details" = "Token 2022 details";
"Token 2022 transfer fee" = "Token 2022 transfer fee";
"Calculated by subtracting the token 2022 transfer fee from your balance" = "Calculated by subtracting the token 2022 transfer fee from your balance";
"Calculated by subtracting the token 2022 transfer fee and account creation fee from your balance" = "Calculated by subtracting the token 2022 transfer fee and account creation fee from your balance";
"Update available" = "Update available";
Expand All @@ -610,3 +608,5 @@
"Open SOLScan" = "Open SOLScan";
"Terms & Conditions" = "Terms & Conditions";
"Swap fee" = "Swap fee";
"Token-2022 transfer fee" = "Token-2022 transfer fee";
"Solscan" = "Solscan";
4 changes: 2 additions & 2 deletions p2p_wallet/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@
"Error with deleting. Try again" = "Error with deleting. Try again";
"Estimated fees" = "Estimated fees";
"Exchanging %@ → %@" = "Exchanging %@ → %@";
"Explorer" = "Explorer";
"Face ID" = "Face ID";
"Failed to get data" = "Failed to get data";
"Fee" = "Fee";
Expand Down Expand Up @@ -584,7 +583,6 @@
"Share my link" = "Share my link";
"Open details" = "Open details";
"Token 2022 details" = "Token 2022 details";
"Token 2022 transfer fee" = "Token 2022 transfer fee";
"Calculated by subtracting the token 2022 transfer fee from your balance" = "Calculated by subtracting the token 2022 transfer fee from your balance";
"Calculated by subtracting the token 2022 transfer fee and account creation fee from your balance" = "Calculated by subtracting the token 2022 transfer fee and account creation fee from your balance";
"Update available" = "Update available";
Expand All @@ -598,3 +596,5 @@
"Open SOLScan" = "Open SOLScan";
"Terms & Conditions" = "Terms & Conditions";
"Swap fee" = "Swap fee";
"Token-2022 transfer fee" = "Token-2022 transfer fee";
"Solscan" = "Solscan";
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,29 @@ extension JupiterSwapBusinessLogic {
if transferFeeBasisPoints == nil {
// Internal function for calculating free basic points
@Sendable
func getTransferFeeBasicPointsForToken(mint: String) async throws -> UInt16 {
func getTransferFeeBasicPointsForToken(mint: String) async throws -> UInt16? {
let mintState: BufferInfo<Token2022MintState>? = try await services
.solanaAPIClient
.getAccountInfo(account: mint)

guard let mintState else { return 0 }
guard let mintState else { return nil }

let transferFeeConfig = mintState
.data
.getParsedExtension(ofType: TransferFeeConfigExtensionState.self)

return transferFeeConfig?.newerTransferFee.transferFeeBasisPoints ?? 0
return transferFeeConfig?.newerTransferFee.transferFeeBasisPoints
}

async let tokenATransferFee = getTransferFeeBasicPointsForToken(mint: state.fromToken.token.mintAddress)
async let tokenBTransferFee = getTransferFeeBasicPointsForToken(mint: state.toToken.token.mintAddress)

let total: UInt16 = try await(tokenATransferFee + tokenBTransferFee)
transferFeeBasisPoints = total
let result = try await(tokenATransferFee, tokenBTransferFee)
if result.0 == nil && result.1 == nil {
transferFeeBasisPoints = nil
} else {
transferFeeBasisPoints = (result.0 ?? 0) + (result.1 ?? 0)
}
}

return await validateAmounts(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ enum JupiterSwapBusinessLogic {
$0.routes = []
$0.fromToken = fromToken
$0.amountFrom = nil
$0.transferFeeBasisPoints = nil
}
case let .changeToToken(toToken):
return state.modified {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ struct SwapSettingsView: View {
}

// Account creation fee
if viewModel.isLoadingOrRouteNotNil {
if viewModel.isLoadingOrRouteNotNil, let fee = viewModel.info.accountCreationFee, fee.amount > 0 {
feeRow(
title: L10n.accountCreationFee,
fee: viewModel.info.accountCreationFee,
fee: fee,
identifier: .accountCreationFee
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ struct DetailTransactionView: View {
viewModel.share()
}
case .explorer:
CircleButton(title: L10n.explorer, image: .explorer) {
CircleButton(title: L10n.solscan, image: .explorer) {
viewModel.explore()
}
}
Expand Down

0 comments on commit 41dc5ea

Please sign in to comment.