feat(@desktop/wallet): greying out already imported/derived addresses in address list and also choosing next available as default one
fixes #5539
This commit is contained in:
parent
142c4122d4
commit
1cf701a758
|
@ -5,21 +5,25 @@ type
|
||||||
address: string
|
address: string
|
||||||
path: string
|
path: string
|
||||||
hasActivity: bool
|
hasActivity: bool
|
||||||
|
alreadyCreated: bool
|
||||||
|
|
||||||
proc initDerivedAddressItem*(
|
proc initDerivedAddressItem*(
|
||||||
address: string,
|
address: string,
|
||||||
path: string,
|
path: string,
|
||||||
hasActivity: bool
|
hasActivity: bool,
|
||||||
|
alreadyCreated: bool
|
||||||
): DerivedAddressItem =
|
): DerivedAddressItem =
|
||||||
result.address = address
|
result.address = address
|
||||||
result.path = path
|
result.path = path
|
||||||
result.hasActivity = hasActivity
|
result.hasActivity = hasActivity
|
||||||
|
result.alreadyCreated = alreadyCreated
|
||||||
|
|
||||||
proc `$`*(self: DerivedAddressItem): string =
|
proc `$`*(self: DerivedAddressItem): string =
|
||||||
result = fmt"""DerivedAddressItem(
|
result = fmt"""DerivedAddressItem(
|
||||||
address: {self.address},
|
address: {self.address},
|
||||||
path: {self.path},
|
path: {self.path},
|
||||||
hasActivity: {self.hasActivity}
|
hasActivity: {self.hasActivity}
|
||||||
|
alreadyCreated: {self.alreadyCreated}
|
||||||
]"""
|
]"""
|
||||||
|
|
||||||
proc getAddress*(self: DerivedAddressItem): string =
|
proc getAddress*(self: DerivedAddressItem): string =
|
||||||
|
@ -31,3 +35,7 @@ proc getPath*(self: DerivedAddressItem): string =
|
||||||
proc getHasActivity*(self: DerivedAddressItem): bool =
|
proc getHasActivity*(self: DerivedAddressItem): bool =
|
||||||
return self.hasActivity
|
return self.hasActivity
|
||||||
|
|
||||||
|
proc getAlreadyCreated*(self: DerivedAddressItem): bool =
|
||||||
|
return self.alreadyCreated
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ type
|
||||||
Address = UserRole + 1,
|
Address = UserRole + 1,
|
||||||
Path,
|
Path,
|
||||||
HasActivity,
|
HasActivity,
|
||||||
|
AlreadyCreated,
|
||||||
|
|
||||||
QtObject:
|
QtObject:
|
||||||
type
|
type
|
||||||
|
@ -45,6 +46,7 @@ QtObject:
|
||||||
ModelRole.Address.int: "address",
|
ModelRole.Address.int: "address",
|
||||||
ModelRole.Path.int: "path",
|
ModelRole.Path.int: "path",
|
||||||
ModelRole.HasActivity.int: "hasActivity",
|
ModelRole.HasActivity.int: "hasActivity",
|
||||||
|
ModelRole.AlreadyCreated.int: "alreadyCreated"
|
||||||
}.toTable
|
}.toTable
|
||||||
|
|
||||||
method data(self: DerivedAddressModel, index: QModelIndex, role: int): QVariant =
|
method data(self: DerivedAddressModel, index: QModelIndex, role: int): QVariant =
|
||||||
|
@ -64,6 +66,8 @@ QtObject:
|
||||||
result = newQVariant(item.getPath())
|
result = newQVariant(item.getPath())
|
||||||
of ModelRole.HasActivity:
|
of ModelRole.HasActivity:
|
||||||
result = newQVariant(item.getHasActivity())
|
result = newQVariant(item.getHasActivity())
|
||||||
|
of ModelRole.AlreadyCreated:
|
||||||
|
result = newQVariant(item.getAlreadyCreated())
|
||||||
|
|
||||||
proc setItems*(self: DerivedAddressModel, items: seq[DerivedAddressItem]) =
|
proc setItems*(self: DerivedAddressModel, items: seq[DerivedAddressItem]) =
|
||||||
self.beginResetModel()
|
self.beginResetModel()
|
||||||
|
@ -91,4 +95,17 @@ QtObject:
|
||||||
let item = self.derivedWalletAddresses[index]
|
let item = self.derivedWalletAddresses[index]
|
||||||
result = item.getHasActivity()
|
result = item.getHasActivity()
|
||||||
|
|
||||||
|
proc getDerivedAddressAlreadyCreatedAtIndex*(self: DerivedAddressModel, index: int): bool =
|
||||||
|
if (index < 0 or index > self.getCount()):
|
||||||
|
return
|
||||||
|
let item = self.derivedWalletAddresses[index]
|
||||||
|
result = item.getAlreadyCreated()
|
||||||
|
|
||||||
|
proc getNextSelectableDerivedAddressIndex*(self: DerivedAddressModel): int =
|
||||||
|
for i in 0 ..< self.derivedWalletAddresses.len:
|
||||||
|
if(not self.derivedWalletAddresses[i].getAlreadyCreated()):
|
||||||
|
return i
|
||||||
|
return -1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -188,7 +188,7 @@ QtObject:
|
||||||
var items: seq[DerivedAddressItem] = @[]
|
var items: seq[DerivedAddressItem] = @[]
|
||||||
let (result, error) = self.delegate.getDerivedAddressList(password, derivedfrom, path, pageSize, pageNumber)
|
let (result, error) = self.delegate.getDerivedAddressList(password, derivedfrom, path, pageSize, pageNumber)
|
||||||
for item in result:
|
for item in result:
|
||||||
items.add(initDerivedAddressItem(item.address, item.path, item.hasActivity))
|
items.add(initDerivedAddressItem(item.address, item.path, item.hasActivity, item.alreadyCreated))
|
||||||
self.derivedAddresses.setItems(items)
|
self.derivedAddresses.setItems(items)
|
||||||
self.derivedAddressesChanged()
|
self.derivedAddressesChanged()
|
||||||
return error
|
return error
|
||||||
|
@ -197,7 +197,7 @@ QtObject:
|
||||||
var items: seq[DerivedAddressItem] = @[]
|
var items: seq[DerivedAddressItem] = @[]
|
||||||
let (result, error) = self.delegate.getDerivedAddressListForMnemonic(mnemonic, path, pageSize, pageNumber)
|
let (result, error) = self.delegate.getDerivedAddressListForMnemonic(mnemonic, path, pageSize, pageNumber)
|
||||||
for item in result:
|
for item in result:
|
||||||
items.add(initDerivedAddressItem(item.address, item.path, item.hasActivity))
|
items.add(initDerivedAddressItem(item.address, item.path, item.hasActivity, item.alreadyCreated))
|
||||||
self.derivedAddresses.setItems(items)
|
self.derivedAddresses.setItems(items)
|
||||||
self.derivedAddressesChanged()
|
self.derivedAddressesChanged()
|
||||||
return error
|
return error
|
||||||
|
@ -216,3 +216,9 @@ QtObject:
|
||||||
proc getDerivedAddressHasActivityAtIndex*(self: View, index: int): bool {.slot.} =
|
proc getDerivedAddressHasActivityAtIndex*(self: View, index: int): bool {.slot.} =
|
||||||
return self.derivedAddresses.getDerivedAddressHasActivityAtIndex(index)
|
return self.derivedAddresses.getDerivedAddressHasActivityAtIndex(index)
|
||||||
|
|
||||||
|
proc getDerivedAddressAlreadyCreatedAtIndex*(self: View, index: int): bool {.slot.} =
|
||||||
|
return self.derivedAddresses.getDerivedAddressAlreadyCreatedAtIndex(index)
|
||||||
|
|
||||||
|
proc getNextSelectableDerivedAddressIndex*(self: View): int {.slot.} =
|
||||||
|
return self.derivedAddresses.getNextSelectableDerivedAddressIndex()
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,11 @@ type DerivedAddressDto* = object
|
||||||
address*: string
|
address*: string
|
||||||
path*: string
|
path*: string
|
||||||
hasActivity*: bool
|
hasActivity*: bool
|
||||||
|
alreadyCreated*: bool
|
||||||
|
|
||||||
proc toDerivedAddressDto*(jsonObj: JsonNode): DerivedAddressDto =
|
proc toDerivedAddressDto*(jsonObj: JsonNode): DerivedAddressDto =
|
||||||
result = DerivedAddressDto()
|
result = DerivedAddressDto()
|
||||||
discard jsonObj.getProp("address", result.address)
|
discard jsonObj.getProp("address", result.address)
|
||||||
discard jsonObj.getProp("path", result.path)
|
discard jsonObj.getProp("path", result.path)
|
||||||
discard jsonObj.getProp("hasActivity", result.hasActivity)
|
discard jsonObj.getProp("hasActivity", result.hasActivity)
|
||||||
|
discard jsonObj.getProp("alreadyCreated", result.alreadyCreated)
|
||||||
|
|
|
@ -17,6 +17,7 @@ Item {
|
||||||
property string pathSubFix: ""
|
property string pathSubFix: ""
|
||||||
function reset() {
|
function reset() {
|
||||||
RootStore.resetDerivedAddressModel()
|
RootStore.resetDerivedAddressModel()
|
||||||
|
_internal.nextSelectableAddressIndex = 0
|
||||||
selectedDerivedAddress.pathSubFix = 0
|
selectedDerivedAddress.pathSubFix = 0
|
||||||
selectedDerivedAddress.title = "---"
|
selectedDerivedAddress.title = "---"
|
||||||
selectedDerivedAddress.subTitle = qsTr("No activity")
|
selectedDerivedAddress.subTitle = qsTr("No activity")
|
||||||
|
@ -28,6 +29,17 @@ Item {
|
||||||
property int noOfPages: Math.ceil(RootStore.derivedAddressesList.count/pageSize)
|
property int noOfPages: Math.ceil(RootStore.derivedAddressesList.count/pageSize)
|
||||||
property int lastPageSize: RootStore.derivedAddressesList.count - ((noOfPages -1) * pageSize)
|
property int lastPageSize: RootStore.derivedAddressesList.count - ((noOfPages -1) * pageSize)
|
||||||
property bool isLastPage: stackLayout.currentIndex == (noOfPages - 1)
|
property bool isLastPage: stackLayout.currentIndex == (noOfPages - 1)
|
||||||
|
property int nextSelectableAddressIndex: RootStore.getNextSelectableDerivedAddressIndex()
|
||||||
|
|
||||||
|
onNextSelectableAddressIndexChanged: {
|
||||||
|
stackLayout.currentIndex = nextSelectableAddressIndex/_internal.pageSize
|
||||||
|
if(nextSelectableAddressIndex >= 0 && nextSelectableAddressIndex < RootStore.derivedAddressesList.count) {
|
||||||
|
selectedDerivedAddress.title = RootStore.getDerivedAddressData(nextSelectableAddressIndex)
|
||||||
|
selectedDerivedAddress.subTitle = RootStore.getDerivedAddressHasActivityData(nextSelectableAddressIndex) ? qsTr("Has Activity"): qsTr("No Activity")
|
||||||
|
selectedDerivedAddress.enabled = !RootStore.getDerivedAddressAlreadyCreatedData(nextSelectableAddressIndex)
|
||||||
|
selectedDerivedAddress.pathSubFix = nextSelectableAddressIndex
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// dimensions
|
// dimensions
|
||||||
property int popupWidth: 359
|
property int popupWidth: 359
|
||||||
|
@ -39,6 +51,8 @@ Item {
|
||||||
onModelReset: {
|
onModelReset: {
|
||||||
_internal.pageSize = 0
|
_internal.pageSize = 0
|
||||||
_internal.pageSize = 6
|
_internal.pageSize = 6
|
||||||
|
_internal.nextSelectableAddressIndex = -1
|
||||||
|
_internal.nextSelectableAddressIndex = RootStore.getNextSelectableDerivedAddressIndex()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,6 +123,7 @@ Item {
|
||||||
statusListItemTitle.anchors.right: undefined
|
statusListItemTitle.anchors.right: undefined
|
||||||
title: RootStore.getDerivedAddressData(actualIndex)
|
title: RootStore.getDerivedAddressData(actualIndex)
|
||||||
subTitle: RootStore.getDerivedAddressHasActivityData(actualIndex) ? qsTr("Has Activity"): qsTr("No Activity")
|
subTitle: RootStore.getDerivedAddressHasActivityData(actualIndex) ? qsTr("Has Activity"): qsTr("No Activity")
|
||||||
|
enabled: !RootStore.getDerivedAddressAlreadyCreatedData(actualIndex)
|
||||||
components: [
|
components: [
|
||||||
StatusBaseText {
|
StatusBaseText {
|
||||||
text: element.actualIndex
|
text: element.actualIndex
|
||||||
|
@ -122,14 +137,6 @@ Item {
|
||||||
selectedDerivedAddress.pathSubFix = actualIndex
|
selectedDerivedAddress.pathSubFix = actualIndex
|
||||||
derivedAddressPopup.close()
|
derivedAddressPopup.close()
|
||||||
}
|
}
|
||||||
Component.onCompleted: {
|
|
||||||
if(index === 0) {
|
|
||||||
selectedDerivedAddress.title = title
|
|
||||||
selectedDerivedAddress.subTitle = subTitle
|
|
||||||
selectedDerivedAddress.pathSubFix = actualIndex
|
|
||||||
stackLayout.currentIndex = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,6 +192,10 @@ QtObject {
|
||||||
return walletSectionAccounts.getDerivedAddressHasActivityAtIndex(index)
|
return walletSectionAccounts.getDerivedAddressHasActivityAtIndex(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getDerivedAddressAlreadyCreatedData(index) {
|
||||||
|
return walletSectionAccounts.getDerivedAddressAlreadyCreatedAtIndex(index)
|
||||||
|
}
|
||||||
|
|
||||||
function getDerivedAddressListForMnemonic(mnemonic, path, pageSize , pageNumber) {
|
function getDerivedAddressListForMnemonic(mnemonic, path, pageSize , pageNumber) {
|
||||||
return walletSectionAccounts.getDerivedAddressListForMnemonic(mnemonic, path, pageSize , pageNumber)
|
return walletSectionAccounts.getDerivedAddressListForMnemonic(mnemonic, path, pageSize , pageNumber)
|
||||||
}
|
}
|
||||||
|
@ -203,4 +207,8 @@ QtObject {
|
||||||
function vaildateMnemonic(mnemonic) {
|
function vaildateMnemonic(mnemonic) {
|
||||||
return onboardingModule.validateMnemonic(mnemonic)
|
return onboardingModule.validateMnemonic(mnemonic)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getNextSelectableDerivedAddressIndex() {
|
||||||
|
return walletSectionAccounts.getNextSelectableDerivedAddressIndex()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue