-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
168 additions
and
34 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
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
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,36 +1,39 @@ | ||
// Copyright 2024 @polkadot-cloud/polkadot-staking-dashboard authors & contributors | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
import Keyring from '@polkadot/keyring'; | ||
import { localStorageOrDefault } from '@w3ux/utils'; | ||
import { formatAccountSs58, localStorageOrDefault } from '@w3ux/utils'; | ||
import type { ActiveProxy } from 'contexts/ActiveAccounts/types'; | ||
import type { NetworkName } from 'types'; | ||
|
||
// Gets local `activeAccount` for a network. | ||
export const getActiveAccountLocal = (network: NetworkName, ss58: number) => { | ||
const keyring = new Keyring(); | ||
keyring.setSS58Format(ss58); | ||
let account = localStorageOrDefault(`${network}_active_account`, null); | ||
if (account !== null) { | ||
account = keyring.addFromAddress(account).address; | ||
const address = localStorageOrDefault(`${network}_active_account`, null); | ||
if (address) { | ||
const formattedAddress = formatAccountSs58(address, ss58); | ||
|
||
if (formattedAddress) { | ||
return formattedAddress; | ||
} | ||
} | ||
return account; | ||
return null; | ||
}; | ||
|
||
// Gets local `activeProxy` for a network. | ||
export const getActiveProxyLocal = (network: NetworkName, ss58: number) => { | ||
const keyring = new Keyring(); | ||
keyring.setSS58Format(ss58); | ||
export const getActiveProxyLocal = ( | ||
network: NetworkName, | ||
ss58: number | ||
): ActiveProxy | null => { | ||
const localActiveProxy = localStorageOrDefault( | ||
`${network}_active_proxy`, | ||
null | ||
) as ActiveProxy | null; | ||
|
||
if (localActiveProxy !== null && localActiveProxy?.address) { | ||
localActiveProxy.address = keyring.addFromAddress( | ||
localActiveProxy.address | ||
).address; | ||
if (localActiveProxy && localActiveProxy?.address) { | ||
const formattedAddress = formatAccountSs58(localActiveProxy.address, ss58); | ||
if (formattedAddress) { | ||
localActiveProxy.address = formattedAddress; | ||
return localActiveProxy; | ||
} | ||
} | ||
|
||
return localActiveProxy; | ||
return 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
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
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
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