Skip to content

Commit 4d38331

Browse files
committed
add amm_clawback
1 parent 2117636 commit 4d38331

File tree

13 files changed

+955
-4
lines changed

13 files changed

+955
-4
lines changed

public/locales/en-US/translations.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@
156156
"transaction_type_name_AMMWithdraw": "AMM Withdraw",
157157
"transaction_type_name_AMMVote": "AMM Vote",
158158
"transaction_type_name_AMMBid": "AMM Bid",
159+
"transaction_type_name_AMMClawback": "AMMClawback",
159160
"transaction_type_name_AccountSet": "Account Set",
160161
"transaction_type_name_CheckCancel": "Check Cancel",
161162
"transaction_type_name_CheckCash": "Check Cash",
@@ -490,6 +491,7 @@
490491
"min_signer_quorum": "Minimum weight <0>{{quorum}}</0> required",
491492
"holder": "Holder",
492493
"action_from": "<0><0>{{action}}</0></0> <1><0>{{amount}}</0></1> from <3><0>{{destination}}</0></3>",
494+
"action_from_and": "<0><0>{{action}}</0></0> <1><0>{{amount1}}</0></1> and <3><0>{{amount2}}</0></3> from <5><0>{{destination}}</0></5>",
493495
"claws_back": "Claws back",
494496
"claws_back_from": "<source/> claws back from <destination/>",
495497
"instruct_to_claw": "The max clawback amount is <amount/>",
@@ -561,5 +563,4 @@
561563
"enable_amendment_name": "Amendment Name",
562564
"amendment_status": "Amendment Status",
563565
"expected_date": "Expected Date"
564-
565566
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { useTranslation } from 'react-i18next'
2+
import { TransactionSimpleProps } from '../types'
3+
import { SimpleRow } from '../SimpleRow'
4+
import { Account } from '../../Account'
5+
import { Amount } from '../../Amount'
6+
7+
export const Simple = ({ data }: TransactionSimpleProps) => {
8+
const { t } = useTranslation()
9+
const { amount2, amount, holder } = data.instructions
10+
return (
11+
<>
12+
{holder && (
13+
<SimpleRow label={t('holder')} data-test="holder">
14+
<Account account={holder} />
15+
</SimpleRow>
16+
)}
17+
{amount && (
18+
<SimpleRow label={t('asset1')} data-test="asset1">
19+
<Amount value={amount} displayIssuer />
20+
</SimpleRow>
21+
)}
22+
{amount2 && (
23+
<SimpleRow label={t('asset2')} data-test="asset2">
24+
<Amount value={amount2} displayIssuer />
25+
</SimpleRow>
26+
)}
27+
</>
28+
)
29+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Trans, useTranslation } from 'react-i18next'
2+
import { Amount } from '../../Amount'
3+
import { Account } from '../../Account'
4+
import { TransactionTableDetailProps } from '../types'
5+
6+
export const TableDetail = ({ instructions }: TransactionTableDetailProps) => {
7+
const { t } = useTranslation()
8+
const { amount2, amount, holder } = instructions
9+
if (amount2) {
10+
return (
11+
<div className="ammClawback">
12+
<Trans i18nKey="action_from_and">
13+
<span className="label">{t('claws_back')}</span>
14+
<Amount value={amount} displayIssuer />
15+
and
16+
<Amount value={amount2} displayIssuer />
17+
from
18+
<Account account={holder} />
19+
</Trans>
20+
</div>
21+
)
22+
}
23+
return (
24+
<div className="ammClawback">
25+
<Trans i18nKey="action_from">
26+
<span className="label">{t('claws_back')}</span>
27+
<Amount value={amount} displayIssuer />
28+
from
29+
<Account account={holder} />
30+
</Trans>
31+
</div>
32+
)
33+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Simple } from './Simple'
2+
import {
3+
TransactionAction,
4+
TransactionCategory,
5+
TransactionMapping,
6+
} from '../types'
7+
import { parser } from './parser'
8+
import { TableDetail } from './TableDetail'
9+
10+
export const AMMClawback: TransactionMapping = {
11+
TableDetail,
12+
Simple,
13+
action: TransactionAction.CANCEL,
14+
category: TransactionCategory.DEX,
15+
parser,
16+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { findAssetAmount } from '../../../metaParser'
2+
import { AMMClawback } from './types'
3+
4+
export function parser(tx: AMMClawback, meta: any) {
5+
const account = tx.Account
6+
const holder = tx.Holder
7+
const amount = findAssetAmount(meta, tx.Asset, tx)
8+
if (tx.Flags) {
9+
const amount2 = findAssetAmount(meta, tx.Asset2, tx)
10+
return {
11+
amount,
12+
account,
13+
amount2,
14+
holder,
15+
}
16+
}
17+
return {
18+
amount,
19+
account,
20+
holder,
21+
}
22+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { expectSimpleRowNotToExist, expectSimpleRowText } from '../../test'
2+
3+
import { createSimpleWrapperFactory } from '../../test/createWrapperFactory'
4+
import { Simple } from '../Simple'
5+
import mockAMMClawbackNoFlag from './mock_data/withoutFlag.json'
6+
import mockAMMClawbackWithAmount from './mock_data/withAmount.json'
7+
import mockAMMClawbackWithFlag from './mock_data/withFlag.json'
8+
9+
const createWrapper = createSimpleWrapperFactory(Simple)
10+
11+
describe('AMMClawback: Simple', () => {
12+
it('renders without tfClawTwoAssets flag, only one asset should be clawed back', () => {
13+
const wrapper = createWrapper(mockAMMClawbackNoFlag)
14+
expectSimpleRowText(
15+
wrapper,
16+
'asset1',
17+
'$260.00 USD.rGGjMesMUrRMP8ZkLZ2cZ5agzmFwBfT4f2',
18+
)
19+
expectSimpleRowNotToExist(wrapper, 'asset2')
20+
expectSimpleRowText(wrapper, 'holder', 'rJk5n4egp7Th4Y4vxAMVAbf1ziuiFuVKiw')
21+
wrapper.unmount()
22+
})
23+
24+
it('renders with tfClawTwoAssets flag, both asset should be clawed back', () => {
25+
const wrapper = createWrapper(mockAMMClawbackWithFlag)
26+
expectSimpleRowText(
27+
wrapper,
28+
'asset1',
29+
'$260.00 USD.rUuVtbgagFKjHPTxmN639XYVHLATnB6VNk',
30+
)
31+
expectSimpleRowText(
32+
wrapper,
33+
'asset2',
34+
'100.00 YEN.rUuVtbgagFKjHPTxmN639XYVHLATnB6VNk',
35+
)
36+
expectSimpleRowText(wrapper, 'holder', 'r4eWC5DixP74dpk7FDzXcap1BJ2NaoUeZN')
37+
wrapper.unmount()
38+
})
39+
40+
it('renders with Amount set', () => {
41+
const wrapper = createWrapper(mockAMMClawbackWithAmount)
42+
expectSimpleRowText(
43+
wrapper,
44+
'asset1',
45+
'$20.00 USD.rK2Du3gUmFbg5UFFHFq9LKywVuGbqNsyyi',
46+
)
47+
wrapper.unmount()
48+
})
49+
})
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { createTableDetailWrapperFactory } from '../../test'
2+
import { TableDetail } from '../TableDetail'
3+
import AMMClawbackNoFlag from './mock_data/withoutFlag.json'
4+
import AMMClawbackWithFlag from './mock_data/withFlag.json'
5+
import mockAMMClawbackWithAmount from './mock_data/withAmount.json'
6+
7+
const createWrapper = createTableDetailWrapperFactory(TableDetail)
8+
9+
describe('AMMClawback: TableDetail', () => {
10+
it('renders without tfClawTwoAssets flag, only one asset should be clawed back', () => {
11+
const wrapper = createWrapper(AMMClawbackNoFlag)
12+
expect(wrapper).toHaveText(
13+
'claws_back' +
14+
'$260.00 USD.rGGjMesMUrRMP8ZkLZ2cZ5agzmFwBfT4f2' +
15+
'from' +
16+
'rJk5n4egp7Th4Y4vxAMVAbf1ziuiFuVKiw',
17+
)
18+
wrapper.unmount()
19+
})
20+
21+
it('renders without tfClawTwoAssets flag, both assets should be clawed back', () => {
22+
const wrapper = createWrapper(AMMClawbackWithFlag)
23+
expect(wrapper).toHaveText(
24+
'claws_back' +
25+
'$260.00 USD.rUuVtbgagFKjHPTxmN639XYVHLATnB6VNk' +
26+
'and' +
27+
'100.00 YEN.rUuVtbgagFKjHPTxmN639XYVHLATnB6VNk' +
28+
'from' +
29+
'r4eWC5DixP74dpk7FDzXcap1BJ2NaoUeZN',
30+
)
31+
wrapper.unmount()
32+
})
33+
34+
it('renders with Amount set', () => {
35+
const wrapper = createWrapper(mockAMMClawbackWithAmount)
36+
expect(wrapper).toHaveText(
37+
'claws_back' +
38+
'$20.00 USD.rK2Du3gUmFbg5UFFHFq9LKywVuGbqNsyyi' +
39+
'from' +
40+
'rJbLyxGA3jvwrFmiouADLHMKaBQn46SVZi',
41+
)
42+
wrapper.unmount()
43+
})
44+
})

0 commit comments

Comments
 (0)