Skip to content

Commit da4534f

Browse files
authored
Fix(Spending limits): check selected token (#4868)
* Fix(Spending limits): check selected token * Fix tests * Move the check
1 parent 423f1d0 commit da4534f

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

apps/web/src/components/tx-flow/flows/TokenTransfer/__tests__/CreateTokenTransfer.test.tsx

+28-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as useHasPermission from '@/permissions/hooks/useHasPermission'
55
import { Permission } from '@/permissions/types'
66
import { render } from '@/tests/test-utils'
77
import { ZERO_ADDRESS } from '@safe-global/protocol-kit/dist/src/utils/constants'
8+
import { TokenType } from '@safe-global/safe-gateway-typescript-sdk'
89

910
describe('CreateTokenTransfer', () => {
1011
const mockParams = {
@@ -38,7 +39,33 @@ describe('CreateTokenTransfer', () => {
3839
.spyOn(tokenUtils, 'useTokenAmount')
3940
.mockReturnValue({ totalAmount: BigInt(1000), spendingLimitAmount: BigInt(500) })
4041

41-
const { getByText } = render(<CreateTokenTransfer params={mockParams} onSubmit={jest.fn()} />)
42+
const tokenAddress = ZERO_ADDRESS
43+
44+
const { getByText } = render(<CreateTokenTransfer params={mockParams} onSubmit={jest.fn()} />, {
45+
initialReduxState: {
46+
balances: {
47+
loading: false,
48+
data: {
49+
fiatTotal: '0',
50+
items: [
51+
{
52+
balance: '10',
53+
tokenInfo: {
54+
address: tokenAddress,
55+
decimals: 18,
56+
logoUri: 'someurl',
57+
name: 'Test token',
58+
symbol: 'TST',
59+
type: TokenType.ERC20,
60+
},
61+
fiatBalance: '10',
62+
fiatConversion: '1',
63+
},
64+
],
65+
},
66+
},
67+
},
68+
})
4269

4370
expect(getByText('Send as')).toBeInTheDocument()
4471

apps/web/src/permissions/config.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ export default <RolePermissionsConfig>{
3535
[ExecuteTransaction]: () => true,
3636
[EnablePushNotifications]: true,
3737
[CreateSpendingLimitTransaction]: ({ token } = {}) => {
38-
if (!token) {
39-
return true
40-
}
38+
if (!token) return false
4139

4240
const spendingLimit = spendingLimits.find((sl) => sl.token.address === token.address)
4341

apps/web/src/permissions/hooks/usePermission.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const usePermission = <P extends Permission>(
2525
return Object.entries(userPermissions).reduce((acc, [role, permissions]) => {
2626
const permissionValue = permissions?.[permission]
2727

28-
if (!permissionValue) {
28+
if (permissionValue === undefined) {
2929
// No permission defined for the role
3030
return acc
3131
}

0 commit comments

Comments
 (0)