fix: smart account feature flag (#481)

* fix: smart account namespace ordering

* feat: add feature flag for smart accounts
This commit is contained in:
Luka Isailovic 2024-02-13 18:50:16 +01:00 committed by GitHub
parent 8a8fe68c3e
commit fce1d3be56
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 9 deletions

View File

@ -23,7 +23,8 @@ export default function SettingsPage() {
multiversxAddress, multiversxAddress,
tronAddress, tronAddress,
tezosAddress, tezosAddress,
kadenaAddress kadenaAddress,
smartAccountEnabled
} = useSnapshot(SettingsStore.state) } = useSnapshot(SettingsStore.state)
return ( return (
@ -68,6 +69,20 @@ export default function SettingsPage() {
<Divider y={2} /> <Divider y={2} />
<Text h4 css={{ marginBottom: '$5' }}>
Smart Account Enabled
</Text>
<Row justify="space-between" align="center">
<Switch
checked={smartAccountEnabled}
onChange={SettingsStore.toggleSmartAccountEnabled}
data-testid="settings-toggle-smart-account-enabled"
/>
<Text>{smartAccountEnabled ? 'Enabled' : 'Disabled'}</Text>
</Row>
<Divider y={2} />
<Row justify="space-between" align="center"> <Row justify="space-between" align="center">
<Text h4 css={{ marginBottom: '$5' }}> <Text h4 css={{ marginBottom: '$5' }}>
Relayer Region Relayer Region

View File

@ -20,7 +20,8 @@ interface State {
activeChainId: string activeChainId: string
currentRequestVerifyContext?: Verify.Context currentRequestVerifyContext?: Verify.Context
sessions: SessionTypes.Struct[] sessions: SessionTypes.Struct[]
smartAccountSponsorshipEnabled: boolean smartAccountSponsorshipEnabled: boolean,
smartAccountEnabled: boolean,
} }
/** /**
@ -42,6 +43,7 @@ const state = proxy<State>({
relayerRegionURL: '', relayerRegionURL: '',
sessions: [], sessions: [],
smartAccountSponsorshipEnabled: false, smartAccountSponsorshipEnabled: false,
smartAccountEnabled: false,
}) })
/** /**
@ -116,6 +118,10 @@ const SettingsStore = {
toggleSmartAccountSponsorship() { toggleSmartAccountSponsorship() {
if (!state.testNets) return if (!state.testNets) return
state.smartAccountSponsorshipEnabled = !state.smartAccountSponsorshipEnabled state.smartAccountSponsorshipEnabled = !state.smartAccountSponsorshipEnabled
},
toggleSmartAccountEnabled() {
state.smartAccountEnabled = !state.smartAccountEnabled
} }
} }

View File

@ -48,7 +48,7 @@ const StyledSpan = styled('span', {
} as any) } as any)
export default function SessionProposalModal() { export default function SessionProposalModal() {
const { smartAccountSponsorshipEnabled } = useSnapshot(SettingsStore.state) const { smartAccountSponsorshipEnabled, smartAccountEnabled } = useSnapshot(SettingsStore.state)
// Get proposal data and wallet address from store // Get proposal data and wallet address from store
const data = useSnapshot(ModalStore.state) const data = useSnapshot(ModalStore.state)
const proposal = data?.data?.proposal as SignClientTypes.EventArguments['session_proposal'] const proposal = data?.data?.proposal as SignClientTypes.EventArguments['session_proposal']
@ -262,7 +262,7 @@ export default function SessionProposalModal() {
if (allowedChainIds.length) { if (allowedChainIds.length) {
const chainIdParsed = allowedChainIds[0].replace(`${nameSpaceKey}:`, '') const chainIdParsed = allowedChainIds[0].replace(`${nameSpaceKey}:`, '')
if (namespaces[nameSpaceKey].accounts) { if (namespaces[nameSpaceKey].accounts && smartAccountEnabled) {
const signerAddress = namespaces[nameSpaceKey].accounts[0].split(':')[2] const signerAddress = namespaces[nameSpaceKey].accounts[0].split(':')[2]
const wallet = eip155Wallets[signerAddress] const wallet = eip155Wallets[signerAddress]
const chain = allowedChains.find(chain => chain.id.toString() === chainIdParsed)! const chain = allowedChains.find(chain => chain.id.toString() === chainIdParsed)!
@ -280,12 +280,10 @@ export default function SessionProposalModal() {
const accountIsAllowed = namespaces.eip155.accounts.findIndex(account => account.includes(id)) const accountIsAllowed = namespaces.eip155.accounts.findIndex(account => account.includes(id))
return namespaces.eip155.accounts[accountIsAllowed] return namespaces.eip155.accounts[accountIsAllowed]
}) })
// when SA available, make it first on dApp
// when SA available, make it 1st on dApp
namespaces.eip155.accounts = [`${nameSpaceKey}:${chain.id}:${smartAccountAddress.address}`, ...allowedAccounts] namespaces.eip155.accounts = [`${nameSpaceKey}:${chain.id}:${smartAccountAddress.address}`, ...allowedAccounts]
} }
console.log('approving namespaces:', namespaces.eip155.accounts) console.log('approving namespaces:', namespaces.eip155.accounts)
} }
} }
@ -304,7 +302,7 @@ export default function SessionProposalModal() {
} }
setIsLoadingApprove(false) setIsLoadingApprove(false)
ModalStore.close() ModalStore.close()
}, [namespaces, proposal, smartAccountSponsorshipEnabled]) }, [namespaces, proposal, smartAccountSponsorshipEnabled, smartAccountEnabled])
// Hanlde reject action // Hanlde reject action
// eslint-disable-next-line react-hooks/rules-of-hooks // eslint-disable-next-line react-hooks/rules-of-hooks