Skip to content

Commit

Permalink
Merge pull request #1689 from p2p-org/feature/pwn-879
Browse files Browse the repository at this point in the history
Feature/pwn 879
  • Loading branch information
lisemyon authored Feb 9, 2024
2 parents 53a3311 + a21b30d commit f4de6a4
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 9 deletions.
3 changes: 2 additions & 1 deletion p2p_wallet/Resources/Base.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@
"Make sure the mint address %@ is correct before confirming" = "Make sure the mint address %@ is correct before confirming";
"Be save and carefull" = "Be save and carefull";
"The token %@ from your swap link seems suspicious, therefore we've refreshed swap pair to default." = "The token %@ from your swap link seems suspicious, therefore we've refreshed swap pair to default.";
"Charge that you need to pay to send or receive tokenA. It helps maintain the network and ensure smooth transactions." = "Charge that you need to pay to send or receive tokenA. It helps maintain the network and ensure smooth transactions.";
"Charge that you need to pay to send or receive tokens-2022. It helps maintain the network and ensure smooth transactions." = "Charge that you need to pay to send or receive tokens-2022. It helps maintain the network and ensure smooth transactions.";
"Unfortunately, you can not cashout in %@, but you can still use other Key App features" = "Unfortunately, you can not cashout in %@, but you can still use other Key App features";
"Share my link" = "Share my link";
"Open details" = "Open details";
Expand All @@ -606,5 +606,6 @@
"Based on absolute and relative profitability of each trade. It shows the relative potential %% profits or losses of your trading strategy." = "Based on absolute and relative profitability of each trade. It shows the relative potential %% profits or losses of your trading strategy.";
"%@%% last 24h" = "%@%% last 24h";
"Result of an investment, trading strategy per 24 hours" = "Result of an investment, trading strategy per 24 hours";
"KeyApp swap fee" = "KeyApp swap fee";
"Referral reward" = "Referral reward";
"Open SOLScan" = "Open SOLScan";
3 changes: 2 additions & 1 deletion p2p_wallet/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@
"Make sure the mint address %@ is correct before confirming" = "Make sure the mint address %@ is correct before confirming";
"Be save and carefull" = "Be save and carefull";
"The token %@ from your swap link seems suspicious, therefore we've refreshed swap pair to default." = "The token %@ from your swap link seems suspicious, therefore we've refreshed swap pair to default.";
"Charge that you need to pay to send or receive tokenA. It helps maintain the network and ensure smooth transactions." = "Charge that you need to pay to send or receive tokenA. It helps maintain the network and ensure smooth transactions.";
"Charge that you need to pay to send or receive tokens-2022. It helps maintain the network and ensure smooth transactions." = "Charge that you need to pay to send or receive tokens-2022. It helps maintain the network and ensure smooth transactions.";
"Confirm selection" = "Confirm selection";
"The token %@ is out of the strict list" = "The token %@ is out of the strict list";
"Make sure the mint address %@ is correct before confirming" = "Make sure the mint address %@ is correct before confirming";
Expand All @@ -594,5 +594,6 @@
"Based on absolute and relative profitability of each trade. It shows the relative potential %% profits or losses of your trading strategy." = "Based on absolute and relative profitability of each trade. It shows the relative potential %% profits or losses of your trading strategy.";
"%@%% last 24h" = "%@%% last 24h";
"Result of an investment, trading strategy per 24 hours" = "Result of an investment, trading strategy per 24 hours";
"KeyApp swap fee" = "KeyApp swap fee";
"Referral reward" = "Referral reward";
"Open SOLScan" = "Open SOLScan";
25 changes: 25 additions & 0 deletions p2p_wallet/Scenes/Main/Swap/State/JupiterSwapState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,31 @@ struct JupiterSwapState: Equatable {
swapTokens
}

var platformFeeAmount: SwapFeeInfo? {
guard let platformFee = route?.platformFee else { return nil }

let tokenFee: TokenMetadata
if route?.swapMode == "ExactIn" {
// Fee in token B
tokenFee = toToken.token
} else {
// Fee in token A
tokenFee = fromToken.token
}

guard let amount = UInt64(platformFee.amount)?.convertToBalance(decimals: tokenFee.decimals) else {
return nil
}

return SwapFeeInfo(
amount: amount,
tokenSymbol: tokenFee.symbol,
tokenName: tokenFee.name,
tokenPriceInCurrentFiat: tokensPriceMap[tokenFee.mintAddress],
canBePaidByKeyApp: false
)
}

