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 Nov 30, 2023
1 parent f15c5aa commit 4fe3fea
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/core/currency/wallet/currency-wallet-cleaners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
EdgeAssetAmount,
EdgeFiatAmount,
EdgeMetadata,
EdgeSwapInfo,
EdgeTxAction,
EdgeTxActionFiat,
EdgeTxActionFiatType,
Expand Down Expand Up @@ -234,12 +235,25 @@ export const asEdgeTxActionSwapType: Cleaner<EdgeTxActionSwapType> = asValue(
'swapOrderCancel'
)

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>({
swapInfo: asEdgeSwapInfo,
type: asEdgeTxActionSwapType,
orderId: asOptional(asString),
orderUri: asOptional(asString),
isEstimate: asOptional(asBoolean),
canBePartial: asOptional(asBoolean),
sourceAsset: asEdgeAssetAmount,
destAsset: asEdgeAssetAmount
destAsset: asEdgeAssetAmount,
payoutWalletId: asString,
payoutAddress: asString
})

export const asEdgeTxActionStakeType: Cleaner<EdgeTxActionStakeType> = asValue(
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,11 +268,17 @@ export type EdgeTxActionSwapType =
| 'swapOrderCancel'

export interface EdgeTxActionSwap {
swapInfo: EdgeSwapInfo

type: EdgeTxActionSwapType
orderId?: string
orderUri?: string
isEstimate?: boolean
canBePartial?: boolean
sourceAsset: EdgeAssetAmount
destAsset: EdgeAssetAmount
payoutAddress: string
payoutWalletId: string
}

export type EdgeTxActionStakeType =
Expand Down Expand Up @@ -1196,6 +1202,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 @@ -1232,6 +1239,7 @@ export interface EdgeSwapResult {

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

/**
Expand Down
28 changes: 28 additions & 0 deletions test/core/currency/wallet/currency-wallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,13 @@ describe('currency wallets', function () {
// Perform the spend:
const metadata: EdgeMetadata = { name: 'me' }
const savedAction: EdgeTxAction = {
swapInfo: {
pluginId: 'myplugin',
displayName: 'My Plugin',
supportEmail: '[email protected]'
},
payoutAddress: '0xpayoutaddress',
payoutWalletId: '0xwalletid',
type: 'swap',
orderId: 'myorderid',
canBePartial: false,
Expand Down Expand Up @@ -504,6 +511,13 @@ describe('currency wallets', function () {
}
])
expect(txs[0].savedAction).deep.equals({
swapInfo: {
pluginId: 'myplugin',
displayName: 'My Plugin',
supportEmail: '[email protected]'
},
payoutAddress: '0xpayoutaddress',
payoutWalletId: '0xwalletid',
type: 'swap',
orderId: 'myorderid',
canBePartial: false,
Expand Down Expand Up @@ -532,6 +546,13 @@ describe('currency wallets', function () {
amountFiat: 0.75
}
const savedAction: EdgeTxAction = {
swapInfo: {
pluginId: 'myplugin',
displayName: 'My Plugin',
supportEmail: '[email protected]'
},
payoutAddress: '0xpayoutaddress',
payoutWalletId: '0xwalletid',
type: 'swap',
orderId: 'myorderid',
canBePartial: false,
Expand Down Expand Up @@ -559,6 +580,13 @@ describe('currency wallets', function () {
...metadata
})
expect(txs[0].savedAction).deep.equals({
swapInfo: {
pluginId: 'myplugin',
displayName: 'My Plugin',
supportEmail: '[email protected]'
},
payoutAddress: '0xpayoutaddress',
payoutWalletId: '0xwalletid',
type: 'swap',
orderId: 'myorderid',
canBePartial: false,
Expand Down

0 comments on commit 4fe3fea

Please sign in to comment.