Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,24 @@
"@shapeshiftoss/chain-adapters": "workspace:^",
"@shapeshiftoss/contracts": "workspace:^",
"@shapeshiftoss/errors": "workspace:^",
"@shapeshiftoss/hdwallet-coinbase": "1.62.15",
"@shapeshiftoss/hdwallet-core": "1.62.15",
"@shapeshiftoss/hdwallet-gridplus": "1.62.15",
"@shapeshiftoss/hdwallet-keepkey": "1.62.15",
"@shapeshiftoss/hdwallet-keepkey-webusb": "1.62.15",
"@shapeshiftoss/hdwallet-keplr": "1.62.15",
"@shapeshiftoss/hdwallet-ledger": "1.62.15",
"@shapeshiftoss/hdwallet-ledger-webhid": "1.62.15",
"@shapeshiftoss/hdwallet-ledger-webusb": "1.62.15",
"@shapeshiftoss/hdwallet-metamask-multichain": "1.62.15",
"@shapeshiftoss/hdwallet-native": "1.62.15",
"@shapeshiftoss/hdwallet-native-vault": "1.62.15",
"@shapeshiftoss/hdwallet-phantom": "1.62.15",
"@shapeshiftoss/hdwallet-trezor": "1.62.15",
"@shapeshiftoss/hdwallet-trezor-connect": "1.62.15",
"@shapeshiftoss/hdwallet-vultisig": "1.62.15",
"@shapeshiftoss/hdwallet-walletconnect": "1.62.15",
"@shapeshiftoss/hdwallet-walletconnectv2": "1.62.15",
"@shapeshiftoss/hdwallet-coinbase": "1.62.16",
"@shapeshiftoss/hdwallet-core": "1.62.16",
"@shapeshiftoss/hdwallet-gridplus": "1.62.16",
"@shapeshiftoss/hdwallet-keepkey": "1.62.16",
"@shapeshiftoss/hdwallet-keepkey-webusb": "1.62.16",
"@shapeshiftoss/hdwallet-keplr": "1.62.16",
"@shapeshiftoss/hdwallet-ledger": "1.62.16",
"@shapeshiftoss/hdwallet-ledger-webhid": "1.62.16",
"@shapeshiftoss/hdwallet-ledger-webusb": "1.62.16",
"@shapeshiftoss/hdwallet-metamask-multichain": "1.62.16",
"@shapeshiftoss/hdwallet-native": "1.62.16",
"@shapeshiftoss/hdwallet-native-vault": "1.62.16",
"@shapeshiftoss/hdwallet-phantom": "1.62.16",
"@shapeshiftoss/hdwallet-trezor": "1.62.16",
"@shapeshiftoss/hdwallet-trezor-connect": "1.62.16",
"@shapeshiftoss/hdwallet-vultisig": "1.62.16",
"@shapeshiftoss/hdwallet-walletconnect": "1.62.16",
"@shapeshiftoss/hdwallet-walletconnectv2": "1.62.16",
"@shapeshiftoss/swapper": "workspace:^",
"@shapeshiftoss/types": "workspace:^",
"@shapeshiftoss/unchained-client": "workspace:^",
Expand Down
18 changes: 18 additions & 0 deletions packages/chain-adapters/src/error/ErrorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@ export const ErrorHandler = async (err: unknown, metadata?: ErrorMetadata): Prom
})
}

if (
err instanceof Error &&
err.message.includes('Remove inserted SafeCard to access internal GridPlus wallet')
) {
throw new ChainAdapterError(err, {
translation: 'chainAdapters.errors.gridplus.removeSafeCard',
})
}

if (
err instanceof Error &&
err.message.includes("Active SafeCard doesn't match expected SafeCard")
) {
throw new ChainAdapterError(err, {
translation: 'chainAdapters.errors.gridplus.wrongSafeCard',
})
}

