Skip to content

Commit f75e685

Browse files
authored
Merge branch 'main' into @szymon/nativeCryptoLib
2 parents 4d97922 + bd68f4f commit f75e685

File tree

11 files changed

+195
-112
lines changed

11 files changed

+195
-112
lines changed

packages/core-mobile/app/new/features/approval/components/NetworkFeeSelectorWithGasless.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type Props = {
1212
gasLimit: number | undefined
1313
handleFeesChange: (fees: Eip1559Fees) => void
1414
caip2ChainId: string
15+
errorMessage: string | undefined
1516
}
1617

1718
export const NetworkFeeSelectorWithGasless = ({
@@ -20,7 +21,8 @@ export const NetworkFeeSelectorWithGasless = ({
2021
shouldShowGaslessSwitch,
2122
gasLimit,
2223
caip2ChainId,
23-
handleFeesChange
24+
handleFeesChange,
25+
errorMessage
2426
}: Props): JSX.Element => {
2527
const { theme } = useTheme()
2628
const chainId = getChainIdFromCaip2(caip2ChainId)
@@ -92,6 +94,13 @@ export const NetworkFeeSelectorWithGasless = ({
9294
<View>
9395
<View>{renderGaslessSwitch()}</View>
9496
{renderNetworkFeeSelector()}
97+
{errorMessage && (
98+
<Text
99+
variant="caption"
100+
sx={{ color: '$textDanger', alignSelf: 'center', marginTop: 8 }}>
101+
{errorMessage}
102+
</Text>
103+
)}
95104
</View>
96105
)
97106
}

packages/core-mobile/app/new/features/approval/screens/ApprovalScreen/ApprovalScreen.tsx

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ import { Details } from '../../components/Details'
3333
import { Network } from '../../components/Network'
3434
import { NetworkFeeSelectorWithGasless } from '../../components/NetworkFeeSelectorWithGasless'
3535
import { SpendLimits } from '../../components/SpendLimits/SpendLimits'
36-
import { overrideContractItem, removeWebsiteItemIfNecessary } from './utils'
36+
import {
37+
getInitialGasLimit,
38+
overrideContractItem,
39+
removeWebsiteItemIfNecessary
40+
} from './utils'
3741

3842
const ApprovalScreen = ({
3943
params: { request, displayData, signingData, onApprove, onReject }
@@ -63,6 +67,9 @@ const ApprovalScreen = ({
6367
const account = useSelector(accountSelector)
6468

6569
const [submitting, setSubmitting] = useState(false)
70+
const [gasLimit, setGasLimit] = useState<number | undefined>(
71+
getInitialGasLimit(signingData)
72+
)
6673
const [maxFeePerGas, setMaxFeePerGas] = useState<bigint | undefined>()
6774
const [maxPriorityFeePerGas, setMaxPriorityFeePerGas] = useState<
6875
bigint | undefined
@@ -137,6 +144,7 @@ const ApprovalScreen = ({
137144
account,
138145
maxFeePerGas,
139146
maxPriorityFeePerGas,
147+
gasLimit,
140148
overrideData: hashedCustomSpend
141149
})
142150
router.canGoBack() && router.back()
@@ -157,6 +165,7 @@ const ApprovalScreen = ({
157165
network,
158166
maxFeePerGas,
159167
maxPriorityFeePerGas,
168+
gasLimit,
160169
hashedCustomSpend
161170
])
162171

@@ -171,11 +180,11 @@ const ApprovalScreen = ({
171180
const ethSendTx = signingData.data
172181

173182
try {
174-
const gasLimit = ethSendTx.gasLimit ? BigInt(ethSendTx.gasLimit) : 0n
183+
const gasLimitToValidate = gasLimit ? BigInt(gasLimit) : 0n
175184
const amount = ethSendTx.value ? BigInt(ethSendTx.value) : 0n
176185

177186
validateFee({
178-
gasLimit,
187+
gasLimit: gasLimitToValidate,
179188
maxFee: maxFeePerGas || 0n,
180189
amount,
181190
nativeToken,
@@ -190,9 +199,10 @@ const ApprovalScreen = ({
190199
setAmountError(SendErrorMessage.UNKNOWN_ERROR)
191200
}
192201
}
193-
}, [signingData, network, maxFeePerGas, nativeToken])
202+
}, [signingData, network, maxFeePerGas, nativeToken, gasLimit])
194203

195204
const handleFeesChange = useCallback((fees: Eip1559Fees) => {
205+
setGasLimit(fees.gasLimit)
196206
setMaxFeePerGas(fees.maxFeePerGas)
197207
setMaxPriorityFeePerGas(fees.maxPriorityFeePerGas)
198208
}, [])
@@ -354,15 +364,6 @@ const ApprovalScreen = ({
354364
useCallback((): JSX.Element | null => {
355365
if (!displayData.networkFeeSelector) return null
356366

357-
let gasLimit: number | undefined
358-
359-
if (
360-
typeof signingData.data === 'object' &&
361-
'gasLimit' in signingData.data
362-
) {
363-
gasLimit = Number(signingData.data.gasLimit || 0)
364-
}
365-
366367
return (
367368
<View sx={{ marginTop: 12 }}>
368369
<NetworkFeeSelectorWithGasless
@@ -372,6 +373,7 @@ const ApprovalScreen = ({
372373
caip2ChainId={caip2ChainId}
373374
handleFeesChange={handleFeesChange}
374375
shouldShowGaslessSwitch={shouldShowGaslessSwitch}
376+
errorMessage={amountError}
375377
/>
376378
</View>
377379
)
@@ -381,8 +383,9 @@ const ApprovalScreen = ({
381383
gaslessEnabled,
382384
setGaslessEnabled,
383385
shouldShowGaslessSwitch,
384-
signingData.data,
385-
handleFeesChange
386+
gasLimit,
387+
handleFeesChange,
388+
amountError
386389
])
387390

388391
const alert = displayData.alert

packages/core-mobile/app/new/features/approval/screens/ApprovalScreen/utils.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import {
22
RpcRequest,
33
DetailItem,
44
RpcMethod,
5-
DetailItemType
5+
DetailItemType,
6+
SigningData
67
} from '@avalabs/vm-module-types'
78
import { RequestContext } from 'store/rpc/types'
89
import { isInAppRequest } from 'store/rpc/utils/isInAppRequest'
@@ -49,3 +50,11 @@ export const overrideContractItem = (
4950

5051
return item
5152
}
53+
54+
export const getInitialGasLimit = (data: SigningData): number | undefined => {
55+
if (!data || data.type !== RpcMethod.ETH_SEND_TRANSACTION) {
56+
return undefined
57+
}
58+
59+
return data.data.gasLimit ? Number(data.data.gasLimit) : undefined
60+
}

packages/core-mobile/app/services/walletconnectv2/walletConnectCache/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export type ApprovalParams = {
3131
account,
3232
maxFeePerGas,
3333
maxPriorityFeePerGas,
34+
gasLimit,
3435
overrideData
3536
}: {
3637
walletId: string
@@ -39,6 +40,7 @@ export type ApprovalParams = {
3940
account: Account
4041
maxFeePerGas?: bigint
4142
maxPriorityFeePerGas?: bigint
43+
gasLimit?: number
4244
overrideData?: string
4345
}) => Promise<void>
4446
onReject: (message?: string) => void

packages/core-mobile/app/store/account/listeners.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import {
55
} from 'store/settings/advanced'
66
import { AppListenerEffectAPI, AppStartListening } from 'store/types'
77
import { AnyAction } from '@reduxjs/toolkit'
8-
import { onAppUnlocked, onLogIn } from 'store/app/slice'
8+
import { onAppUnlocked } from 'store/app/slice'
99
import { WalletType } from 'services/wallet/types'
1010
import AnalyticsService from 'services/analytics/AnalyticsService'
1111
import SeedlessService from 'seedless/services/SeedlessService'
1212
import { recentAccountsStore } from 'new/features/accountSettings/store'
1313
import {
1414
selectActiveWallet,
15+
selectIsMigratingActiveAccounts,
1516
selectSeedlessWallet,
1617
selectWallets,
1718
setWalletName
@@ -196,8 +197,11 @@ const migrateActiveAccountsIfNeeded = async (
196197
const state = listenerApi.getState()
197198
const activeWallet = selectActiveWallet(state)
198199
const activeAccount = selectActiveAccount(state)
200+
const isMigratingActiveAccounts = selectIsMigratingActiveAccounts(state)
201+
199202
if (
200203
!activeWallet ||
204+
isMigratingActiveAccounts ||
201205
!canMigrateActiveAccounts(activeWallet) ||
202206
!activeAccount
203207
) {
@@ -241,14 +245,28 @@ const migrateSolanaAddressesIfNeeded = async (
241245
}
242246
}
243247

248+
const handleInitAccountsIfNeeded = async (
249+
_action: AnyAction,
250+
listenerApi: AppListenerEffectAPI
251+
): Promise<void> => {
252+
const state = listenerApi.getState()
253+
const accounts = selectAccounts(state)
254+
255+
// if there are no accounts, we need to initialize them
256+
// initAcounts after onboarding might have failed
257+
// or user might have force quit the app while creating the first account
258+
if (Object.keys(accounts).length === 0) {
259+
await initAccounts(_action, listenerApi)
260+
return
261+
}
262+
263+
// if there are accounts, we need to migrate them
264+
migrateActiveAccountsIfNeeded(_action, listenerApi)
265+
}
266+
244267
export const addAccountListeners = (
245268
startListening: AppStartListening
246269
): void => {
247-
startListening({
248-
actionCreator: onLogIn,
249-
effect: initAccounts
250-
})
251-
252270
startListening({
253271
actionCreator: toggleDeveloperMode,
254272
effect: reloadAccounts
@@ -261,7 +279,7 @@ export const addAccountListeners = (
261279

262280
startListening({
263281
actionCreator: onAppUnlocked,
264-
effect: migrateActiveAccountsIfNeeded
282+
effect: handleInitAccountsIfNeeded
265283
})
266284

267285
startListening({

packages/core-mobile/app/store/account/utils.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AVM, EVM, PVM, VM } from '@avalabs/avalanchejs'
2-
import { Account, AccountCollection } from 'store/account/types'
2+
import { Account } from 'store/account/types'
33
import { Network, NetworkVMType } from '@avalabs/core-chains-sdk'
44
import WalletFactory from 'services/wallet/WalletFactory'
55
import { WalletType } from 'services/wallet/types'
@@ -17,6 +17,7 @@ import { StorageKey } from 'resources/Constants'
1717
import { appendToStoredArray, loadArrayFromStorage } from 'utils/mmkv/storages'
1818
import { setIsMigratingActiveAccounts } from 'store/wallet/slice'
1919
import WalletService from 'services/wallet/WalletService'
20+
import { selectWalletState, WalletState } from 'store/app'
2021
import { setAccounts, setNonActiveAccounts } from './slice'
2122

2223
export function getAddressByVM(
@@ -103,8 +104,9 @@ export const migrateRemainingActiveAccounts = async ({
103104
walletId: string
104105
walletType: WalletType.SEEDLESS | WalletType.MNEMONIC | WalletType.KEYSTONE
105106
startIndex: number
106-
}): Promise<AccountCollection> => {
107-
listenerApi.dispatch(setIsMigratingActiveAccounts(true))
107+
}): Promise<void> => {
108+
const { getState, dispatch } = listenerApi
109+
dispatch(setIsMigratingActiveAccounts(true))
108110

109111
try {
110112
const toastId = uuid()
@@ -120,6 +122,17 @@ export const migrateRemainingActiveAccounts = async ({
120122
startIndex
121123
})
122124

125+
const state = getState()
126+
const walletState = selectWalletState(state)
127+
if (walletState !== WalletState.ACTIVE) {
128+
Logger.error(
129+
'Wallet is not active, skipping migrateRemainingActiveAccounts'
130+
)
131+
dispatch(setIsMigratingActiveAccounts(false))
132+
global.toast?.hideAll()
133+
return
134+
}
135+
123136
const accountIds = Object.keys(accounts)
124137
if (accountIds.length > 0) {
125138
// set accounts for seedless wallet, which trigger balance update
@@ -147,16 +160,13 @@ export const migrateRemainingActiveAccounts = async ({
147160
}
148161

149162
markWalletAsMigrated(walletId)
150-
151-
return accounts
152163
} catch (error) {
153164
Logger.error('Failed to fetch remaining active accounts', error)
154165
transactionSnackbar.error({
155166
error: 'Failed to add accounts'
156167
})
157-
return {}
158168
} finally {
159-
listenerApi.dispatch(setIsMigratingActiveAccounts(false))
169+
dispatch(setIsMigratingActiveAccounts(false))
160170
}
161171
}
162172

packages/core-mobile/app/vmModule/ApprovalController/ApprovalController.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class ApprovalController implements VmModuleApprovalController {
8484
account,
8585
maxFeePerGas,
8686
maxPriorityFeePerGas,
87+
gasLimit,
8788
overrideData
8889
}: {
8990
walletId: string
@@ -92,6 +93,7 @@ class ApprovalController implements VmModuleApprovalController {
9293
account: Account
9394
maxFeePerGas?: bigint
9495
maxPriorityFeePerGas?: bigint
96+
gasLimit?: number
9597
overrideData?: string
9698
}): Promise<void> => {
9799
switch (signingData.type) {
@@ -129,6 +131,7 @@ class ApprovalController implements VmModuleApprovalController {
129131
account,
130132
maxFeePerGas,
131133
maxPriorityFeePerGas,
134+
gasLimit,
132135
overrideData,
133136
resolve
134137
})

packages/core-mobile/app/vmModule/handlers/ethSendTransaction.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const ethSendTransaction = async ({
1414
walletType,
1515
maxFeePerGas,
1616
maxPriorityFeePerGas,
17+
gasLimit,
1718
overrideData,
1819
resolve
1920
}: {
@@ -24,18 +25,27 @@ export const ethSendTransaction = async ({
2425
walletType: WalletType
2526
maxFeePerGas: bigint | undefined
2627
maxPriorityFeePerGas: bigint | undefined
28+
gasLimit: number | undefined
2729
overrideData: string | undefined
2830
resolve: (value: ApprovalResponse) => void
2931
}): Promise<void> => {
30-
const { gasLimit, type, nonce, data, from, to, value } = transactionRequest
32+
const {
33+
gasLimit: defaultGasLimit,
34+
type,
35+
nonce,
36+
data,
37+
from,
38+
to,
39+
value
40+
} = transactionRequest
3141

3242
const transaction = {
3343
nonce,
3444
type,
3545
chainId: network.chainId,
3646
maxFeePerGas,
3747
maxPriorityFeePerGas,
38-
gasLimit,
48+
gasLimit: gasLimit ? BigInt(gasLimit) : defaultGasLimit,
3949
data: overrideData ?? data,
4050
from,
4151
to,

packages/core-mobile/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,9 @@
261261
"@babel/preset-typescript": "7.25.7",
262262
"@lavamoat/allow-scripts": "3.2.1",
263263
"@playwright/test": "1.48.0",
264-
"@react-native-community/cli": "18.0.0",
265-
"@react-native-community/cli-platform-android": "18.0.0",
266-
"@react-native-community/cli-platform-ios": "18.0.0",
264+
"@react-native-community/cli": "18.0.1",
265+
"@react-native-community/cli-platform-android": "18.0.1",
266+
"@react-native-community/cli-platform-ios": "18.0.1",
267267
"@react-native/babel-preset": "0.79.5",
268268
"@react-native/eslint-config": "0.79.5",
269269
"@react-native/metro-config": "0.79.5",

packages/k2-alpine/src/components/TokenUnitInput/TokenUnitInputWidget.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ export const TokenUnitInputWidget = ({
5858
index: number
5959
): void => {
6060
const value = balance.mul(percent)
61-
textInputRef.current?.setValue(value.toDisplay())
61+
const displayValue = value.toDisplay({ asNumber: true })
62+
textInputRef.current?.setValue(displayValue.toString())
6263

6364
onChange?.(
6465
new TokenUnit(
65-
Number(value.toDisplay({ asNumber: true })) * 10 ** token.maxDecimals,
66+
displayValue * 10 ** token.maxDecimals,
6667
token.maxDecimals,
6768
token.symbol
6869
)

0 commit comments

Comments
 (0)