Skip to content

Commit

Permalink
CP-8870: Transaction parsing, validation and simulation with EVM modu…
Browse files Browse the repository at this point in the history
…le (#1408)
  • Loading branch information
onghwan authored Jul 24, 2024
1 parent 26acd76 commit 0872748
Show file tree
Hide file tree
Showing 35 changed files with 755 additions and 1,059 deletions.
1 change: 0 additions & 1 deletion packages/core-mobile/.storybook/storybook.requires.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ try {

const getStories = () => {
return {
"./storybook/stories/ApproveTransactionView.stories.tsx": require("../storybook/stories/ApproveTransactionView.stories.tsx"),
"./storybook/stories/AvaListItem.stories.tsx": require("../storybook/stories/AvaListItem.stories.tsx"),
"./storybook/stories/AvaText.stories.tsx": require("../storybook/stories/AvaText.stories.tsx"),
"./storybook/stories/BottomSheet.stories.tsx": require("../storybook/stories/BottomSheet.stories.tsx"),
Expand Down
37 changes: 0 additions & 37 deletions packages/core-mobile/app/components/Banner.tsx

This file was deleted.

218 changes: 101 additions & 117 deletions packages/core-mobile/app/components/EditSpendLimit.tsx
Original file line number Diff line number Diff line change
@@ -1,143 +1,127 @@
import AvaText from 'components/AvaText'
import { Space } from 'components/Space'
import { View } from 'react-native'
import AvaButton from 'components/AvaButton'
import React, { useState } from 'react'
import { useApplicationContext } from 'contexts/ApplicationContext'
import FlexSpacer from 'components/FlexSpacer'
import { Row } from 'components/Row'
import { Checkbox } from 'components/Checkbox'
import { BNInput } from 'components/BNInput'
import BN from 'bn.js'
import { PeerMeta } from 'store/rpc/types'
import { TokenWithBalanceERC20 } from '@avalabs/vm-module-types'
import { useRoute } from '@react-navigation/native'
import { WalletScreenProps } from 'navigation/types'
import AppNavigation from 'navigation/AppNavigation'
import RpcRequestBottomSheet from 'screens/rpc/components/shared/RpcRequestBottomSheet'
import { View, Text, Button } from '@avalabs/k2-mobile'
import { Limit, SpendLimit } from 'hooks/useSpendLimits'
import { hexToBN } from '@avalabs/utils-sdk'

export enum Limit {
DEFAULT = 'DEFAULT',
UNLIMITED = 'UNLIMITED',
CUSTOM = 'CUSTOM'
}

export interface SpendLimit {
limitType: Limit
value?: {
bn: BN
amount: string
}
}

interface Props {
token: TokenWithBalanceERC20
setSpendLimit(limitData: SpendLimit): void
onClose(): void
spendLimit: SpendLimit
requestedApprovalLimit?: BN
site: PeerMeta | null | undefined
}

const EditSpendLimit = ({
spendLimit,
token,
onClose,
setSpendLimit,
site,
requestedApprovalLimit
}: Props): JSX.Element => {
const { theme } = useApplicationContext()
const EditSpendLimit = (): JSX.Element | null => {
const { spendLimit, onClose, updateSpendLimit, dAppName, editingToken } =
useRoute<EditSpendLimitScreenProps['route']>().params
const [customSpendLimit, setCustomSpendLimit] = useState<SpendLimit>({
...spendLimit
})

const handleOnSave = (): void => {
setSpendLimit(customSpendLimit)
updateSpendLimit(customSpendLimit)
onClose()
}

return (
<View style={{ flex: 1, paddingBottom: 16, paddingHorizontal: 16 }}>
<AvaText.LargeTitleBold>Edit Spend Limit</AvaText.LargeTitleBold>
<Space y={24} />
<AvaText.Body2 color={theme.colorText1}>Spending Limit</AvaText.Body2>
<Space y={8} />
<AvaText.Body2 color={theme.colorText2}>
Set a limit that you will allow {site?.name} to withdraw and spend.
</AvaText.Body2>
<Space y={26} />
<Row style={{ alignItems: 'center' }}>
<Checkbox
selected={customSpendLimit.limitType === Limit.UNLIMITED}
onPress={() => {
setCustomSpendLimit({
...customSpendLimit,
limitType: Limit.UNLIMITED
})
}}
/>
<Space x={18} />
<AvaText.Heading2>Unlimited</AvaText.Heading2>
</Row>
<Space y={8} />
<Row style={{ alignItems: 'flex-start' }}>
<Checkbox
selected={customSpendLimit.limitType === Limit.DEFAULT}
onPress={() => {
setCustomSpendLimit({
...customSpendLimit,
limitType: Limit.DEFAULT
})
}}
/>
<Space x={18} />
<View>
<AvaText.Heading2 textStyle={{ marginTop: 14 }}>
Default
</AvaText.Heading2>

<BNInput
value={requestedApprovalLimit}
denomination={token.decimals}
editable={false}
selectTextOnFocus={false}
style={{ maxWidth: 300 }}
<RpcRequestBottomSheet onClose={onClose}>
<View
style={{
flex: 1,
paddingBottom: 16,
paddingHorizontal: 16
}}>
<Text variant="heading3">Edit Spend Limit</Text>
<Space y={24} />
<Text variant="body2">Spending Limit</Text>
<Space y={8} />
<Text variant="body2" sx={{ color: '$neutral400' }}>
Set a limit that you will allow {dAppName} to withdraw and spend.
</Text>
<Space y={26} />
<Row style={{ alignItems: 'center' }}>
<Checkbox
selected={customSpendLimit.limitType === Limit.UNLIMITED}
onPress={() => {
setCustomSpendLimit({
...customSpendLimit,
limitType: Limit.UNLIMITED
})
}}
/>
</View>
</Row>
<Space y={8} />
<Row style={{ justifyContent: 'flex-start' }}>
<Checkbox
selected={customSpendLimit.limitType === Limit.CUSTOM}
onPress={() => {
setCustomSpendLimit({
...customSpendLimit,
limitType: Limit.CUSTOM
})
}}
/>
<View style={{ alignItems: 'flex-start', paddingTop: 13 }}>
<AvaText.Heading2 textStyle={{ paddingStart: 16 }}>
Custom Spend Limit
</AvaText.Heading2>
<BNInput
value={customSpendLimit?.value?.bn}
placeholder={'Custom Limit'}
onChange={value => {
<Space x={18} />
<Text variant="buttonLarge">Unlimited</Text>
</Row>
<Space y={8} />
<Row style={{ alignItems: 'flex-start' }}>
<Checkbox
selected={customSpendLimit.limitType === Limit.DEFAULT}
onPress={() => {
setCustomSpendLimit({
...customSpendLimit,
limitType: Limit.DEFAULT
})
}}
/>
<Space x={18} />
<View>
<Text variant="buttonLarge" sx={{ marginTop: 14 }}>
Default
</Text>
<BNInput
value={hexToBN(editingToken.defaultValue)}
denomination={editingToken.decimals}
editable={false}
selectTextOnFocus={false}
style={{ maxWidth: 300 }}
/>
</View>
</Row>
<Space y={8} />
<Row style={{ justifyContent: 'flex-start' }}>
<Checkbox
selected={customSpendLimit.limitType === Limit.CUSTOM}
onPress={() => {
setCustomSpendLimit({
...customSpendLimit,
value,
limitType: Limit.CUSTOM
})
}}
denomination={token.decimals}
/>
</View>
</Row>
<FlexSpacer />
<AvaButton.PrimaryLarge
style={{ marginHorizontal: 12 }}
onPress={handleOnSave}>
Save
</AvaButton.PrimaryLarge>
</View>
<View sx={{ alignItems: 'flex-start', paddingTop: 13 }}>
<Text variant="buttonLarge" sx={{ paddingStart: 16 }}>
Custom Spend Limit
</Text>
<BNInput
value={customSpendLimit?.value?.bn}
placeholder={'Custom Limit'}
onChange={value => {
setCustomSpendLimit({
...customSpendLimit,
value,
limitType: Limit.CUSTOM
})
}}
denomination={editingToken.decimals}
/>
</View>
</Row>
<FlexSpacer />
<Button
type="primary"
size="xlarge"
style={{ marginHorizontal: 12 }}
onPress={handleOnSave}>
Save
</Button>
</View>
</RpcRequestBottomSheet>
)
}

type EditSpendLimitScreenProps = WalletScreenProps<
typeof AppNavigation.Modal.EditSpendLimit
>

export default EditSpendLimit
Loading

0 comments on commit 0872748

Please sign in to comment.