Skip to content

Commit

Permalink
Merge pull request #323 from EdgeApp/matthew/memoTypes
Browse files Browse the repository at this point in the history
Add special memo types for Ripple and Stellar
  • Loading branch information
peachbits authored Apr 19, 2024
2 parents 4a4e16d + c52bb68 commit 5a60800
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- added: Special case Ripple and Stellar memo types

## 2.4.0 (2024-04-05)

- added: Login info to testconfig for testpartners.ts
Expand Down
9 changes: 7 additions & 2 deletions src/swap/central/changehero.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
makeSwapPluginQuote,
SwapOrder
} from '../../util/swapHelpers'
import { convertRequest, getAddress } from '../../util/utils'
import { convertRequest, getAddress, memoType } from '../../util/utils'
import { EdgeSwapRequestPlugin, StringMap } from '../types'

const pluginId = 'changehero'
Expand Down Expand Up @@ -323,7 +323,12 @@ export function makeChangeHeroPlugin(
const memos: EdgeMemo[] =
quoteInfo.payinExtraId == null
? []
: [{ type: 'text', value: quoteInfo.payinExtraId }]
: [
{
type: memoType(request.fromWallet.currencyInfo.pluginId),
value: quoteInfo.payinExtraId
}
]

const spendInfo: EdgeSpendInfo = {
tokenId: request.fromTokenId,
Expand Down
20 changes: 17 additions & 3 deletions src/swap/central/changenow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
makeSwapPluginQuote,
SwapOrder
} from '../../util/swapHelpers'
import { convertRequest, getAddress } from '../../util/utils'
import { convertRequest, getAddress, memoType } from '../../util/utils'
import { EdgeSwapRequestPlugin } from '../types'
const pluginId = 'changenow'

Expand Down Expand Up @@ -272,7 +272,14 @@ export function makeChangeNowPlugin(
)

const memos: EdgeMemo[] =
payinExtraId == null ? [] : [{ type: 'text', value: payinExtraId }]
payinExtraId == null
? []
: [
{
type: memoType(request.fromWallet.currencyInfo.pluginId),
value: payinExtraId
}
]

const spendInfo: EdgeSpendInfo = {
tokenId: request.fromTokenId,
Expand Down Expand Up @@ -342,7 +349,14 @@ export function makeChangeNowPlugin(
)

const memos: EdgeMemo[] =
payinExtraId == null ? [] : [{ type: 'text', value: payinExtraId }]
payinExtraId == null
? []
: [
{
type: memoType(request.fromWallet.currencyInfo.pluginId),
value: payinExtraId
}
]

const spendInfo: EdgeSpendInfo = {
tokenId: request.fromTokenId,
Expand Down
9 changes: 7 additions & 2 deletions src/swap/central/exolix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
makeSwapPluginQuote,
SwapOrder
} from '../../util/swapHelpers'
import { convertRequest, getAddress } from '../../util/utils'
import { convertRequest, getAddress, memoType } from '../../util/utils'
import { EdgeSwapRequestPlugin } from '../types'

const pluginId = 'exolix'
Expand Down Expand Up @@ -291,7 +291,12 @@ export function makeExolixPlugin(opts: EdgeCorePluginOptions): EdgeSwapPlugin {
const memos: EdgeMemo[] =
quoteInfo.depositExtraId == null
? []
: [{ type: 'text', value: quoteInfo.depositExtraId }]
: [
{
type: memoType(request.fromWallet.currencyInfo.pluginId),
value: quoteInfo.depositExtraId
}
]

const spendInfo: EdgeSpendInfo = {
tokenId: request.fromTokenId,
Expand Down
9 changes: 7 additions & 2 deletions src/swap/central/godex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
makeSwapPluginQuote,
SwapOrder
} from '../../util/swapHelpers'
import { convertRequest, getAddress } from '../../util/utils'
import { convertRequest, getAddress, memoType } from '../../util/utils'
import { asNumberString, EdgeSwapRequestPlugin } from '../types'

const pluginId = 'godex'
Expand Down Expand Up @@ -307,7 +307,12 @@ export function makeGodexPlugin(opts: EdgeCorePluginOptions): EdgeSwapPlugin {
const memos: EdgeMemo[] =
quoteInfo.deposit_extra_id == null
? []
: [{ type: 'text', value: quoteInfo.deposit_extra_id }]
: [
{
type: memoType(request.fromWallet.currencyInfo.pluginId),
value: quoteInfo.deposit_extra_id
}
]

// Make the transaction:
const spendInfo: EdgeSpendInfo = {
Expand Down
9 changes: 7 additions & 2 deletions src/swap/central/letsexchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
makeSwapPluginQuote,
SwapOrder
} from '../../util/swapHelpers'
import { convertRequest, getAddress } from '../../util/utils'
import { convertRequest, getAddress, memoType } from '../../util/utils'
import { asNumberString, EdgeSwapRequestPlugin } from '../types'
import { asOptionalBlank } from './changenow'

Expand Down Expand Up @@ -318,7 +318,12 @@ export function makeLetsExchangePlugin(
const memos: EdgeMemo[] =
quoteInfo.deposit_extra_id == null
? []
: [{ type: 'text', value: quoteInfo.deposit_extra_id }]
: [
{
type: memoType(request.fromWallet.currencyInfo.pluginId),
value: quoteInfo.deposit_extra_id
}
]

// Make the transaction:
const spendInfo: EdgeSpendInfo = {
Expand Down
9 changes: 7 additions & 2 deletions src/swap/central/sideshift.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
makeSwapPluginQuote,
SwapOrder
} from '../../util/swapHelpers'
import { convertRequest, getAddress } from '../../util/utils'
import { convertRequest, getAddress, memoType } from '../../util/utils'
import { EdgeSwapRequestPlugin } from '../types'

// See https://help.sideshift.ai/en/articles/4559664-which-coins-and-tokens-are-listed for list of supported currencies
Expand Down Expand Up @@ -279,7 +279,12 @@ const fetchSwapQuoteInner = async (
const memos: EdgeMemo[] =
order.depositMemo == null
? []
: [{ type: 'text', value: order.depositMemo }]
: [
{
type: memoType(request.fromWallet.currencyInfo.pluginId),
value: order.depositMemo
}
]

const spendInfo: EdgeSpendInfo = {
tokenId: request.fromTokenId,
Expand Down
11 changes: 9 additions & 2 deletions src/swap/central/swapuz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
makeSwapPluginQuote,
SwapOrder
} from '../../util/swapHelpers'
import { convertRequest, getAddress } from '../../util/utils'
import { convertRequest, getAddress, memoType } from '../../util/utils'
import { EdgeSwapRequestPlugin } from '../types'

const pluginId = 'swapuz'
Expand Down Expand Up @@ -255,7 +255,14 @@ export function makeSwapuzPlugin(opts: EdgeCorePluginOptions): EdgeSwapPlugin {
)

const memos: EdgeMemo[] =
memoFrom == null ? [] : [{ type: 'text', value: memoFrom }]
memoFrom == null
? []
: [
{
type: memoType(request.fromWallet.currencyInfo.pluginId),
value: memoFrom
}
]

const spendInfo: EdgeSpendInfo = {
tokenId: request.fromTokenId,
Expand Down
9 changes: 9 additions & 0 deletions src/util/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
EdgeCurrencyWallet,
EdgeFetchFunction,
EdgeFetchResponse,
EdgeMemoOption,
EdgeSwapRequest
} from 'edge-core-js'

Expand Down Expand Up @@ -192,3 +193,11 @@ export const hexToDecimal = (hex: string): string => {
return add(`0x${hex}`, '0')
}
}

const pluginIdMemoTypes: { [pluginId: string]: EdgeMemoOption['type'] } = {
ripple: 'number',
stellar: 'number'
}
export const memoType = (pluginId: string): EdgeMemoOption['type'] => {
return pluginIdMemoTypes[pluginId] ?? 'text'
}

0 comments on commit 5a60800

Please sign in to comment.