Skip to content

Commit

Permalink
Merge branch 'main' into CP-9073/k2-alpine-package
Browse files Browse the repository at this point in the history
  • Loading branch information
sroy3 committed Sep 3, 2024
2 parents 9171879 + 698936f commit 8d360e6
Show file tree
Hide file tree
Showing 50 changed files with 1,601 additions and 2,477 deletions.
14 changes: 14 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,22 @@ updates:
ignore:
- dependency-name: "react-native"
- dependency-name: "@react-native/metro-config"
- dependency-name: "@react-native/babel-preset"
- dependency-name: "react-native-reanimated"
- dependency-name: "react-native-mmkv" # we're currently on 2.12.2 which is the latest version compatible with react-native 0.73.7
- dependency-name: "@walletconnect/react-native-compat"
- dependency-name: "@walletconnect/types"
- dependency-name: "@walletconnect/utils"
- dependency-name: "@walletconnect/web3wallet"
- dependency-name: "@avalabs/*"
- dependency-name: "ethers" # we should be using ethers 6.8.1 (please refer to dependencies_resolutions.md)
- dependency-name: "web3" # we should be using web3 1.7.5 (please refer to dependencies_resolutions.md)
- dependency-name: "eslint" # we should be using eslint 8.50.0 (please refer to dependencies_resolutions.md)
- dependency-name: "eslint-config-prettier" # we should be using eslint-config-prettier 8.10.0 (please refer to dependencies_resolutions.md)
- dependency-name: "eslint-plugin-prettier" # to use the latest version, update eslint first
- dependency-name: "prettier" # to use the latest version, update eslint first
- dependency-name: "@typescript-eslint/eslint-plugin" # to use the latest version, update eslint first
- dependency-name: "@typescript-eslint/parser" # to use the latest version, update eslint first
- dependency-name: "bip174" # we should be using bip174 2.1.0 (please refer to dependencies_resolutions.md)
- dependency-name: "bitcoinjs-lib" # we should be using bitcoinjs-lib 5.2.0 (please refer to dependencies_resolutions.md)
- dependency-name: "bip39" # we should be using patched version of bip39 3.0.4 (please refer to /patches/bip39+3.0.4.patch)
2 changes: 1 addition & 1 deletion docs/dependencies_resolutions.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ TypeError: Cannot convert undefined or null to object
at Object.<anonymous> (/Users/vagrant/git/node_modules/jest-cli/node_modules/jest-snapshot/node_modules/@babel/highlight/node_modules/chalk/index.js:82:28)
```

### "rxjs": "7.5.6"
### "rxjs": "7.8.1"

in NftFullScreen we have a type error related to rxjs

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"alpine": "yarn workspace @avalabs/k2-alpine"
},
"devDependencies": {
"husky": "8.0.1",
"lint-staged": "15.0.2"
"husky": "9.1.5",
"lint-staged": "15.2.9"
},
"resolutions": {
"minimist": "1.2.6",
Expand All @@ -29,12 +29,12 @@
"ansi-styles": "3.2.1",
"@types/react": "18.3.4",
"@types/react-dom": "18.2.21",
"rxjs": "7.5.6",
"rxjs": "7.8.1",
"eslint": "8.50.0",
"eslint-config-prettier": "8.10.0",
"jest": "29.7.0",
"bip174": "2.1.0",
"ethers": "6.13.2",
"ethers": "6.8.1",
"web3": "1.7.5",
"@hpke/core": "1.2.7",
"@noble/secp256k1": "2.1.0"
Expand Down
24 changes: 24 additions & 0 deletions packages/core-mobile/ReactotronConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Reactotron, { type ReactotronReactNative } from 'reactotron-react-native'
import mmkvPlugin from 'reactotron-react-native-mmkv'
import { reactotronRedux } from 'reactotron-redux'
import AsyncStorage from '@react-native-async-storage/async-storage'
import { commonStorage } from 'utils/mmkv'

const reactotron = Reactotron.setAsyncStorageHandler(AsyncStorage)
.configure({
name: 'Core Mobile'
})
.useReactNative({
asyncStorage: true,
networking: {
ignoreUrls: /symbolicate/
},
editor: false,
errors: { veto: _stackFrame => false },
overlay: false
})
.use(mmkvPlugin<ReactotronReactNative>({ storage: commonStorage }))
.use(reactotronRedux())
.connect()

export default reactotron
4 changes: 4 additions & 0 deletions packages/core-mobile/app/ContextApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import SentryService from 'services/sentry/SentryService'
import CoreSplash from 'assets/icons/core_splash.svg'
import { useMigrateFromAsyncStorage } from 'hooks/useMigrateFromAsyncStorage'

if (__DEV__) {
require('../ReactotronConfig')
}

function setToast(toast: Toast): void {
global.toast = toast
}
Expand Down
25 changes: 14 additions & 11 deletions packages/core-mobile/app/contexts/SendNFTContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { useInAppRequest } from 'hooks/useInAppRequest'
import { audioFeedback, Audios } from 'utils/AudioFeedback'
import { showTransactionErrorToast } from 'utils/toast'
import { getJsonRpcErrorMessage } from 'utils/getJsonRpcErrorMessage'
import { isUserRejectedError } from 'store/rpc/providers/walletConnect/utils'

export interface SendNFTContextState {
sendToken: NFTItem
Expand Down Expand Up @@ -134,13 +135,15 @@ export const SendNFTContextProvider = ({
})
.catch(reason => {
setSendStatus('Fail')
showTransactionErrorToast({
message: getJsonRpcErrorMessage(reason)
})
AnalyticsService.capture('NftSendFailed', {
errorMessage: reason?.error?.message,
chainId: activeNetwork.chainId
})
if (!isUserRejectedError(reason)) {
showTransactionErrorToast({
message: getJsonRpcErrorMessage(reason)
})
AnalyticsService.capture('NftSendFailed', {
errorMessage: reason?.error?.message,
chainId: activeNetwork.chainId
})
}
})
.finally(() => {
SentryWrapper.finish(sentryTrx)
Expand All @@ -164,13 +167,13 @@ export const SendNFTContextProvider = ({
}

sendService
.validateStateAndCalculateFees(
.validateStateAndCalculateFees({
sendState,
activeNetwork,
activeAccount,
selectedCurrency,
account: activeAccount,
currency: selectedCurrency,
nativeTokenBalance
)
})
.then(state => {
setGasLimit(state.gasLimit ?? 0)
setError(state.error ? state.error.message : undefined)
Expand Down
70 changes: 55 additions & 15 deletions packages/core-mobile/app/contexts/SendTokenContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ import { audioFeedback, Audios } from 'utils/AudioFeedback'
import { TokenWithBalance } from '@avalabs/vm-module-types'
import { showTransactionErrorToast } from 'utils/toast'
import { getJsonRpcErrorMessage } from 'utils/getJsonRpcErrorMessage'
import { isUserRejectedError } from 'store/rpc/providers/walletConnect/utils'
import { BitcoinInputUTXO } from '@avalabs/core-wallets-sdk'
import { NetworkVMType } from '@avalabs/core-chains-sdk'
import SendServiceBTC from 'services/send/SendServiceBTC'

export type SendStatus = 'Idle' | 'Sending' | 'Success' | 'Fail'

Expand Down Expand Up @@ -72,7 +76,6 @@ export const SendTokenContextProvider = ({
const [sendToken, setSendToken] = useState<TokenWithBalance | undefined>()
const [maxAmount, setMaxAmount] = useState<Amount>(ZERO_AMOUNT)
const [sendAmount, setSendAmount] = useState<Amount>(ZERO_AMOUNT)

const [sendStatus, setSendStatus] = useState<SendStatus>('Idle')

const [sendToAddress, setSendToAddress] = useState('')
Expand All @@ -93,9 +96,40 @@ export const SendTokenContextProvider = ({

const [canSubmit, setCanSubmit] = useState(false)
const [error, setError] = useState<string | undefined>()
const [utxos, setUtxos] = useState<BitcoinInputUTXO[] | undefined>()

const { request } = useInAppRequest()

useEffect(() => {
const fetchBtcBalance = async (): Promise<void> => {
if (!activeAccount || activeNetwork.vmName !== NetworkVMType.BITCOIN)
return

const balance = await SendServiceBTC.getBalance({
isMainnet: !activeNetwork.isTestnet,
address: activeAccount.addressBTC,
currency: selectedCurrency.toLowerCase()
})
setUtxos(balance.utxos)
}

fetchBtcBalance()

const intervalId = setInterval(
() => fetchBtcBalance().catch(Logger.error),
30000
)

return () => {
clearInterval(intervalId)
}
}, [
activeAccount,
activeNetwork.isTestnet,
activeNetwork.vmName,
selectedCurrency
])

useEffect(validateStateFx, [
activeAccount,
activeNetwork,
Expand All @@ -105,7 +139,8 @@ export const SendTokenContextProvider = ({
sendToAddress,
sendToken,
defaultMaxFeePerGas,
nativeTokenBalance
nativeTokenBalance,
utxos
])

const setSendTokenAndResetAmount = useCallback(
Expand Down Expand Up @@ -137,7 +172,8 @@ export const SendTokenContextProvider = ({
amount: sendAmount.bn,
defaultMaxFeePerGas: defaultMaxFeePerGas.toSubUnit(),
gasLimit,
token: sendToken
token: sendToken,
canSubmit: true
}

InteractionManager.runAfterInteractions(() => {
Expand All @@ -164,13 +200,15 @@ export const SendTokenContextProvider = ({
})
.catch(reason => {
setSendStatus('Fail')
showTransactionErrorToast({
message: getJsonRpcErrorMessage(reason)
})
AnalyticsService.capture('SendTransactionFailed', {
errorMessage: reason.message,
chainId: activeNetwork.chainId
})
if (!isUserRejectedError(reason)) {
showTransactionErrorToast({
message: getJsonRpcErrorMessage(reason)
})
AnalyticsService.capture('SendTransactionFailed', {
errorMessage: reason.message,
chainId: activeNetwork.chainId
})
}
})
.finally(() => {
SentryWrapper.finish(sentryTrx)
Expand Down Expand Up @@ -201,15 +239,17 @@ export const SendTokenContextProvider = ({
}

sendService
.validateStateAndCalculateFees(
.validateStateAndCalculateFees({
sendState,
activeNetwork,
activeAccount,
selectedCurrency,
nativeTokenBalance
)
account: activeAccount,
currency: selectedCurrency,
nativeTokenBalance,
utxos
})
.then(state => {
setGasLimit(state.gasLimit ?? 0)

setMaxAmount({
bn: state.maxAmount ?? 0n,
amount:
Expand Down
16 changes: 9 additions & 7 deletions packages/core-mobile/app/contexts/SwapContext/SwapContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import React, {
useState
} from 'react'
import { getSwapRate, getTokenAddress } from 'swap/getSwapRate'
import { SwapSide } from 'paraswap'
import { OptimalRate } from 'paraswap-core'
import { SwapSide, OptimalRate } from '@paraswap/sdk'
import Logger from 'utils/Logger'
import { resolve } from '@avalabs/core-utils-sdk'
import { Amount } from 'types'
Expand All @@ -27,6 +26,7 @@ import { useNetworks } from 'hooks/networks/useNetworks'
import { showTransactionErrorToast } from 'utils/toast'
import { audioFeedback, Audios } from 'utils/AudioFeedback'
import { TokenWithBalance } from '@avalabs/vm-module-types'
import { isUserRejectedError } from 'store/rpc/providers/walletConnect/utils'
import { performSwap } from './performSwap/performSwap'

// success here just means the transaction was sent, not that it was successful/confirmed
Expand Down Expand Up @@ -168,11 +168,13 @@ export const SwapContextProvider = ({
.then(([result, err]) => {
if (err || (result && 'error' in result)) {
setSwapStatus('Fail')
AnalyticsService.captureWithEncryption('SwapTransactionFailed', {
address: activeAccount.addressC,
chainId: activeNetwork.chainId
})
showTransactionErrorToast({ message: humanizeSwapErrors(err) })
if (!isUserRejectedError(err)) {
AnalyticsService.captureWithEncryption('SwapTransactionFailed', {
address: activeAccount.addressC,
chainId: activeNetwork.chainId
})
showTransactionErrorToast({ message: humanizeSwapErrors(err) })
}
} else {
setSwapStatus('Success')
AnalyticsService.captureWithEncryption('SwapTransactionSucceeded', {
Expand Down
Loading

0 comments on commit 8d360e6

Please sign in to comment.