-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MOB-544 Add preference setting for gas payment type (#189)
- Loading branch information
Showing
16 changed files
with
237 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
dydx/dydxPresenters/dydxPresenters/_Features/settings_gas_token.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[ | ||
{ | ||
"input":"1", | ||
"fields":[ | ||
{ | ||
"title":{ | ||
"text":"APP.GENERAL.PAY_GAS_WITH" | ||
}, | ||
"field":{ | ||
"field":"gas_token", | ||
"type":"text", | ||
"options":[ | ||
{ | ||
"text":"USDC", | ||
"value":"USDC" | ||
}, | ||
{ | ||
"text":"NATIVE", | ||
"value":"NATIVE" | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
] |
26 changes: 26 additions & 0 deletions
26
dydx/dydxPresenters/dydxPresenters/_v4/GlobalWorkers/Workers/dydxGasTokenWorker.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// dydxGasTokenWorker.swift | ||
// dydxPresenters | ||
// | ||
// Created by Rui Huang on 10/06/2024. | ||
// | ||
|
||
import Abacus | ||
import Combine | ||
import dydxStateManager | ||
import ParticlesKit | ||
import RoutingKit | ||
import Utilities | ||
|
||
public final class dydxGasTokenWorker: BaseWorker { | ||
|
||
public override func start() { | ||
super.start() | ||
|
||
// set the gas token to the user preference | ||
if let tokenName = SettingsStore.shared?.gasToken, | ||
let token = GasToken.from(tokenName: tokenName) { | ||
AbacusStateManager.shared.setGasToken(token: token) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
dydx/dydxPresenters/dydxPresenters/_v4/Profile/GasToken/dydxGasTokenViewBuilder.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// | ||
// dydxGasTokenViewBuilder.swift | ||
// dydxPresenters | ||
// | ||
// Created by Rui Huang on 10/06/2024. | ||
// Copyright © 2024 dYdX Trading Inc. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
import dydxViews | ||
import PlatformParticles | ||
import RoutingKit | ||
import ParticlesKit | ||
import PlatformUI | ||
import PlatformUIJedio | ||
import Utilities | ||
import dydxStateManager | ||
import Abacus | ||
|
||
public class dydxGasTokenViewBuilder: NSObject, ObjectBuilderProtocol { | ||
public func build<T>() -> T? { | ||
let presenter = dydxGasTokenViewPresenter() | ||
let view = presenter.viewModel?.createView() ?? PlatformViewModel().createView() | ||
let viewController = SettingsViewController(presenter: presenter, view: view, configuration: .default) | ||
viewController.requestPath = "/settings/gas_token" | ||
return viewController as? T | ||
} | ||
} | ||
|
||
private class dydxGasTokenViewPresenter: FieldSettingsViewPresenter { | ||
init() { | ||
super.init(definitionFile: "settings_gas_token.json", fieldName: "gas_token", keyValueStore: SettingsStore.shared) | ||
|
||
let header = SettingHeaderViewModel() | ||
header.text = DataLocalizer.localize(path: "APP.GENERAL.PAY_GAS_WITH") | ||
header.dismissAction = { | ||
Router.shared?.navigate(to: RoutingRequest(path: "/action/dismiss"), animated: true, completion: nil) | ||
} | ||
viewModel?.headerViewModel = header | ||
} | ||
|
||
override func onOptionSelected(option: [String: Any], changed: Bool) { | ||
if changed, let value = option["value"] as? String { | ||
if let token = GasToken.from(tokenName: value) { | ||
AbacusStateManager.shared.setGasToken(token: token) | ||
Router.shared?.navigate(to: RoutingRequest(path: "/action/dismiss"), animated: true, completion: nil) | ||
} else { | ||
ErrorLogging.shared?.e(tag: "dydxGasTokenViewPresenter", | ||
message: "Invalid token: \(value)") | ||
} | ||
} | ||
} | ||
|
||
override func textForOption(option: [String: Any]) -> String? { | ||
GasTokenOptionTransformer().textForOption(option: option) ?? super.textForOption(option: option) | ||
} | ||
} | ||
|
||
class GasTokenOptionTransformer: SettingsOptionTransformProtocol { | ||
func textForOption(option: [String: Any]) -> String? { | ||
switch option["value"] as? String { | ||
case "USDC": | ||
return AbacusStateManager.shared.environment?.usdcTokenInfo?.name | ||
case "NATIVE": | ||
return AbacusStateManager.shared.environment?.nativeTokenInfo?.name | ||
default: | ||
return nil | ||
} | ||
} | ||
} |
Oops, something went wrong.