Skip to content

Commit

Permalink
Extend EdgeTxActionSwap params
Browse files Browse the repository at this point in the history
This allows us to replace SwapData with EdgeTxActionSwap
  • Loading branch information
paullinator committed Dec 6, 2023
1 parent 99108eb commit 59a0dd3
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
17 changes: 16 additions & 1 deletion src/core/currency/wallet/currency-wallet-cleaners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
EdgeAssetAmount,
EdgeFiatAmount,
EdgeMetadata,
EdgeSwapInfo,
EdgeTxAction,
EdgeTxActionFiat,
EdgeTxActionStake,
Expand Down Expand Up @@ -221,12 +222,26 @@ export const asEdgeFiatAmount = asObject<EdgeFiatAmount>({
fiatAmount: asString
})

export const asEdgeSwapInfo = asObject<EdgeSwapInfo>({
pluginId: asString,
displayName: asString,
isDex: asOptional(asBoolean),
orderUri: asOptional(asString), // The orderId would be appended to this
supportEmail: asString
})

export const asEdgeTxActionSwap = asObject<EdgeTxActionSwap>({
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<EdgeTxActionStake>({
Expand Down
12 changes: 10 additions & 2 deletions src/core/currency/wallet/currency-wallet-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -1251,6 +1258,7 @@ export interface EdgeSwapResult {

export interface EdgeSwapApproveOptions {
metadata?: EdgeMetadata
savedAction?: EdgeTxAction
}

/**
Expand Down
24 changes: 24 additions & 0 deletions test/core/currency/wallet/currency-wallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,19 @@ describe('currency wallets', function () {
}
const savedAction: EdgeTxAction = {
actionType: 'swap',
swapInfo: {
pluginId: 'myplugin',
displayName: 'My Plugin',
supportEmail: '[email protected]',
isDex: false,
orderUri: undefined
},
isEstimate: false,
payoutAddress: '0xpayoutaddress',
payoutWalletId: '0xwalletid',
refundAddress: undefined,
orderId: 'myorderid',
orderUri: 'https://myplugin.com',
canBePartial: false,
sourceAsset: {
pluginId: 'bitcoin',
Expand Down Expand Up @@ -534,7 +546,19 @@ describe('currency wallets', function () {
}
const savedAction: EdgeTxAction = {
actionType: 'swap',
swapInfo: {
pluginId: 'myplugin',
displayName: 'My Plugin',
supportEmail: '[email protected]',
isDex: false,
orderUri: undefined
},
isEstimate: false,
payoutAddress: '0xpayoutaddress',
payoutWalletId: '0xwalletid',
refundAddress: undefined,
orderId: 'myorderid',
orderUri: 'https://myplugin.com',
canBePartial: false,
sourceAsset: {
pluginId: 'bitcoin',
Expand Down

0 comments on commit 59a0dd3

Please sign in to comment.