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

[ETH-949] Swap state fee bugs #1702

Merged
merged 2 commits into from
Feb 15, 2024
Merged
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
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
Loading