Skip to content

Commit

Permalink
Merge pull request #309 from cosmostation/feature/307_chain_order_custom
Browse files Browse the repository at this point in the history
Feature/307 chain order custom
  • Loading branch information
wannabit-yongjoo authored Oct 26, 2021
2 parents a603131 + 506ff53 commit d92c50d
Show file tree
Hide file tree
Showing 38 changed files with 1,591 additions and 1,471 deletions.
48 changes: 40 additions & 8 deletions Cosmos-IOS/Cosmostation/Cosmostation.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "iconEdit.pdf",
"idiom" : "universal"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "iconListadd.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "iconListdelete.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ [email protected]";
"title_ibc_transfer" = "IBC Send";
"title_sif_dex" = "SifChain Dex";
"title_sif_incentive" = "Incentive Claim";
"title_edit_chain" = "Edit Chains";


"proposal_type_basic" = "Basic";
Expand Down Expand Up @@ -685,6 +686,9 @@ [email protected]";
"error_noting_repay_asset" = "Noting to be repaid";
"error_remain_borrow_small" = "Remain borrow amount less than $10";
"error_alreay_rizon_swap" = "There is already a swap request in progress.";
"error_max_account_number" = "No more accounts can be added to this chain.";
"error_reserve_1_account" = "Please reserve at least 1 account to displayed.";
"error_hided_chain" = "Hidden Chain.";



Expand Down
5 changes: 4 additions & 1 deletion Cosmos-IOS/Cosmostation/Cosmostation/Base/BaseConstant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ let SUPPORT_BEP3_SWAP = true;

let KEY_RECENT_ACCOUNT = "KEY_RECENT_ACCOUNT"
let KEY_RECENT_CHAIN = "KEY_RECENT_CHAIN"
let KEY_RECENT_CHAIN_S = "KEY_RECENT_CHAIN_S"
let KEY_ALL_VAL_SORT = "KEY_ALL_VAL_SORT"
let KEY_MY_VAL_SORT = "KEY_MY_VAL_SORT"
let KEY_LAST_TAB = "KEY_LAST_TAB"
Expand All @@ -23,6 +24,8 @@ let KEY_USING_BIO_AUTH = "KEY_USING_BIO_AUTH"
let KEY_ENGINER_MODE = "KEY_ENGINER_MODE"
let KEY_FCM_TOKEN = "KEY_FCM_TOKEN"
let KEY_KAVA_TESTNET_WARN = "KEY_KAVA_TESTNET_WARN"
let KEY_USER_HIDEN_CHAINS = "KEY_USER_HIDEN_CHAINS"
let KEY_USER_SORTED_CHAINS = "KEY_USER_SORTED_CHAINS"
let KEY_PRE_EVENT_HIDE = "KEY_PRE_EVENT_HIDE"

let STATION_URL = "https://api-utility.cosmostation.io/";
Expand Down Expand Up @@ -403,7 +406,7 @@ let PASSWORD_RESUKT_CANCEL = 1
let PASSWORD_RESUKT_FAIL = 2
let PASSWORD_RESUKT_OK_FOR_DELETE = 3


let MAX_WALLET_PER_CHAIN = 5
let BASE_PATH = "m/44'/118'/0'/0/"
let BNB_BASE_PATH = "m/44'/714'/0'/0/"
let KAVA_BASE_PATH = "m/44'/459'/0'/0/"
Expand Down
145 changes: 103 additions & 42 deletions Cosmos-IOS/Cosmostation/Cosmostation/Base/BaseData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,6 @@ final class BaseData : NSObject{
return nil
}

// func getIbcSendableChains() -> Array<ChainType> {
// var result = Array<ChainType>()
// for ibcPath in mIbcPaths {
// if ibcPath.paths.filter({ $0.auth == true }).first != nil {
// if let chainType = WUtils.getChainTypeByChainId(ibcPath.chain_id) {
// result.append(chainType)
// }
// }
// }
// return result
// }

