Skip to content

Commit

Permalink
Add EdgeTxActionFiat tx action
Browse files Browse the repository at this point in the history
  • Loading branch information
paullinator committed Dec 6, 2023
1 parent 20449ef commit 99108eb
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
37 changes: 35 additions & 2 deletions src/core/currency/wallet/currency-wallet-cleaners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import {
EdgeAssetAction,
EdgeAssetActionType,
EdgeAssetAmount,
EdgeFiatAmount,
EdgeMetadata,
EdgeTxAction,
EdgeTxActionFiat,
EdgeTxActionStake,
EdgeTxActionSwap,
EdgeTxSwap
Expand Down Expand Up @@ -213,6 +215,11 @@ export const asEdgeAssetAmount = asObject<EdgeAssetAmount>({
tokenId: asOptional(asString),
nativeAmount: asOptional(asIntegerString)
})
export const asEdgeFiatAmount = asObject<EdgeFiatAmount>({
// core-js style fiat code including 'iso:'
fiatCurrencyCode: asString,
fiatAmount: asString
})

export const asEdgeTxActionSwap = asObject<EdgeTxActionSwap>({
actionType: asValue('swap'),
Expand All @@ -227,7 +234,30 @@ export const asEdgeTxActionStake = asObject<EdgeTxActionStake>({
stakeAssets: asArray(asEdgeAssetAmount)
})

export const asEdgeTxAction = asEither(asEdgeTxActionSwap, asEdgeTxActionStake)
export const asEdgeTxActionFiat = asObject<EdgeTxActionFiat>({
actionType: asValue('fiat'),

orderId: asString,
orderUri: asOptional(asString),
isEstimate: asBoolean,

fiatPlugin: asObject({
providerId: asString,
providerDisplayName: asString,
supportEmail: asOptional(asString)
}),

payinAddress: asOptional(asString),
payoutAddress: asOptional(asString),
fiatAsset: asEdgeFiatAmount,
cryptoAsset: asEdgeAssetAmount
})

export const asEdgeTxAction: Cleaner<EdgeTxAction> = asEither(
asEdgeTxActionSwap,
asEdgeTxActionStake,
asEdgeTxActionFiat
)

export const asEdgeAssetActionType: Cleaner<EdgeAssetActionType> = asValue(
'stake',
Expand All @@ -241,7 +271,10 @@ export const asEdgeAssetActionType: Cleaner<EdgeAssetActionType> = asValue(
'swap',
'swapOrderPost',
'swapOrderFill',
'swapOrderCancel'
'swapOrderCancel',
'buy',
'sell',
'sellNetworkFee'
)

export const asEdgeAssetAction = asObject({
Expand Down
33 changes: 32 additions & 1 deletion src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ export interface EdgeAssetAmount {
nativeAmount?: string
}

export interface EdgeFiatAmount {
// core-js style fiat code including 'iso:'
fiatCurrencyCode: string
fiatAmount: string
}

export interface EdgeTxActionSwap {
actionType: 'swap'
orderId?: string
Expand All @@ -273,7 +279,29 @@ export interface EdgeTxActionStake {
stakeAssets: EdgeAssetAmount[]
}

export type EdgeTxAction = EdgeTxActionSwap | EdgeTxActionStake
export interface EdgeTxActionFiat {
actionType: 'fiat'

orderId: string
orderUri?: string
isEstimate: boolean

fiatPlugin: {
providerId: string
providerDisplayName: string
supportEmail?: string
}

payinAddress?: string
payoutAddress?: string
fiatAsset: EdgeFiatAmount
cryptoAsset: EdgeAssetAmount
}

export type EdgeTxAction =
| EdgeTxActionSwap
| EdgeTxActionStake
| EdgeTxActionFiat

export type EdgeAssetActionType =
| 'stake'
Expand All @@ -288,6 +316,9 @@ export type EdgeAssetActionType =
| 'swapOrderPost'
| 'swapOrderFill'
| 'swapOrderCancel'
| 'buy'
| 'sell'
| 'sellNetworkFee'

export interface EdgeAssetAction {
assetActionType: EdgeAssetActionType
Expand Down

0 comments on commit 99108eb

Please sign in to comment.