-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* get expiration status * add new Error types * wip * updates to use u64 instead of Timestamp * bump Sargon * lint * Add Siwft Tests * Add extension for status --------- Co-authored-by: micbakos-rdx <[email protected]>
- Loading branch information
1 parent
82af570
commit 456272e
Showing
23 changed files
with
322 additions
and
33 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
...Connect/WalletInteraction/DappToWalletInteractionSubintentExpiration+Wrap+Functions.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,8 @@ | ||
import Foundation | ||
import SargonUniFFI | ||
|
||
extension DappToWalletInteractionSubintentExpiration { | ||
public func getStatus() -> DappToWalletInteractionSubintentExpirationStatus { | ||
getSubintentExpirationStatus(expiration: self) | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...nnect/WalletInteraction/DappToWalletInteractionSubintentExpireAtTime+Wrap+Functions.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,8 @@ | ||
import Foundation | ||
import SargonUniFFI | ||
|
||
extension DappToWalletInteractionSubintentExpireAtTime { | ||
public var date: Date { | ||
.init(timeIntervalSince1970: TimeInterval(unixTimestampSeconds)) | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...ases/RadixConnect/WalletInteraction/DappToWalletInteractionSubintentExpirationTests.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,22 @@ | ||
import Foundation | ||
import SargonUniFFI | ||
import XCTest | ||
|
||
final class DappToWalletInteractionSubintentExpirationTests: TestCase { | ||
typealias SUT = DappToWalletInteractionSubintentExpiration | ||
|
||
func testGetStatus() throws { | ||
let afterDelay = SUT.afterDelay(.init(expireAfterSeconds: 100)) | ||
XCTAssertEqual(afterDelay.getStatus(), .valid) | ||
|
||
let atTimeExpired = SUT.atTime(.init(unixTimestampSeconds: 0)) | ||
XCTAssertEqual(atTimeExpired.getStatus(), .expired) | ||
|
||
let now = UInt64(Date.now.timeIntervalSince1970) | ||
let atTimeCloseToExpiration = SUT.atTime(.init(unixTimestampSeconds: now + 15)) | ||
XCTAssertEqual(atTimeCloseToExpiration.getStatus(), .expirationTooClose) | ||
|
||
let atTimeValid = SUT.atTime(.init(unixTimestampSeconds: now + 60)) | ||
XCTAssertEqual(atTimeValid.getStatus(), .valid) | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...es/RadixConnect/WalletInteraction/DappToWalletInteractionSubintentExpireAtTimeTests.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,18 @@ | ||
import Foundation | ||
import SargonUniFFI | ||
import XCTest | ||
|
||
final class DappToWalletInteractionSubintentExpireAtTimeTests: TestCase { | ||
typealias SUT = DappToWalletInteractionSubintentExpireAtTime | ||
|
||
func testDate() throws { | ||
var sut = SUT.init(unixTimestampSeconds: 0) | ||
XCTAssertEqual(sut.date, Date(timeIntervalSince1970: 0)) | ||
|
||
sut = .init(unixTimestampSeconds: 500) | ||
XCTAssertEqual(sut.date, Date(timeIntervalSince1970: 500)) | ||
|
||
sut = .init(unixTimestampSeconds: 1000) | ||
XCTAssertEqual(sut.date.timeIntervalSince1970, 1000) | ||
} | ||
} |
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
2 changes: 2 additions & 0 deletions
2
...p_wallet_interaction/dapp_to_wallet/interaction_items/pre_authorization/expiration/mod.rs
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
mod after_delay; | ||
mod at_time; | ||
mod expiration; | ||
mod status; | ||
|
||
pub use after_delay::*; | ||
pub use at_time::*; | ||
pub use expiration::*; | ||
pub use status::*; |
19 changes: 19 additions & 0 deletions
19
...allet_interaction/dapp_to_wallet/interaction_items/pre_authorization/expiration/status.rs
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,19 @@ | ||
use crate::prelude::*; | ||
use sargon::DappToWalletInteractionSubintentExpirationStatus as InternalDappToWalletInteractionSubintentExpirationStatus; | ||
|
||
/// An enum that represents the expiration status of a subintent at a given time. | ||
/// | ||
/// Useful for determining if a subintent is still valid at the moment the Host apps | ||
/// receive the corresponding request. | ||
#[derive(Clone, PartialEq, InternalConversion, uniffi::Enum)] | ||
pub enum DappToWalletInteractionSubintentExpirationStatus { | ||
/// The subintent hasn't expired yet | ||
Valid, | ||
|
||
/// The subintent is too close to its expiration. Although it hasn't expired yet, the Host apps | ||
/// shouldn't allow the user dealing with it. | ||
ExpirationTooClose, | ||
|
||
/// The subintent has already expired. | ||
Expired, | ||
} |
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
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
2 changes: 2 additions & 0 deletions
2
...p_wallet_interaction/dapp_to_wallet/interaction_items/pre_authorization/expiration/mod.rs
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
mod after_delay; | ||
mod at_time; | ||
mod expiration; | ||
mod status; | ||
|
||
pub use after_delay::*; | ||
pub use at_time::*; | ||
pub use expiration::*; | ||
pub use status::*; |
47 changes: 47 additions & 0 deletions
47
...allet_interaction/dapp_to_wallet/interaction_items/pre_authorization/expiration/status.rs
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,47 @@ | ||
use crate::prelude::*; | ||
|
||
/// An enum that represents the expiration status of a subintent at a given time. | ||
/// | ||
/// Useful for determining if a subintent is still valid at the moment the Host apps | ||
/// receive the corresponding request. | ||
#[derive(Debug, Clone, PartialEq)] | ||
pub enum DappToWalletInteractionSubintentExpirationStatus { | ||
/// The subintent hasn't expired yet | ||
Valid, | ||
|
||
/// The subintent is too close to its expiration. Although it hasn't expired yet, the Host apps | ||
/// shouldn't allow the user dealing with it. | ||
ExpirationTooClose, | ||
|
||
/// The subintent has already expired. | ||
Expired, | ||
} | ||
|
||
impl HasSampleValues for DappToWalletInteractionSubintentExpirationStatus { | ||
fn sample() -> Self { | ||
Self::Valid | ||
} | ||
|
||
fn sample_other() -> Self { | ||
Self::ExpirationTooClose | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[allow(clippy::upper_case_acronyms)] | ||
type SUT = DappToWalletInteractionSubintentExpirationStatus; | ||
|
||
#[test] | ||
fn equality() { | ||
assert_eq!(SUT::sample(), SUT::sample()); | ||
assert_eq!(SUT::sample_other(), SUT::sample_other()); | ||
} | ||
|
||
#[test] | ||
fn inequality() { | ||
assert_ne!(SUT::sample(), SUT::sample_other()); | ||
} | ||
} |
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
Oops, something went wrong.