From 59a0dd326a2a74be734d4068b62ec13990e61c2f Mon Sep 17 00:00:00 2001 From: Paul Puey Date: Mon, 4 Dec 2023 16:36:38 -0800 Subject: [PATCH] Extend EdgeTxActionSwap params This allows us to replace SwapData with EdgeTxActionSwap --- .../wallet/currency-wallet-cleaners.ts | 17 ++++++++++++- .../currency/wallet/currency-wallet-export.ts | 12 ++++++++-- src/types/types.ts | 8 +++++++ .../currency/wallet/currency-wallet.test.ts | 24 +++++++++++++++++++ 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/src/core/currency/wallet/currency-wallet-cleaners.ts b/src/core/currency/wallet/currency-wallet-cleaners.ts index 38eec9117..f56e4b008 100644 --- a/src/core/currency/wallet/currency-wallet-cleaners.ts +++ b/src/core/currency/wallet/currency-wallet-cleaners.ts @@ -17,6 +17,7 @@ import { EdgeAssetAmount, EdgeFiatAmount, EdgeMetadata, + EdgeSwapInfo, EdgeTxAction, EdgeTxActionFiat, EdgeTxActionStake, @@ -221,12 +222,26 @@ export const asEdgeFiatAmount = asObject({ fiatAmount: asString }) +export const asEdgeSwapInfo = asObject({ + pluginId: asString, + displayName: asString, + isDex: asOptional(asBoolean), + orderUri: asOptional(asString), // The orderId would be appended to this + supportEmail: asString +}) + export const asEdgeTxActionSwap = asObject({ actionType: asValue('swap'), + swapInfo: asEdgeSwapInfo, orderId: asOptional(asString), + orderUri: asOptional(asString), + isEstimate: asOptional(asBoolean), canBePartial: asOptional(asBoolean), sourceAsset: asEdgeAssetAmount, - destAsset: asEdgeAssetAmount + destAsset: asEdgeAssetAmount, + payoutWalletId: asString, + payoutAddress: asString, + refundAddress: asOptional(asString) }) export const asEdgeTxActionStake = asObject({ diff --git a/src/core/currency/wallet/currency-wallet-export.ts b/src/core/currency/wallet/currency-wallet-export.ts index 0b53b85bb..738ec2bf7 100644 --- a/src/core/currency/wallet/currency-wallet-export.ts +++ b/src/core/currency/wallet/currency-wallet-export.ts @@ -77,8 +77,16 @@ export function searchStringFilter( if (action != null) { if (action.actionType === 'swap') { - const { pluginId = '' } = action.destAsset - if (checkNullTypeAndIndex(pluginId)) return true + const { pluginId: destPluginId } = action.destAsset + const { pluginId: sourcePluginId } = action.sourceAsset + const { displayName, supportEmail } = action.swapInfo + if ( + checkNullTypeAndIndex(sourcePluginId) || + checkNullTypeAndIndex(destPluginId) || + checkNullTypeAndIndex(displayName) || + checkNullTypeAndIndex(supportEmail) + ) + return true } } if (tx.spendTargets != null) { diff --git a/src/types/types.ts b/src/types/types.ts index 4c1e0215b..dd5c90fc2 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -268,10 +268,16 @@ export interface EdgeFiatAmount { export interface EdgeTxActionSwap { actionType: 'swap' + swapInfo: EdgeSwapInfo orderId?: string + orderUri?: string + isEstimate?: boolean canBePartial?: boolean sourceAsset: EdgeAssetAmount destAsset: EdgeAssetAmount + payoutAddress: string + payoutWalletId: string + refundAddress?: string } export interface EdgeTxActionStake { @@ -1215,6 +1221,7 @@ export interface EdgeSwapInfo { readonly displayName: string readonly isDex?: boolean + /** @deprecated Use orderUri in EdgeTxAction */ readonly orderUri?: string // The orderId would be appended to this readonly supportEmail: string } @@ -1251,6 +1258,7 @@ export interface EdgeSwapResult { export interface EdgeSwapApproveOptions { metadata?: EdgeMetadata + savedAction?: EdgeTxAction } /** diff --git a/test/core/currency/wallet/currency-wallet.test.ts b/test/core/currency/wallet/currency-wallet.test.ts index 657e73e51..9604e4f06 100644 --- a/test/core/currency/wallet/currency-wallet.test.ts +++ b/test/core/currency/wallet/currency-wallet.test.ts @@ -442,7 +442,19 @@ describe('currency wallets', function () { } const savedAction: EdgeTxAction = { actionType: 'swap', + swapInfo: { + pluginId: 'myplugin', + displayName: 'My Plugin', + supportEmail: 'support@myemail.com', + isDex: false, + orderUri: undefined + }, + isEstimate: false, + payoutAddress: '0xpayoutaddress', + payoutWalletId: '0xwalletid', + refundAddress: undefined, orderId: 'myorderid', + orderUri: 'https://myplugin.com', canBePartial: false, sourceAsset: { pluginId: 'bitcoin', @@ -534,7 +546,19 @@ describe('currency wallets', function () { } const savedAction: EdgeTxAction = { actionType: 'swap', + swapInfo: { + pluginId: 'myplugin', + displayName: 'My Plugin', + supportEmail: 'support@myemail.com', + isDex: false, + orderUri: undefined + }, + isEstimate: false, + payoutAddress: '0xpayoutaddress', + payoutWalletId: '0xwalletid', + refundAddress: undefined, orderId: 'myorderid', + orderUri: 'https://myplugin.com', canBePartial: false, sourceAsset: { pluginId: 'bitcoin',