Enable per chain account selection

This commit is contained in:
Ilja 2022-03-04 14:08:20 +02:00
parent a22cd324b1
commit 39e68dfcd3

View File

@ -3,6 +3,8 @@ import ProjectInfoCard from '@/components/ProjectInfoCard'
import RequesDetailsCard from '@/components/RequestDetalilsCard' import RequesDetailsCard from '@/components/RequestDetalilsCard'
import RequestMethodCard from '@/components/RequestMethodCard' import RequestMethodCard from '@/components/RequestMethodCard'
import RequestModalContainer from '@/components/RequestModalContainer' import RequestModalContainer from '@/components/RequestModalContainer'
import { COSMOS_MAINNET_CHAINS, TCosmosChain } from '@/data/COSMOSData'
import { EIP155_CHAINS, TEIP155Chain } from '@/data/EIP155Data'
import ModalStore from '@/store/ModalStore' import ModalStore from '@/store/ModalStore'
import { cosmosAddresses } from '@/utils/CosmosWalletUtil' import { cosmosAddresses } from '@/utils/CosmosWalletUtil'
import { eip155Addresses } from '@/utils/EIP155WalletUtil' import { eip155Addresses } from '@/utils/EIP155WalletUtil'
@ -51,19 +53,7 @@ export default function SessionProposalModal() {
// Hanlde approve action // Hanlde approve action
async function onApprove() { async function onApprove() {
if (proposal) { if (proposal) {
const accounts: string[] = [] const accounts = [...selectedEIP155, ...selectedCosmos]
chains.forEach(chain => {
if (isEIP155Chain(chain)) {
selectedEIP155.forEach(address => {
accounts.push(`${chain}:${address}`)
})
} else if (isCosmosChain(chain)) {
selectedCosmos.forEach(address => {
accounts.push(`${chain}:${address}`)
})
}
})
const response = { const response = {
state: { state: {
accounts accounts
@ -95,25 +85,27 @@ export default function SessionProposalModal() {
<RequestMethodCard methods={methods} /> <RequestMethodCard methods={methods} />
<Divider y={2} />
{chains.map(chain => { {chains.map(chain => {
if (isEIP155Chain(chain)) { if (isEIP155Chain(chain)) {
return ( return (
<Row> <Fragment>
<Col> <Divider y={2} />
<Text h5>Select EIP155 Accounts</Text>
{eip155Addresses.map((address, index) => ( <Row>
<AccountSelectCard <Col>
key={address} <Text h5>{`Select ${EIP155_CHAINS[chain as TEIP155Chain].name} Accounts`}</Text>
address={address} {eip155Addresses.map((address, index) => (
index={index} <AccountSelectCard
onSelect={() => onSelectEIP155(address)} key={address}
selected={selectedEIP155.includes(address)} address={address}
/> index={index}
))} onSelect={() => onSelectEIP155(`${chain}:${address}`)}
</Col> selected={selectedEIP155.includes(`${chain}:${address}`)}
</Row> />
))}
</Col>
</Row>
</Fragment>
) )
} else if (isCosmosChain(chain)) { } else if (isCosmosChain(chain)) {
return ( return (
@ -122,14 +114,16 @@ export default function SessionProposalModal() {
<Row> <Row>
<Col> <Col>
<Text h5>Select Cosmos Accounts</Text> <Text h5>
{`Select ${COSMOS_MAINNET_CHAINS[chain as TCosmosChain].name} Accounts`}
</Text>
{cosmosAddresses.map((address, index) => ( {cosmosAddresses.map((address, index) => (
<AccountSelectCard <AccountSelectCard
key={address} key={address}
address={address} address={address}
index={index} index={index}
onSelect={() => onSelectCosmos(address)} onSelect={() => onSelectCosmos(`${chain}:${address}`)}
selected={selectedCosmos.includes(address)} selected={selectedCosmos.includes(`${chain}:${address}`)}
/> />
))} ))}
</Col> </Col>