Compare commits

..
1 Commits
Author SHA1 Message Date
Adw8 162efe377c Import denom from registry-sdk 2024-08-01 12:07:05 +05:30
4 changed files with 35 additions and 6 deletions
+1
View File
@@ -60,6 +60,7 @@ const Accounts = () => {
networksData,
selectedNetwork!,
accounts,
currentIndex,
);
if (!updatedNamespaces) {
+3 -1
View File
@@ -19,7 +19,7 @@ const PairingModal = ({
setModalVisible,
setToastVisible,
}: PairingModalProps) => {
const { accounts } = useAccounts();
const { accounts, currentIndex } = useAccounts();
const { selectedNetwork, networksData } = useNetworks();
const [isLoading, setIsLoading] = useState(false);
const [chainError, setChainError] = useState('');
@@ -101,6 +101,7 @@ const PairingModal = ({
networksData,
selectedNetwork!,
accounts,
currentIndex,
);
setSupportedNamespaces(nameSpaces);
} catch (err) {
@@ -126,6 +127,7 @@ const PairingModal = ({
networksData,
selectedNetwork,
accounts,
currentIndex,
setCurrentProposal,
setModalVisible,
web3wallet
+3 -1
View File
@@ -1,3 +1,5 @@
import { DENOM } from '@cerc-io/registry-sdk'
import { COSMOS_TESTNET_CHAINS } from './wallet-connect/COSMOSData';
import { EIP155_CHAINS } from './wallet-connect/EIP155Data';
@@ -10,7 +12,7 @@ export const DEFAULT_NETWORKS = [
namespace: COSMOS,
rpcUrl: process.env.REACT_APP_LACONICD_RPC_URL!,
blockExplorerUrl: '',
nativeDenom: 'alnt',
nativeDenom: DENOM,
addressPrefix: 'laconic',
coinType: '118',
gasPrice: '1',
+28 -4
View File
@@ -40,6 +40,7 @@ export const getNamespaces = async (
networksData: NetworksDataState[],
selectedNetwork: NetworksDataState,
accounts: Account[],
currentIndex: number,
) => {
const namespaceChainId = `${selectedNetwork.namespace}:${selectedNetwork.chainId}`;
@@ -100,6 +101,23 @@ export const getNamespaces = async (
const requiredAddressesArray = await Promise.all(requiredAddressesPromise);
const requiredAddresses = requiredAddressesArray.flat();
let sortedAccounts = requiredAddresses;
// If selected network is included in chains requested from dApp,
// Put selected account as first account
if (walletConnectChains.includes(namespaceChainId)) {
const currentAddresses = requiredAddresses.filter(address =>
address.includes(namespaceChainId),
);
sortedAccounts = [
currentAddresses[currentIndex],
...currentAddresses.filter((address, index) => index !== currentIndex),
...requiredAddresses.filter(
address => !currentAddresses.includes(address),
),
];
}
// construct namespace object
const newNamespaces = {
eip155: {
@@ -115,7 +133,7 @@ export const getNamespaces = async (
...(optionalNamespaces.eip155?.events ?? []),
...(requiredNamespaces.eip155?.events ?? []),
],
accounts: requiredAddresses.filter(account => account.includes(EIP155)),
accounts: sortedAccounts.filter(account => account.includes(EIP155)),
},
cosmos: {
chains: walletConnectChains.filter(chain => chain.includes(COSMOS)),
@@ -129,12 +147,18 @@ export const getNamespaces = async (
...(optionalNamespaces.cosmos?.events ?? []),
...(requiredNamespaces.cosmos?.events ?? []),
],
accounts: requiredAddresses.filter(account => account.includes(COSMOS)),
accounts: sortedAccounts.filter(account => account.includes(COSMOS)),
},
};
return newNamespaces;
} else {
// Set selected account as the first account in supported namespaces
const sortedAccounts = [
accounts[currentIndex],
...accounts.filter((account, index) => index !== currentIndex),
];
switch (selectedNetwork.namespace) {
case EIP155:
return {
@@ -151,7 +175,7 @@ export const getNamespaces = async (
...(optionalNamespaces.eip155?.events ?? []),
...(requiredNamespaces.eip155?.events ?? []),
],
accounts: accounts.map(ethAccount => {
accounts: sortedAccounts.map(ethAccount => {
return `${namespaceChainId}:${ethAccount.address}`;
}),
},
@@ -176,7 +200,7 @@ export const getNamespaces = async (
...(optionalNamespaces.cosmos?.events ?? []),
...(requiredNamespaces.cosmos?.events ?? []),
],
accounts: accounts.map(cosmosAccount => {
accounts: sortedAccounts.map(cosmosAccount => {
return `${namespaceChainId}:${cosmosAccount.address}`;
}),
},