Skip to content

Commit

Permalink
Merge pull request #367 from Concordium/bugfix/cis2-bug-fix
Browse files Browse the repository at this point in the history
CIS2 pre-release bug fixes
  • Loading branch information
prinshamlet authored Oct 5, 2023
2 parents 80e245a + 4608c05 commit 5d96831
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ struct ButtonSlider: View {
imageName: "ccd_coins",
action: didTapTokensButton
),
// ActionButton(
// imageName: "button_slider_send",
// action: actionSend
// ),
ActionButton(
imageName: "button_slider_send",
action: actionSend
),
ActionButton(
imageName: "transaction_list",
action: didTapTransactionList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ struct TokenDetailsView: View {
var sendFunds: () -> Void
var context: Context
@State private var isAlertShown = false
@State private var isMetadataShown = false
@State var isOwned = false
@State private var error: TokenError? = nil

Expand Down Expand Up @@ -150,19 +149,12 @@ struct TokenDetailsView: View {
.foregroundColor(.gray)
Text("\(token.decimals)").font(.body)
}

Button {
isMetadataShown = true
} label: {
Text("Show raw metadata")
}
}
.padding()
}
.alert(item: $error) { error in
Alert(title: Text("Error"), message: Text(error.errorMessage), dismissButton: .default(Text("OK")))
}
.sheet(isPresented: $isMetadataShown) {}
.onReceive(service.observedTokensPublisher(for: token.accountAddress, filteredBy: token.tokenId).asResult()) { result in
switch result {
case let .success(items):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ class CIS2Service: CIS2ServiceProtocol {
.map { $0.filter { $0.contractIndex == contractIndex } }
.eraseToAnyPublisher()
}

func observedTokens(for accountAddress: String, filteredBy contractIndex: String) -> [CIS2TokenSelectionRepresentable] {
storageManager.getUserStoredCIS2Tokens(for: accountAddress, filteredBy: contractIndex).map {
map(entity: $0)
transformCIS2Token(from: $0)
}
}

Expand Down Expand Up @@ -68,8 +69,8 @@ class CIS2Service: CIS2ServiceProtocol {
.eraseToAnyPublisher()
}

private func map(entity: CIS2TokenOwnershipEntity) -> CIS2TokenSelectionRepresentable {
return CIS2TokenSelectionRepresentable(
private func transformCIS2Token(from entity: CIS2TokenOwnershipEntity) -> CIS2TokenSelectionRepresentable {
CIS2TokenSelectionRepresentable(
contractName: entity.contractName,
tokenId: entity.tokenId,
balance: .zero,
Expand Down Expand Up @@ -97,7 +98,8 @@ class CIS2Service: CIS2ServiceProtocol {
ResourceRequest(
url: ApiConstants.cis2Tokens
.appendingPathComponent(contractIndex)
.appendingPathComponent(contractSubindex)
.appendingPathComponent(contractSubindex),
parameters: ["limit" : "1000"]
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
// ConcordiumWallet
//

import BigInt
import Combine
import SwiftUI
import BigInt

enum TokenError: Error, Identifiable {
var id: String { errorMessage }
Expand Down Expand Up @@ -52,7 +52,7 @@ struct TokenLookupView: View {
)
}
}
.debounce(for: 0.5, scheduler: RunLoop.main)
.debounce(for: 1, scheduler: RunLoop.main)
.flatMapLatest { token -> AnyPublisher<[CIS2Token], TokenError> in
service.fetchTokens(contractIndex: token, contractSubindex: "0")
.map { $0.tokens }
Expand Down

0 comments on commit 5d96831

Please sign in to comment.