-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #615 from Syn-McJ/feature/voting-list
feat(voting): list of username requests
- Loading branch information
Showing
66 changed files
with
17,265 additions
and
603 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
23f06b9dd7ba1c5998bbf5a37e06af207d7cb997 | ||
8e0e0029fff15707bae4dd8512840ccef4e85c83 |
Large diffs are not rendered by default.
Oops, something went wrong.
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,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
DashWallet/Resources/AppAssets.xcassets/Voting/link.badge.imageset/Contents.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,23 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "link.png", | ||
"idiom" : "universal", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"filename" : "[email protected]", | ||
"idiom" : "universal", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"filename" : "[email protected]", | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Binary file added
BIN
+726 Bytes
DashWallet/Resources/AppAssets.xcassets/Voting/link.badge.imageset/link.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.32 KB
DashWallet/Resources/AppAssets.xcassets/Voting/link.badge.imageset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.91 KB
DashWallet/Resources/AppAssets.xcassets/Voting/link.badge.imageset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions
23
DashWallet/Resources/AppAssets.xcassets/icon_filter_horizontal.imageset/Contents.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,23 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "filters.png", | ||
"idiom" : "universal", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"filename" : "[email protected]", | ||
"idiom" : "universal", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"filename" : "[email protected]", | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Binary file added
BIN
+351 Bytes
...Wallet/Resources/AppAssets.xcassets/icon_filter_horizontal.imageset/filters.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+562 Bytes
...let/Resources/AppAssets.xcassets/icon_filter_horizontal.imageset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+779 Bytes
...let/Resources/AppAssets.xcassets/icon_filter_horizontal.imageset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
9 changes: 9 additions & 0 deletions
9
...ources/Infrastructure/Database/Migrations.bundle/20231023152234_add_username_requests.sql
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,9 @@ | ||
CREATE TABLE username_requests ( | ||
requestId TEXT PRIMARY KEY, | ||
username TEXT NOT NULL, | ||
createdAt INTEGER NOT NULL, | ||
identity TEXT NOT NULL, | ||
link TEXT, | ||
votes INTEGER NOT NULL, | ||
isApproved INTEGER NOT NULL | ||
); |
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
138 changes: 138 additions & 0 deletions
138
DashWallet/Sources/Models/Voting/DAO/UsernameRequestsDAO.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,138 @@ | ||
// | ||
// Created by Andrei Ashikhmin | ||
// Copyright © 2023 Dash Core Group. All rights reserved. | ||
// | ||
// Licensed under the MIT License (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://opensource.org/licenses/MIT | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Foundation | ||
import SQLite | ||
|
||
// MARK: - UsernameRequestsDAO | ||
|
||
protocol UsernameRequestsDAO { | ||
func create(dto: UsernameRequest) | ||
func all() -> [UsernameRequest] | ||
func get(by requestId: String) -> UsernameRequest? | ||
func update(dto: UsernameRequest) | ||
func delete(dto: UsernameRequest) | ||
func deleteAll() | ||
} | ||
|
||
// MARK: - UsernameRequestsDAOImpl | ||
|
||
class UsernameRequestsDAOImpl: NSObject, UsernameRequestsDAO { | ||
private var db: Connection { DatabaseConnection.shared.db } | ||
private var cache: [String: UsernameRequest] = [:] | ||
|
||
private let queue = DispatchQueue(label: "org.dash.infrastructure.queue.username-requests-dao", attributes: .concurrent) | ||
|
||
func create(dto: UsernameRequest) { | ||
do { | ||
let usernameRequest = UsernameRequest.table.insert(or: .replace, | ||
UsernameRequest.requestId <- dto.requestId, | ||
UsernameRequest.username <- dto.username, | ||
UsernameRequest.createdAt <- dto.createdAt, | ||
UsernameRequest.identity <- dto.identity, | ||
UsernameRequest.link <- dto.link, | ||
UsernameRequest.votes <- dto.votes, | ||
UsernameRequest.isApproved <- dto.isApproved) | ||
try db.run(usernameRequest) | ||
|
||
} catch { | ||
print(error) | ||
} | ||
|
||
queue.async(flags: .barrier) { [weak self] in | ||
self?.cache[dto.requestId] = dto | ||
} | ||
} | ||
|
||
func all() -> [UsernameRequest] { | ||
let statement = UsernameRequest.table | ||
var userInfos: [UsernameRequest] = [] | ||
|
||
do { | ||
for requestRow in try db.prepare(statement) { | ||
let userInfo = UsernameRequest(row: requestRow) | ||
userInfos.append(userInfo) | ||
} | ||
} catch { | ||
print(error) | ||
} | ||
|
||
return userInfos | ||
} | ||
|
||
func get(by requestId: String) -> UsernameRequest? { | ||
if let cached = cachedValue(by: requestId) { | ||
return cached | ||
} | ||
|
||
let statement = UsernameRequest.table.filter(UsernameRequest.requestId == requestId) | ||
|
||
do { | ||
for row in try db.prepare(statement) { | ||
let userInfo = UsernameRequest(row: row) | ||
queue.async(flags: .barrier) { [weak self] in | ||
self?.cache[requestId] = userInfo | ||
} | ||
return userInfo | ||
} | ||
} catch { | ||
print(error) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
private func cachedValue(by key: String) -> UsernameRequest? { | ||
var v: UsernameRequest? | ||
|
||
queue.sync { | ||
v = cache[key] | ||
} | ||
|
||
return v | ||
} | ||
|
||
func update(dto: UsernameRequest) { | ||
create(dto: dto) | ||
} | ||
|
||
func delete(dto: UsernameRequest) { | ||
queue.async(flags: .barrier) { [weak self] in | ||
self?.cache[dto.requestId] = nil | ||
} | ||
} | ||
|
||
func deleteAll() { | ||
do { | ||
try db.run(UsernameRequest.table.delete()) | ||
queue.async(flags: .barrier) { [weak self] in | ||
self?.cache = [:] | ||
} | ||
} catch { | ||
print(error) | ||
} | ||
} | ||
|
||
static let shared = UsernameRequestsDAOImpl() | ||
} | ||
|
||
extension UsernameRequestsDAOImpl { | ||
func dictionaryOfAllItems() -> [String: UsernameRequest] { | ||
_ = all() | ||
return cache | ||
} | ||
} |
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,63 @@ | ||
// | ||
// Created by Andrei Ashikhmin | ||
// Copyright © 2023 Dash Core Group. All rights reserved. | ||
// | ||
// Licensed under the MIT License (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://opensource.org/licenses/MIT | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Foundation | ||
import SQLite | ||
|
||
// MARK: - UsernameRequest | ||
|
||
struct UsernameRequest { | ||
var requestId: String | ||
var username: String | ||
var createdAt: Int64 | ||
var identity: String | ||
var link: String? | ||
var votes: Int | ||
var isApproved: Bool | ||
|
||
init(requestId: String, username: String, createdAt: Int64, identity: String, link: String?, votes: Int, isApproved: Bool) { | ||
self.requestId = requestId | ||
self.username = username | ||
self.createdAt = createdAt | ||
self.identity = identity | ||
self.link = link | ||
self.votes = votes | ||
self.isApproved = isApproved | ||
} | ||
|
||
init(row: Row) { | ||
self.requestId = row[UsernameRequest.requestId] | ||
self.username = row[UsernameRequest.username] | ||
self.createdAt = row[UsernameRequest.createdAt] | ||
self.identity = row[UsernameRequest.identity] | ||
self.link = row[UsernameRequest.link] | ||
self.votes = row[UsernameRequest.votes] | ||
self.isApproved = row[UsernameRequest.isApproved] | ||
} | ||
} | ||
|
||
extension UsernameRequest { | ||
static var table: Table { Table("username_requests") } | ||
|
||
static var requestId: Expression<String> { Expression<String>("requestId") } | ||
static var username: Expression<String> { Expression<String>("username") } | ||
static var createdAt: Expression<Int64> { Expression<Int64>("createdAt") } | ||
static var identity: Expression<String> { Expression<String>("identity") } | ||
static var votes: Expression<Int> { Expression<Int>("votes") } | ||
static var isApproved: Expression<Bool> { Expression<Bool>("isApproved") } | ||
static var link: Expression<String?> { .init("link") } | ||
} |
35 changes: 35 additions & 0 deletions
35
DashWallet/Sources/Models/Voting/Voting+UserDefaults.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,35 @@ | ||
// | ||
// Created by Andrei Ashikhmin | ||
// Copyright © 2023 Dash Core Group. All rights reserved. | ||
// | ||
// Licensed under the MIT License (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://opensource.org/licenses/MIT | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Foundation | ||
|
||
private let kIsVotingInfoShown = "votingInfoShownKey" | ||
|
||
// MARK: - VotingPrefs | ||
|
||
class VotingPrefs { | ||
public static let shared: VotingPrefs = .init() | ||
|
||
private var _infoShown: Bool? = nil | ||
var infoShown: Bool { | ||
get { _infoShown ?? UserDefaults.standard.bool(forKey: kIsVotingInfoShown) } | ||
set(value) { | ||
_infoShown = value | ||
UserDefaults.standard.set(value, forKey: kIsVotingInfoShown) | ||
} | ||
} | ||
} |
Oops, something went wrong.