Skip to content

Commit

Permalink
fixup! Upgrade edge-core-js to 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
paullinator committed Dec 31, 2023
1 parent ff49f69 commit 1661d3a
Show file tree
Hide file tree
Showing 23 changed files with 55 additions and 71 deletions.
2 changes: 1 addition & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1409,4 +1409,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: a84a2c04da9e8c38a3ce0d31af51c1be7866ec59

COCOAPODS: 1.14.3
COCOAPODS: 1.13.0
2 changes: 0 additions & 2 deletions src/__tests__/scenes/RequestScene.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ describe('Request', () => {
const actual = renderer.render(
<RequestSceneComponent
{...fakeSceneProps('request', {})}
account={null as any}
isConnected={false}
currencyCode={null as any}
wallet={null as any}
Expand Down Expand Up @@ -41,7 +40,6 @@ describe('Request', () => {
const actual = renderer.render(
<RequestSceneComponent
{...fakeSceneProps('request', {})}
account={null as any}
isConnected={false}
currencyCode="BTC"
wallet={fakeWallet}
Expand Down
2 changes: 1 addition & 1 deletion src/actions/CryptoExchangeActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function getQuoteForTransaction(navigation: NavigationBase, info: SetNati
navigation.navigate('exchangeTab', { screen: 'exchange' })

const insufficientFunds = asMaybeInsufficientFundsError(error)
if (insufficientFunds != null && fromWalletId != null) {
if (insufficientFunds != null && fromWalletId != null && fromTokenId !== insufficientFunds.tokenId) {
const { tokenId } = insufficientFunds
const { currencyWallets } = state.core.account
const fromWallet = currencyWallets[fromWalletId]
Expand Down
4 changes: 2 additions & 2 deletions src/actions/PaymentProtoActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from '../types/PaymentProtoTypes'
import { NavigationBase } from '../types/routerTypes'
import { EdgeAsset, StringMap } from '../types/types'
import { getTokenId } from '../util/CurrencyInfoHelpers'
import { getTokenId, getTokenIdForced } from '../util/CurrencyInfoHelpers'

export interface LaunchPaymentProtoParams {
wallet?: EdgeCurrencyWallet
Expand Down Expand Up @@ -206,7 +206,7 @@ export async function launchPaymentProto(navigation: NavigationBase, account: Ed
// This is an additional buffer because the protocol doesn't discount segwit
// transactions and we want to make sure the transaction succeeds.
const { pluginId } = selectedWallet.currencyInfo
const tokenId = getTokenId(account, selectedWallet.currencyInfo.pluginId, selectedCurrencyCode ?? selectedWallet.currencyInfo.currencyCode) ?? null
const tokenId = getTokenIdForced(account, selectedWallet.currencyInfo.pluginId, selectedCurrencyCode ?? selectedWallet.currencyInfo.currencyCode)

if (typeof requiredFeeRate === 'number' && SPECIAL_CURRENCY_INFO[pluginId].hasSegwit) requiredFeeRate *= 1.8
const spendInfo: EdgeSpendInfo = {
Expand Down
1 change: 1 addition & 0 deletions src/actions/ScanActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export function handleWalletUris(
// TOKEN URI
const { contractAddress, currencyName, denominations } = parsedUri.token
return navigation.push('editToken', {
currencyCode: parsedUri.token.currencyCode.toUpperCase(),
tokenId,
multiplier: denominations[0]?.multiplier,
displayName: currencyName,
Expand Down
2 changes: 1 addition & 1 deletion src/components/modals/FlipInputModal2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ const FlipInputModal2Component = React.forwardRef<FlipInputModalRef, Props>((pro
</View>
<EdgeText style={feeTextStyle}>
{feeCryptoText}
<FiatText nativeCryptoAmount={feeNativeAmount} wallet={wallet} maxPrecision={2} subCentTruncation tokenId={tokenId} />
<FiatText nativeCryptoAmount={feeNativeAmount} wallet={wallet} maxPrecision={2} subCentTruncation tokenId={feeTokenId} />
{parenString}
</EdgeText>
</View>
Expand Down
5 changes: 1 addition & 4 deletions src/components/scenes/EditTokenScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { lstrings } from '../../locales/strings'
import { config } from '../../theme/appConfig'
import { useSelector } from '../../types/reactRedux'
import { EdgeSceneProps } from '../../types/routerTypes'
import { getCurrencyCode } from '../../util/CurrencyInfoHelpers'
import { getWalletName } from '../../util/CurrencyWalletHelpers'
import { logActivity } from '../../util/logger'
import { ButtonsContainer } from '../buttons/ButtonsContainer'
Expand All @@ -34,10 +33,8 @@ function EditTokenSceneComponent(props: Props) {
const styles = getStyles(theme)
const account = useSelector(state => state.core.account)

const initialCurrencyCode = tokenId !== undefined ? getCurrencyCode(wallet, tokenId) : undefined

// Extract our initial state from the token:
const [currencyCode, setCurrencyCode] = React.useState(initialCurrencyCode ?? '')
const [currencyCode, setCurrencyCode] = React.useState(route.params.currencyCode ?? '')
const [displayName, setDisplayName] = React.useState(route.params.displayName ?? '')
const [contractAddress, setContractAddress] = React.useState<string>(() => {
const clean = asMaybeContractLocation(route.params.networkLocation)
Expand Down
3 changes: 1 addition & 2 deletions src/components/scenes/Fio/FioStakingChangeScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ export const FioStakingChangeScene = withWallet((props: Props) => {

const dispatch = useDispatch()
const currencyPlugin = useSelector(state => state.core.account.currencyConfig[pluginId])
const wallet = useSelector(state => state.core.account.currencyWallets[walletId])
const currencyCode = getCurrencyCode(wallet, tokenId)
const currencyCode = getCurrencyCode(currencyWallet, tokenId)
const currencyDenomination = useSelector(state => getDisplayDenomination(state, pluginId, currencyCode))
const defaultDenomination = useSelector(state => getExchangeDenomination(state, pluginId, currencyCode))
const exchangeRates = useSelector(state => state.exchangeRates)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const LoanCreateConfirmationScene = (props: Props) => {
const source: LoanAsset = {
wallet: srcWallet,
nativeAmount: nativeSrcAmount,
...(srcTokenId != null ? { tokenId: srcTokenId } : { tokenId: null })
tokenId: srcTokenId
}

const destination: LoanAsset = {
Expand Down
13 changes: 2 additions & 11 deletions src/components/scenes/RequestScene.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Clipboard from '@react-native-clipboard/clipboard'
import { lt } from 'biggystring'
import { EdgeAccount, EdgeCurrencyWallet, EdgeEncodeUri, EdgeTokenId } from 'edge-core-js'
import { EdgeCurrencyWallet, EdgeEncodeUri, EdgeTokenId } from 'edge-core-js'
import * as React from 'react'
import { ActivityIndicator, Linking, Platform, Text, TouchableOpacity, View } from 'react-native'
import Share, { ShareOptions } from 'react-native-share'
Expand Down Expand Up @@ -44,7 +44,6 @@ import { ShareButtons } from '../themed/ShareButtons'
interface OwnProps extends EdgeSceneProps<'request'> {}

interface StateProps {
account: EdgeAccount
currencyCode?: string
wallet?: EdgeCurrencyWallet
exchangeSecondaryToPrimaryRatio?: string
Expand Down Expand Up @@ -242,13 +241,10 @@ export class RequestSceneComponent extends React.Component<Props, State> {
}

handleOpenWalletListModal = () => {
const { account } = this.props
Airship.show<WalletListResult>(bridge => <WalletListModal bridge={bridge} headerTitle={lstrings.select_wallet} navigation={this.props.navigation} />)
.then(async result => {
if (result?.type === 'wallet') {
const { walletId, currencyCode } = result
const wallet = account.currencyWallets[walletId]
const tokenId = getTokenIdForced(account, wallet.currencyInfo.pluginId, currencyCode)
const { walletId, tokenId } = result
await this.props.onSelectWallet(this.props.navigation, walletId, tokenId)

if (this.flipInputRef.current != null) {
Expand Down Expand Up @@ -310,9 +306,6 @@ export class RequestSceneComponent extends React.Component<Props, State> {
// Selected denomination
const denomString = `1 ${primaryCurrencyInfo.displayDenomination.name}`

if (primaryCurrencyInfo.tokenId === undefined) {
throw new Error('RequestScene primaryCurrencyInfo.tokenId undefined')
}
return keysOnlyMode ? (
this.renderKeysOnlyMode()
) : (
Expand Down Expand Up @@ -548,7 +541,6 @@ export const RequestScene = connect<StateProps, DispatchProps, OwnProps>(

if (currencyCode == null || wallet == null) {
return {
account,
publicAddress: '',
fioAddressesExist: false,
isConnected: state.network.isConnected,
Expand All @@ -575,7 +567,6 @@ export const RequestScene = connect<StateProps, DispatchProps, OwnProps>(
const fioAddressesExist = !!state.ui.fioAddress.fioAddresses.length

return {
account,
currencyCode,
wallet,
exchangeSecondaryToPrimaryRatio,
Expand Down
5 changes: 3 additions & 2 deletions src/components/services/WalletConnectService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import '@walletconnect/react-native-compat'

import { Core } from '@walletconnect/core'
import Web3Wallet, { Web3WalletTypes } from '@walletconnect/web3wallet'
import { asNumber, asObject, asOptional, asString, asUnknown } from 'cleaners'
import { asNumber, asObject, asString, asUnknown } from 'cleaners'
import { EdgeAccount } from 'edge-core-js'
import * as React from 'react'

import { ENV } from '../../env'
import { useAsyncEffect } from '../../hooks/useAsyncEffect'
import { getAccounts, getClient, getWalletIdFromSessionNamespace, waitingClients, walletConnectClient } from '../../hooks/useWalletConnect'
import { asLegacyTokenId } from '../../types/types'
import { WcSmartContractModal } from '../modals/WcSmartContractModal'
import { Airship, showError } from '../services/AirshipInstance'

Expand Down Expand Up @@ -99,7 +100,7 @@ export const WalletConnectService = (props: Props) => {
}

// Cleaners
const payloadAmounts = asObject({ nativeAmount: asString, networkFee: asString, tokenId: asOptional(asString, null) })
const payloadAmounts = asObject({ nativeAmount: asString, networkFee: asString, tokenId: asLegacyTokenId })
const asSessionRequest = asObject({
id: asNumber,
topic: asString,
Expand Down
3 changes: 2 additions & 1 deletion src/components/themed/ManageTokensRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ export const ManageTokensRowComponent = (props: Props) => {

// Handle editing custom tokens:
const handleEdit = useHandler(() => {
const { displayName, denominations, networkLocation } = token
const { currencyCode, displayName, denominations, networkLocation } = token
navigation.navigate('editToken', {
currencyCode,
displayName,
multiplier: denominations[0]?.multiplier,
networkLocation,
Expand Down
2 changes: 0 additions & 2 deletions src/controllers/action-queue/cleaners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ const asLoanRepayActionOp = asObject<LoanRepayActionOp>({
nativeAmount: asString,
walletId: asString,
tokenId: asEdgeTokenId,

// TODO: Why was this missing in the cleaner but not in the type? @samholmes
fromTokenId: asEdgeTokenId
})

Expand Down
4 changes: 2 additions & 2 deletions src/controllers/action-queue/types/pushCleaners.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { asArray, asDate, asEither, asNumber, asObject, asOptional, asString, asTuple, asValue, Cleaner } from 'cleaners'

import { asEdgeTokenId } from '../../../types/types'
import { asLegacyTokenId } from '../../../types/types'
import { asBase64 } from '../../../util/cleaners/asBase64'
import { NewPushEvent } from './pushApiTypes'
import {
Expand All @@ -20,7 +20,7 @@ import {
export const asAddressBalanceTrigger: Cleaner<AddressBalanceTrigger> = asObject({
type: asValue('address-balance'),
pluginId: asString,
tokenId: asEdgeTokenId,
tokenId: asLegacyTokenId,
address: asString,
aboveAmount: asOptional(asString), // Satoshis or Wei or such
belowAmount: asOptional(asString) // Satoshis or Wei or such
Expand Down
6 changes: 3 additions & 3 deletions src/controllers/edgeProvider/EdgeProviderServer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { abs } from 'biggystring'
import { asArray, asOptional, Cleaner } from 'cleaners'
import { asArray, asOptional } from 'cleaners'
import {
EdgeAccount,
EdgeCurrencyWallet,
Expand Down Expand Up @@ -33,7 +33,7 @@ import { getTokenIdForced } from '../../util/CurrencyInfoHelpers'
import { getWalletName } from '../../util/CurrencyWalletHelpers'
import { makeCurrencyCodeTable } from '../../util/tokenIdTools'
import { CurrencyConfigMap } from '../../util/utils'
import { asEdgeTokenIdExtended } from './types/edgeProviderCleaners'
import { asExtendedCurrencyCode } from './types/edgeProviderCleaners'
import {
EdgeGetReceiveAddressOptions,
EdgeGetWalletHistoryResult,
Expand All @@ -45,7 +45,7 @@ import {
WalletDetails
} from './types/edgeProviderTypes'

const asCurrencyCodesArray: Cleaner<ExtendedCurrencyCode[] | undefined> = asOptional(asArray(asEdgeTokenIdExtended))
const asCurrencyCodesArray = asOptional(asArray(asExtendedCurrencyCode))

export class EdgeProviderServer implements EdgeProviderMethods {
// Private properties:
Expand Down
11 changes: 4 additions & 7 deletions src/controllers/edgeProvider/types/edgeProviderCleaners.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import { asArray, asBoolean, asEither, asNull, asNumber, asObject, asOptional, asString, asTuple, asUnknown, asValue, Cleaner } from 'cleaners'
import { asArray, asBoolean, asEither, asNumber, asObject, asOptional, asString, asTuple, asUnknown, asValue, Cleaner } from 'cleaners'
import { EdgeMemo, EdgeMetadata, EdgeNetworkFee, EdgeReceiveAddress, EdgeTransaction } from 'edge-core-js'

import { asEdgeAsset, asEdgeCurrencyCode } from '../../../types/types'
import { asEdgeAsset, asEdgeCurrencyCode, asEdgeTokenId } from '../../../types/types'
import {
EdgeGetWalletHistoryResult,
EdgeProviderDeepLink,
EdgeProviderMethods,
EdgeProviderSpendTarget,
EdgeRequestSpendOptions,
ExtendedCurrencyCode,
WalletDetails
} from './edgeProviderTypes'

export const asEdgeTokenIdExtended = asEither(asEdgeAsset, asEdgeCurrencyCode)

const asEdgeMetadata = asObject<EdgeMetadata>({
amountFiat: asOptional(asNumber),
bizId: asOptional(asNumber),
Expand Down Expand Up @@ -48,7 +45,7 @@ const asEdgeMemo = asObject<EdgeMemo>({
})

const asEdgeTransaction = asObject<EdgeTransaction>({
tokenId: asEither(asString, asNull),
tokenId: asEdgeTokenId,
walletId: asString,

currencyCode: asString,
Expand All @@ -71,7 +68,7 @@ const asEdgeTransaction = asObject<EdgeTransaction>({
txid: asString
})

const asExtendedCurrencyCode: Cleaner<ExtendedCurrencyCode> = asEither(asString, asEdgeTokenIdExtended)
export const asExtendedCurrencyCode = asEither(asString, asEdgeAsset, asEdgeCurrencyCode)

const asWalletDetails = asObject<WalletDetails>({
name: asString,
Expand Down
13 changes: 3 additions & 10 deletions src/controllers/edgeProvider/types/edgeProviderTypes.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import { EdgeMetadata, EdgeNetworkFee, EdgeReceiveAddress, EdgeTransaction } from 'edge-core-js'

export type ExtendedCurrencyCode =
| string
| {
pluginId: string
tokenId: string | null
}
| {
pluginId: string
currencyCode: string
}
import { asExtendedCurrencyCode } from './edgeProviderCleaners'

export type ExtendedCurrencyCode = ReturnType<typeof asExtendedCurrencyCode>

export interface WalletDetails {
name: string
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/redux/useContactThumbnail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const maybeShowContactsPermissionModal = (dispatch: Dispatch, contactsPer
/**
* Looks up a thumbnail image for a contact.
*/
export const useContactThumbnail = (name?: string | null): string | undefined => {
export const useContactThumbnail = (name?: string): string | undefined => {
const dispatch = useDispatch()
const contacts = useSelector(state => state.contacts)
const contactsPermissionOn = useSelector(state => state.ui.settings.contactsPermissionOn)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const makeAaveBorrowEngineFactory = (blueprint: BorrowEngineBlueprint) =>
return tokenId
}
}
return null
throw new Error(`Cannot find token for contract address: ${address}`)
}
const adjustCollateral = (tokenId: EdgeTokenId, amount: string) => {
if (instance.collaterals.length === 0) throw new Error(`Invalid execution time; too early invocation`)
Expand Down
5 changes: 3 additions & 2 deletions src/types/routerTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export interface RouteParamList {
lobbyId: string
}
editToken: {
currencyCode?: string
displayName?: string
multiplier?: string
networkLocation?: JsonObject
Expand Down Expand Up @@ -203,12 +204,12 @@ export interface RouteParamList {
loanCreateConfirmation: {
borrowEngine: BorrowEngine
borrowPlugin: BorrowPlugin
destTokenId: string
destTokenId: EdgeTokenId
destWallet: EdgeCurrencyWallet
nativeDestAmount: string
nativeSrcAmount: string
paymentMethod?: PaymentMethod
srcTokenId: string | null
srcTokenId: EdgeTokenId
srcWallet: EdgeCurrencyWallet
}
loanClose: {
Expand Down
9 changes: 7 additions & 2 deletions src/types/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { asBoolean, asEither, asMaybe, asNull, asNumber, asObject, asString } from 'cleaners'
import { asBoolean, asEither, asMaybe, asNull, asNumber, asObject, asOptional, asString } from 'cleaners'
import { EdgeCurrencyWallet, EdgeDenomination, EdgeMetadata, EdgeToken, EdgeTokenId } from 'edge-core-js/types'

import { LocaleStringKey } from '../locales/en_US'
import { RootState } from './reduxTypes'
import { Theme } from './Theme'

/** @deprecated Only to be used for payloads that still allow undefined for
* tokenId such as notification server
*/
export const asLegacyTokenId = asOptional(asString, null)

export const asEdgeTokenId = asEither(asString, asNull)
export const asEdgeAsset = asObject({
pluginId: asString,
Expand Down Expand Up @@ -318,7 +323,7 @@ export interface AppConfig {
export interface WalletListItem {
key: string

// These will be set for token rows:
// `token` will be set for token rows:
token?: EdgeToken
tokenId: EdgeTokenId

Expand Down
Loading

0 comments on commit 1661d3a

Please sign in to comment.