-
Notifications
You must be signed in to change notification settings - Fork 90
feat(keycard): Add support for keycard channel events #19548
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
Open
alexjba
wants to merge
1
commit into
fix/keycard-nfc-2
Choose a base branch
from
fix/keycard-nfc-3
base: fix/keycard-nfc-2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+193
−3
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,9 @@ | ||
| ## Constants for keycard channel operational states | ||
| ## These values must match the strings emitted by status-keycard-qt | ||
|
|
||
| const KEYCARD_CHANNEL_STATE_IDLE* = "idle" | ||
| const KEYCARD_CHANNEL_STATE_WAITING_FOR_KEYCARD* = "waiting-for-keycard" | ||
| const KEYCARD_CHANNEL_STATE_READING* = "reading" | ||
| const KEYCARD_CHANNEL_STATE_ERROR* = "error" | ||
|
|
||
|
|
This file contains hidden or 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,27 @@ | ||
| import ./io_interface | ||
| import app/core/eventemitter | ||
| import app_service/service/keycardV2/service as keycard_serviceV2 | ||
|
|
||
| type | ||
| Controller* = ref object of RootObj | ||
| delegate: io_interface.AccessInterface | ||
| events: EventEmitter | ||
|
|
||
| proc newController*( | ||
| delegate: io_interface.AccessInterface, | ||
| events: EventEmitter | ||
| ): Controller = | ||
| result = Controller() | ||
| result.delegate = delegate | ||
| result.events = events | ||
|
|
||
| proc delete*(self: Controller) = | ||
| discard | ||
|
|
||
| proc init*(self: Controller) = | ||
| # Listen to channel state changes | ||
| self.events.on(keycard_serviceV2.SIGNAL_KEYCARD_CHANNEL_STATE_UPDATED) do(e: Args): | ||
| let args = keycard_serviceV2.KeycardChannelStateArg(e) | ||
| self.delegate.setKeycardChannelState(args.state) | ||
|
|
||
|
|
This file contains hidden or 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,23 @@ | ||
| type | ||
| AccessInterface* {.pure inheritable.} = ref object of RootObj | ||
| ## Abstract class for any input/interaction with this module. | ||
|
|
||
| method delete*(self: AccessInterface) {.base.} = | ||
| raise newException(ValueError, "No implementation available") | ||
|
|
||
| method load*(self: AccessInterface) {.base.} = | ||
| raise newException(ValueError, "No implementation available") | ||
|
|
||
| method isLoaded*(self: AccessInterface): bool {.base.} = | ||
| raise newException(ValueError, "No implementation available") | ||
|
|
||
| # View Delegate Interface | ||
| # Delegate for the view must be declared here due to use of QtObject and multi | ||
| # inheritance, which is not well supported in Nim. | ||
| method viewDidLoad*(self: AccessInterface) {.base.} = | ||
| raise newException(ValueError, "No implementation available") | ||
|
|
||
| method setKeycardChannelState*(self: AccessInterface, state: string) {.base.} = | ||
| raise newException(ValueError, "No implementation available") | ||
|
|
||
|
|
This file contains hidden or 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,49 @@ | ||
| import nimqml | ||
|
|
||
| import io_interface, view, controller | ||
| import app/global/global_singleton | ||
| import app/core/eventemitter | ||
| import ./constants | ||
|
|
||
| export io_interface | ||
| export constants | ||
|
|
||
| type | ||
| Module* = ref object of io_interface.AccessInterface | ||
| view: View | ||
| viewVariant: QVariant | ||
| controller: Controller | ||
| moduleLoaded: bool | ||
|
|
||
| proc newModule*( | ||
| events: EventEmitter, | ||
| ): Module = | ||
| result = Module() | ||
| result.view = view.newView(result) | ||
| result.viewVariant = newQVariant(result.view) | ||
| result.controller = controller.newController(result, events) | ||
| result.moduleLoaded = false | ||
|
|
||
| singletonInstance.engine.setRootContextProperty("keycardChannelModule", result.viewVariant) | ||
|
|
||
| method delete*(self: Module) = | ||
| self.view.delete | ||
| self.viewVariant.delete | ||
| self.controller.delete | ||
|
|
||
| method load*(self: Module) = | ||
| self.controller.init() | ||
| self.view.load() | ||
|
|
||
| method isLoaded*(self: Module): bool = | ||
| return self.moduleLoaded | ||
|
|
||
| proc checkIfModuleDidLoad(self: Module) = | ||
| self.moduleLoaded = true | ||
|
|
||
| method viewDidLoad*(self: Module) = | ||
| self.checkIfModuleDidLoad() | ||
|
|
||
| method setKeycardChannelState*(self: Module, state: string) = | ||
| self.view.setKeycardChannelState(state) | ||
|
|
This file contains hidden or 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,62 @@ | ||
| import nimqml | ||
|
|
||
| import ./io_interface | ||
| import ./constants | ||
|
|
||
| QtObject: | ||
| type | ||
| View* = ref object of QObject | ||
| delegate: io_interface.AccessInterface | ||
| keycardChannelState: string # Operational channel state | ||
|
|
||
| proc setup(self: View) | ||
| proc delete*(self: View) | ||
| proc newView*(delegate: io_interface.AccessInterface): View = | ||
| new(result, delete) | ||
| result.delegate = delegate | ||
| result.keycardChannelState = KEYCARD_CHANNEL_STATE_IDLE | ||
| result.setup() | ||
|
|
||
| proc load*(self: View) = | ||
| self.delegate.viewDidLoad() | ||
|
|
||
| proc keycardChannelStateChanged*(self: View) {.signal.} | ||
| proc setKeycardChannelState*(self: View, value: string) = | ||
| if self.keycardChannelState == value: | ||
| return | ||
| self.keycardChannelState = value | ||
| self.keycardChannelStateChanged() | ||
| proc getKeycardChannelState*(self: View): string {.slot.} = | ||
| return self.keycardChannelState | ||
| QtProperty[string] keycardChannelState: | ||
| read = getKeycardChannelState | ||
| write = setKeycardChannelState | ||
| notify = keycardChannelStateChanged | ||
|
|
||
| # Constants for channel states (readonly properties for QML) | ||
| proc getStateIdle*(self: View): string {.slot.} = | ||
| return KEYCARD_CHANNEL_STATE_IDLE | ||
| QtProperty[string] stateIdle: | ||
| read = getStateIdle | ||
|
|
||
| proc getStateWaitingForKeycard*(self: View): string {.slot.} = | ||
| return KEYCARD_CHANNEL_STATE_WAITING_FOR_KEYCARD | ||
| QtProperty[string] stateWaitingForKeycard: | ||
| read = getStateWaitingForKeycard | ||
|
|
||
| proc getStateReading*(self: View): string {.slot.} = | ||
| return KEYCARD_CHANNEL_STATE_READING | ||
| QtProperty[string] stateReading: | ||
| read = getStateReading | ||
|
|
||
| proc getStateError*(self: View): string {.slot.} = | ||
| return KEYCARD_CHANNEL_STATE_ERROR | ||
| QtProperty[string] stateError: | ||
| read = getStateError | ||
|
|
||
| proc setup(self: View) = | ||
| self.QObject.setup | ||
|
|
||
| proc delete*(self: View) = | ||
| self.QObject.delete | ||
|
|
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can add
"status-changed"and"channel-state-changed"toapp_service/common/wallet_constants.nim?