func getIbcSendableRelayers() -> Array<IbcPath> {
var result = Array<IbcPath>()
for ibcPath in mIbcPaths {
Expand All @@ -139,16 +127,6 @@ final class BaseData : NSObject{
return result
}

// func getIbcRollbackChain(_ denom: String) -> Array<ChainType> {
// var result = Array<ChainType>()
// if let ibcToken = getIbcToken(denom.replacingOccurrences(of: "ibc/", with: "")) {
// if let chainType = WUtils.getChainTypeByChainId(ibcToken.counter_party?.chain_id) {
// result.append(chainType)
// }
// }
// return result
// }

func getIbcRollbackRelayer(_ denom: String) -> Array<IbcPath> {
var result = Array<IbcPath>()
if let ibcToken = getIbcToken(denom.replacingOccurrences(of: "ibc/", with: "")) {
Expand All @@ -161,17 +139,6 @@ final class BaseData : NSObject{
return result
}

// func getIbcCounterChainId(_ channelId: String?) -> String {
// for ibcPath in mIbcPaths {
// for path in ibcPath.paths {
// if (path.channel_id == channelId) {
// return ibcPath.chain_id ?? ""
// }
// }
// }
// return ""
// }

func getBaseDenom(_ denom: String) -> String {
if (denom.starts(with: "ibc/")) {
guard let ibcToken = getIbcToken(denom.replacingOccurrences(of: "ibc/", with: "")) else {
Expand Down Expand Up @@ -501,23 +468,34 @@ final class BaseData : NSObject{
}

func getRecentAccountId() -> Int64 {
return Int64(UserDefaults.standard.integer(forKey: KEY_RECENT_ACCOUNT))
let account = selectAccountById(id: Int64(UserDefaults.standard.integer(forKey: KEY_RECENT_ACCOUNT)))
let chainType = WUtils.getChainType(account!.account_base_chain)!
if (dpSortedChains().contains(chainType)) {
return Int64(UserDefaults.standard.integer(forKey: KEY_RECENT_ACCOUNT))

} else {
for dpChain in dpSortedChains() {
if (selectAllAccountsByChain(dpChain).count > 0) {
return selectAllAccountsByChain(dpChain)[0].account_id
}
}
return Int64(UserDefaults.standard.integer(forKey: KEY_RECENT_ACCOUNT))
}
}

func setRecentChain(_ id : Int) {
UserDefaults.standard.set(id, forKey: KEY_RECENT_CHAIN)
func setRecentChain(_ chain : ChainType) {
UserDefaults.standard.set(WUtils.getChainDBName(chain), forKey: KEY_RECENT_CHAIN_S)
}

func getRecentChain() -> Int {
let position = Int(UserDefaults.standard.integer(forKey: KEY_RECENT_CHAIN))
if (ChainType.SUPPRT_CHAIN().count < position) {
return 0
func getRecentChain() -> ChainType {
let chain = WUtils.getChainType(UserDefaults.standard.string(forKey: KEY_RECENT_CHAIN_S) ?? CHAIN_COSMOS_S)!
if (userSortedChains().contains(chain)) {
return chain
} else {
return position
return ChainType.COSMOS_MAIN
}
}


func setAllValidatorSort(_ sort : Int64) {
UserDefaults.standard.set(sort, forKey: KEY_ALL_VAL_SORT)
}
Expand Down Expand Up @@ -687,6 +665,89 @@ final class BaseData : NSObject{
return false
}

func getUserHiddenChains() -> Array<String>? {
return UserDefaults.standard.stringArray(forKey: KEY_USER_HIDEN_CHAINS) ?? []
}

func setUserHiddenChains(_ hidedChains: Array<ChainType>) {
var toHideChain = Array<String>()
hidedChains.forEach { chainType in
toHideChain.append(WUtils.getChainDBName(chainType))
}
UserDefaults.standard.set(toHideChain, forKey: KEY_USER_HIDEN_CHAINS)
}

func getUserSortedChains() -> Array<String>? {
return UserDefaults.standard.stringArray(forKey: KEY_USER_SORTED_CHAINS) ?? []
}

func setUserSortedChains(_ displayedChains: Array<ChainType>) {
var toDisplayChain = Array<String>()
displayedChains.forEach { chainType in
toDisplayChain.append(WUtils.getChainDBName(chainType))
}
UserDefaults.standard.set(toDisplayChain, forKey: KEY_USER_SORTED_CHAINS)
}

func userDisplayChains() -> Array<ChainType> {
var result = Array<ChainType>()
let allChains = ChainType.SUPPRT_CHAIN().dropFirst()
let hiddenChains = userHideChains()
allChains.forEach { chain in
if (hiddenChains.contains(chain) == false) {
result.append(chain)
}
}
return result;
}

func userHideChains() -> Array<ChainType> {
var result = Array<ChainType>()
let allChains = ChainType.SUPPRT_CHAIN().dropFirst()
let hiddenChainS = getUserHiddenChains()
allChains.forEach { chain in
if (hiddenChainS?.contains(WUtils.getChainDBName(chain)) == true) {
result.append(chain)
}
}
return result;
}

func userSortedChains() -> Array<ChainType> {
var result = Array<ChainType>()
let rawDpChains = userDisplayChains()
let orderedChainS = getUserHiddenChains()
orderedChainS?.forEach({ chainS in
if (rawDpChains.contains(WUtils.getChainType(chainS)!) == true) {
result.append(WUtils.getChainType(chainS)!)
}
})
rawDpChains.forEach { chain in
if (result.contains(chain) == false) {
result.append(chain)
}
}
return result;
}

func dpSortedChains() -> Array<ChainType> {
var result = Array<ChainType>()
result.append(ChainType.COSMOS_MAIN)
let rawDpChains = userDisplayChains()
let orderedChainS = getUserHiddenChains()
orderedChainS?.forEach({ chainS in
if (rawDpChains.contains(WUtils.getChainType(chainS)!) == true) {
result.append(WUtils.getChainType(chainS)!)
}
})
rawDpChains.forEach { chain in
if (result.contains(chain) == false) {
result.append(chain)
}
}
return result;
}


func initdb() {
do {
Expand Down
Loading

0 comments on commit d92c50d

Please sign in to comment.