/// Network fee of the transaction, can be modified by the fee relayer service
var networkFee: SwapFeeInfo? {
guard route != nil else { return nil }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ final class SwapSettingsCoordinator: Coordinator<SwapSettingsCoordinatorResult>
strategy = .accountCreationFee
case .liquidityFee:
strategy = .liquidityFee
case .platformFee:
return
case .minimumReceived:
strategy = .minimumReceived
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ final class SwapSettingsInfoViewModel: BaseViewModel, ObservableObject {
case .transferFee:
image = .accountCreationFeeHand
title = L10n.transferFee
subtitle = L10n.ChargeThatYouNeedToPayToSendOrReceiveTokenA
subtitle = L10n.ChargeThatYouNeedToPayToSendOrReceiveTokens2022
.itHelpsMaintainTheNetworkAndEnsureSmoothTransactions
buttonTitle = L10n.gotIt + "👍"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,23 @@ struct JupiterSwapStateInfo: Equatable {
let networkFee: SwapFeeInfo
let accountCreationFee: SwapFeeInfo?
let liquidityFee: [SwapFeeInfo]
let platformFee: PlatformFee?
let platformFeeAmount: SwapFeeInfo?
let minimumReceived: SwapTokenAmountInfo?
let transferFee: String?
let transferFeeFiat: Double?
let exchangeRateInfo: String?

var estimatedFees: String? {
let estimatedFees = (liquidityFee + [networkFee, accountCreationFee].compactMap { $0 })
var fees = (liquidityFee + [networkFee, accountCreationFee, platformFeeAmount]
.compactMap { $0 })
.compactMap(\.amountInFiat)
.reduce(0.0, +)
if let transferFeeFiat {
fees = fees + transferFeeFiat
}

return estimatedFees > 0 ? "" + estimatedFees.formattedFiat() : nil
return fees > 0 ? "" + fees.formattedFiat() : nil
}
}

Expand Down Expand Up @@ -68,11 +75,15 @@ extension JupiterSwapState {
),
accountCreationFee: accountCreationFee,
liquidityFee: liquidityFee,
platformFee: route?.platformFee,
platformFeeAmount: platformFeeAmount,
minimumReceived: minimumReceivedAmount == nil ? nil : .init(
amount: minimumReceivedAmount!,
token: toToken.token.symbol
),
transferFee: transferFeeBasisPoints != nil ? "\(Double(transferFeeBasisPoints!) / 100)%" : nil,
transferFeeFiat: transferFeeBasisPoints != nil ? Double(transferFeeBasisPoints!) / 100 / 100 *
amountFromFiat : nil,
exchangeRateInfo: exchangeRateInfo
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ struct SwapSettingsView: View {
}
}

// Platform fee
if let platformFee = viewModel.info.platformFee {
commonRow(
title: L10n.keyAppSwapFee,
subtitle: nil,
trailingSubtitle: feeBpsFormatter(platformFee.feeBps),
trailingView: EmptyView().castToAnyView(),
identifier: .platformFee
)
}

// Estimated fee
if viewModel.isLoadingOrRouteNotNil, viewModel.info.estimatedFees != nil {
HStack {
Expand Down Expand Up @@ -178,10 +189,12 @@ struct SwapSettingsView: View {
VStack(alignment: .leading, spacing: 4) {
Text(title)
.apply(style: .text3)
Text(subtitle)
.apply(style: .label1)
.foregroundColor(Color(subtitleColor))
.skeleton(with: viewModel.isLoading, size: .init(width: 100, height: 12))
if let subtitle {
Text(subtitle)
.apply(style: .label1)
.foregroundColor(Color(subtitleColor))
.skeleton(with: viewModel.isLoading, size: .init(width: 100, height: 12))
}
}

Spacer()
Expand All @@ -205,6 +218,17 @@ struct SwapSettingsView: View {
}
}

private func feeBpsFormatter(_ feeBps: Int) -> String {
let formatter = NumberFormatter()
formatter.numberStyle = .percent
formatter.minimumIntegerDigits = 1
formatter.maximumIntegerDigits = 3
formatter.maximumFractionDigits = 2
formatter.decimalSeparator = "."

return formatter.string(from: NSDecimalNumber(decimal: Decimal(feeBps) / 1000)) ?? "N/A"
}

// struct SwapSettingsView_Previews: PreviewProvider {
// static let viewModel = SwapSettingsViewModel(
// status: .loading,
Expand Down Expand Up @@ -297,6 +321,7 @@ extension SwapSettingsView {
case transferFee
case accountCreationFee
case liquidityFee
case platformFee
case minimumReceived
}
}

0 comments on commit f4de6a4

Please sign in to comment.