Skip to content

Commit

Permalink
improve sort of assets
Browse files Browse the repository at this point in the history
  • Loading branch information
Thykof committed Jun 5, 2024
1 parent f860d36 commit e06f2e2
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions internal/handler/wallet/get_all_assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,28 @@ func (g *getAllAssets) Handle(params operations.GetAllAssetsParams) middleware.R

assetsWithBalance = append(assetsWithBalance, userAssetData...)

// sort AssetsWithBalance by name
sort.Slice(assetsWithBalance, func(i, j int) bool {
if assetsWithBalance[i].AssetInfo.Symbol == "MAS" {
return true
}
if assetsWithBalance[j].AssetInfo.Symbol == "MAS" {
return false
}
if assetsWithBalance[i].DollarValue == nil {
return false

valueI := assetsWithBalance[i].DollarValue
valueJ := assetsWithBalance[j].DollarValue

if (valueI == nil || *valueI == 0) && (valueJ == nil || *valueJ == 0) {
return assetsWithBalance[i].AssetInfo.Symbol < assetsWithBalance[j].AssetInfo.Symbol
}
if assetsWithBalance[j].DollarValue == nil {
if valueI == nil || *valueI == 0 {
return false
}
return *assetsWithBalance[i].DollarValue > *assetsWithBalance[j].DollarValue
if valueJ == nil || *valueJ == 0 {
return true
}

return *valueI > *valueJ
})

// Return the list of assets with balance
Expand Down

0 comments on commit e06f2e2

Please sign in to comment.