if ((err as AxiosError).isAxiosError) {
const response = JSON.stringify((err as AxiosError).response?.data)
if (metadata) throw new ChainAdapterError(response, metadata)
Expand Down
13 changes: 11 additions & 2 deletions src/assets/translations/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -1429,7 +1429,9 @@
"renamed": "SafeCard renamed",
"deleted": "SafeCard deleted",
"deletedDescription": "Portfolio data has been cleared",
"warning": "Each SafeCard maintains its own portfolio. Make sure to insert the correct SafeCard in your device before connecting."
"warning": "Each SafeCard maintains its own portfolio. Make sure to insert the correct SafeCard in your device before connecting.",
"safeCardLabel": "SafeCard",
"internalSafeCardLabel": "Internal SafeCard"
},
"connect": {
"header": "Connect New SafeCard",
Expand Down Expand Up @@ -1463,6 +1465,9 @@
"deviceNotConnected": "Device not connected. Call connectDevice first.",
"connectFailure": "Unable to connect GridPlus wallet",
"unknown": "An unexpected error occurred communicating with GridPlus wallet"
},
"menu": {
"switchSafeCard": "Switch SafeCard"
}
},
"ledger": {
Expand Down Expand Up @@ -2518,7 +2523,11 @@
"getFeeData": "Failed to estimate network fees.",
"getPublicKey": "Failed to get public key from wallet.",
"getUtxos": "Failed to get utxos.",
"getValidator": "Failed to get validator."
"getValidator": "Failed to get validator.",
"gridplus": {
"wrongSafeCard": "Wrong SafeCard inserted. Please insert the correct SafeCard and try again.",
"removeSafeCard": "Remove inserted SafeCard to access internal GridPlus wallet."
}
}
},
"actionCenter": {
Expand Down
16 changes: 8 additions & 8 deletions src/components/Modals/Send/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {
import { utxoChainIds } from '@shapeshiftoss/chain-adapters'
import type { HDWallet } from '@shapeshiftoss/hdwallet-core'
import { supportsETH, supportsSolana } from '@shapeshiftoss/hdwallet-core'
import { isGridPlus } from '@shapeshiftoss/hdwallet-gridplus'
import { isLedger } from '@shapeshiftoss/hdwallet-ledger'
import { isTrezor } from '@shapeshiftoss/hdwallet-trezor'
import type { CosmosSdkChainId, EvmChainId, KnownChainIds, UtxoChainId } from '@shapeshiftoss/types'
Expand Down Expand Up @@ -150,6 +151,7 @@ export const handleSend = async ({
const supportedEvmChainIds = getSupportedEvmChainIds()
const isMetaMaskDesktop = checkIsMetaMaskDesktop(wallet)
const isVultisig = (await wallet.getModel()) === 'Vultisig'
const skipDeviceDerivation = isLedger(wallet) || isTrezor(wallet) || isGridPlus(wallet)
if (
fromChainId(asset.chainId).chainNamespace === CHAIN_NAMESPACE.CosmosSdk &&
!wallet.supportsOfflineSigning() &&
Expand Down Expand Up @@ -188,6 +190,7 @@ export const handleSend = async ({
const contractAddress = contractAddressOrUndefined(asset.assetId)
const { accountNumber } = bip44Params
const adapter = assertGetEvmChainAdapter(chainId)
const pubKey = skipDeviceDerivation ? fromAccountId(sendInput.accountId).account : undefined
return await adapter.buildSendTransaction({
to,
value,
Expand All @@ -201,6 +204,7 @@ export const handleSend = async ({
},
sendMax: sendInput.sendMax,
customNonce: sendInput.customNonce,
pubKey,
})
}

Expand All @@ -214,8 +218,7 @@ export const handleSend = async ({
}
const { accountNumber } = bip44Params
const adapter = assertGetUtxoChainAdapter(chainId)
const utxoPubKey = isTrezor(wallet) ? fromAccountId(sendInput.accountId).account : undefined
console.log('UTXO buildSendTransaction pubKey:', { isTrezor: isTrezor(wallet), utxoPubKey })
const pubKey = skipDeviceDerivation ? fromAccountId(sendInput.accountId).account : undefined
return adapter.buildSendTransaction({
to,
value,
Expand All @@ -228,7 +231,7 @@ export const handleSend = async ({
opReturnData: memo,
},
sendMax: sendInput.sendMax,
pubKey: utxoPubKey,
pubKey,
})
}

Expand Down Expand Up @@ -284,10 +287,7 @@ export const handleSend = async ({
value,
wallet,
accountNumber: bip44Params.accountNumber,
pubKey:
isLedger(wallet) || isTrezor(wallet)
? fromAccountId(sendInput.accountId).account
: undefined,
pubKey: skipDeviceDerivation ? fromAccountId(sendInput.accountId).account : undefined,
chainSpecific:
instructions.length <= 1
? {
Expand Down Expand Up @@ -328,7 +328,7 @@ export const handleSend = async ({
accountNumber: accountMetadata.bip44Params.accountNumber,
accountType: accountMetadata.accountType,
wallet,
pubKey: isTrezor(wallet) ? fromAccountId(sendInput.accountId).account : undefined,
pubKey: skipDeviceDerivation ? fromAccountId(sendInput.accountId).account : undefined,
})

const broadcastTXID = await (async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { fromAccountId } from '@shapeshiftoss/caip'
import { assertGetViemClient } from '@shapeshiftoss/contracts'
import { isGridPlus } from '@shapeshiftoss/hdwallet-gridplus'
import { isTrezor } from '@shapeshiftoss/hdwallet-trezor'
import { COW_SWAP_VAULT_RELAYER_ADDRESS, SwapperName } from '@shapeshiftoss/swapper'
import { useMutation } from '@tanstack/react-query'
Expand Down Expand Up @@ -89,7 +90,7 @@ export const useAllowanceApproval = ({
}, [activeQuote?.response.id, dispatch, isAllowanceApprovalRequired, isQueryEnabled])

const pubKey = useMemo(() => {
const skipDeviceDerivation = wallet && isTrezor(wallet)
const skipDeviceDerivation = wallet && (isTrezor(wallet) || isGridPlus(wallet))
if (!skipDeviceDerivation || !activeQuote?.params.accountId) return undefined
return fromAccountId(activeQuote.params.accountId).account
}, [wallet, activeQuote?.params.accountId])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { fromAccountId } from '@shapeshiftoss/caip'
import { assertGetViemClient } from '@shapeshiftoss/contracts'
import { isGridPlus } from '@shapeshiftoss/hdwallet-gridplus'
import { isTrezor } from '@shapeshiftoss/hdwallet-trezor'
import type { TradeQuote, TradeQuoteStep } from '@shapeshiftoss/swapper'
import { useMutation } from '@tanstack/react-query'
Expand Down Expand Up @@ -79,7 +80,7 @@ export const useAllowanceApproval = (
)

const pubKey = useMemo(() => {
const skipDeviceDerivation = wallet && isTrezor(wallet)
const skipDeviceDerivation = wallet && (isTrezor(wallet) || isGridPlus(wallet))
if (!skipDeviceDerivation || !sellAssetAccountId) return undefined
return fromAccountId(sellAssetAccountId).account
}, [wallet, sellAssetAccountId])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { SignTx, SignTypedDataInput } from '@shapeshiftoss/chain-adapters'
import { ChainAdapterError, toAddressNList } from '@shapeshiftoss/chain-adapters'
import type { ETHSignTypedData, SolanaSignTx } from '@shapeshiftoss/hdwallet-core'
import { supportsETH } from '@shapeshiftoss/hdwallet-core'
import { isGridPlus } from '@shapeshiftoss/hdwallet-gridplus'
import { isTrezor } from '@shapeshiftoss/hdwallet-trezor'
import type { SupportedTradeQuoteStepIndex, TradeQuote } from '@shapeshiftoss/swapper'
import {
Expand Down Expand Up @@ -291,13 +292,15 @@ export const useTradeExecution = (

if (!isExecutableTradeQuote(tradeQuote)) throw new Error('Unable to execute trade')

const skipDeviceDerivation = wallet && (isTrezor(wallet) || isGridPlus(wallet))
const pubKey = fromAccountId(sellAssetAccountId).account

if (swapperName === SwapperName.CowSwap) {
const adapter = assertGetEvmChainAdapter(stepSellAssetChainId)
const from = await adapter.getAddress({
accountNumber,
wallet,
pubKey:
wallet && isTrezor(wallet) ? fromAccountId(sellAssetAccountId).account : undefined,
pubKey: skipDeviceDerivation ? pubKey : undefined,
})

const output = await execution.execEvmMessage({
Expand Down Expand Up @@ -342,8 +345,7 @@ export const useTradeExecution = (
const from = await adapter.getAddress({
accountNumber,
wallet,
pubKey:
wallet && isTrezor(wallet) ? fromAccountId(sellAssetAccountId).account : undefined,
pubKey: skipDeviceDerivation ? pubKey : undefined,
})
const supportsEIP1559 = supportsETH(wallet) && (await wallet.ethSupportsEIP1559())

Expand Down Expand Up @@ -376,16 +378,14 @@ export const useTradeExecution = (

const adapter = assertGetUtxoChainAdapter(stepSellAssetChainId)

const xpub =
wallet && isTrezor(wallet)
? fromAccountId(sellAssetAccountId).account
: (await adapter.getPublicKey(wallet, accountNumber, accountType)).xpub
const xpub = skipDeviceDerivation
? pubKey
: (await adapter.getPublicKey(wallet, accountNumber, accountType)).xpub
const senderAddress = await adapter.getAddress({
accountNumber,
accountType,
wallet,
pubKey:
wallet && isTrezor(wallet) ? fromAccountId(sellAssetAccountId).account : undefined,
pubKey: skipDeviceDerivation ? pubKey : undefined,
})

const output = await execution.execUtxoTransaction({
Expand All @@ -410,7 +410,11 @@ export const useTradeExecution = (
case CHAIN_NAMESPACE.CosmosSdk: {
const adapter = assertGetCosmosSdkChainAdapter(stepSellAssetChainId)

const from = await adapter.getAddress({ accountNumber, wallet })
const from = await adapter.getAddress({
accountNumber,
wallet,
pubKey: skipDeviceDerivation ? pubKey : undefined,
})

const output = await execution.execCosmosSdkTransaction({
swapperName,
Expand Down Expand Up @@ -440,8 +444,7 @@ export const useTradeExecution = (
const from = await adapter.getAddress({
accountNumber,
wallet,
pubKey:
wallet && isTrezor(wallet) ? fromAccountId(sellAssetAccountId).account : undefined,
pubKey: skipDeviceDerivation ? pubKey : undefined,
})

const output = await execution.execSolanaTransaction({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { bchAssetId, CHAIN_NAMESPACE, fromAccountId, fromChainId } from '@shapeshiftoss/caip'
import { supportsETH } from '@shapeshiftoss/hdwallet-core'
import { isGridPlus } from '@shapeshiftoss/hdwallet-gridplus'
import { isLedger } from '@shapeshiftoss/hdwallet-ledger'
import { isTrezor } from '@shapeshiftoss/hdwallet-trezor'
import type { SupportedTradeQuoteStepIndex } from '@shapeshiftoss/swapper'
Expand Down Expand Up @@ -92,6 +93,8 @@ export const useTradeNetworkFeeCryptoBaseUnit = ({
fromChainId(stepSellAssetChainId)

const pubKey = fromAccountId(sellAssetAccountId).account
const skipDeviceDerivation =
wallet && (isLedger(wallet) || isTrezor(wallet) || isGridPlus(wallet))

switch (stepSellAssetChainNamespace) {
case CHAIN_NAMESPACE.Evm: {
Expand All @@ -100,7 +103,7 @@ export const useTradeNetworkFeeCryptoBaseUnit = ({
const from = await adapter.getAddress({
accountNumber,
wallet,
pubKey: wallet && (isLedger(wallet) || isTrezor(wallet)) ? pubKey : undefined,
pubKey: skipDeviceDerivation ? pubKey : undefined,
})
const supportsEIP1559 = supportsETH(wallet) && (await wallet.ethSupportsEIP1559())

Expand All @@ -123,15 +126,14 @@ export const useTradeNetworkFeeCryptoBaseUnit = ({
if (accountType === undefined) throw Error('Missing UTXO account type')

const adapter = assertGetUtxoChainAdapter(stepSellAssetChainId)
const xpub =
wallet && isTrezor(wallet)
? fromAccountId(sellAssetAccountId).account
: (await adapter.getPublicKey(wallet, accountNumber, accountType)).xpub
const xpub = skipDeviceDerivation
? fromAccountId(sellAssetAccountId).account
: (await adapter.getPublicKey(wallet, accountNumber, accountType)).xpub
const _senderAddress = await adapter.getAddress({
accountNumber,
accountType,
wallet,
...(isLedger(wallet) || isTrezor(wallet) ? { pubKey } : {}),
...(skipDeviceDerivation ? { pubKey } : {}),
})
const senderAddress =
stepSellAssetAssetId === bchAssetId
Expand Down Expand Up @@ -159,7 +161,7 @@ export const useTradeNetworkFeeCryptoBaseUnit = ({
const from = await adapter.getAddress({
accountNumber,
wallet,
...(isLedger(wallet) || isTrezor(wallet) ? { pubKey } : {}),
...(skipDeviceDerivation ? { pubKey } : {}),
})

const output = await swapper.getCosmosSdkTransactionFees({
Expand All @@ -181,7 +183,7 @@ export const useTradeNetworkFeeCryptoBaseUnit = ({
const from = await adapter.getAddress({
accountNumber,
wallet,
...(isLedger(wallet) || isTrezor(wallet) ? { pubKey } : {}),
...(skipDeviceDerivation ? { pubKey } : {}),
})

const output = await swapper.getSolanaTransactionFees({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { skipToken as reduxSkipToken } from '@reduxjs/toolkit/query'
import { fromAccountId } from '@shapeshiftoss/caip'
import { isGridPlus } from '@shapeshiftoss/hdwallet-gridplus'
import { isLedger } from '@shapeshiftoss/hdwallet-ledger'
import { isTrezor } from '@shapeshiftoss/hdwallet-trezor'
import type {
Expand Down Expand Up @@ -183,6 +184,9 @@ export const useGetTradeQuotes = () => {
if (sellAccountNumber === undefined) throw new Error('sellAccountNumber is required')
if (!receiveAddress) throw new Error('receiveAddress is required')

const skipDeviceDerivation =
wallet && (isLedger(wallet) || isTrezor(wallet) || isGridPlus(wallet))

const updatedTradeQuoteInput: GetTradeQuoteInput | GetTradeRateInput | undefined =
await getTradeQuoteOrRateInput({
sellAsset,
Expand All @@ -198,7 +202,7 @@ export const useGetTradeQuotes = () => {
// Pass in the user's slippage preference if it's set, else let the swapper use its default
slippageTolerancePercentageDecimal: userSlippageTolerancePercentageDecimal,
pubKey:
wallet && (isLedger(wallet) || isTrezor(wallet)) && sellAccountId
skipDeviceDerivation && sellAccountId
? fromAccountId(sellAccountId).account
: undefined,
})
Expand Down
Loading
Loading