Skip to content

Commit 1d95322

Browse files
authored
add support for RCAT (#2697)
* add support for RCAT * removed unused variable * show revocable in WalletConnect spendCAT
1 parent e4124c8 commit 1d95322

31 files changed

Lines changed: 240 additions & 81 deletions

packages/api-react/src/services/wallet.ts

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -75,58 +75,60 @@ export const walletApi = apiWithTag.injectEndpoints({
7575
throw new Error('List of the wallets is not defined');
7676
}
7777

78-
return {
79-
data: await Promise.all(
80-
wallets.map(async (wallet: Wallet) => {
81-
const { type } = wallet;
82-
const meta: any = {};
83-
if ([WalletType.CAT, WalletType.CRCAT].includes(type)) {
84-
// get CAT asset
85-
const { data: assetData, error: assetError } = await fetchWithBQ({
86-
command: 'getAssetId',
87-
service: CAT,
88-
args: { walletId: wallet.id },
89-
});
78+
const allWallets = await Promise.all(
79+
wallets.map(async (wallet: Wallet) => {
80+
const { type } = wallet;
81+
const meta: any = {};
82+
if ([WalletType.CAT, WalletType.RCAT, WalletType.CRCAT].includes(type)) {
83+
// get CAT asset
84+
const { data: assetData, error: assetError } = await fetchWithBQ({
85+
command: 'getAssetId',
86+
service: CAT,
87+
args: { walletId: wallet.id },
88+
});
9089

91-
if (assetError) {
92-
throw assetError as Error;
93-
}
90+
if (assetError) {
91+
throw assetError as Error;
92+
}
9493

95-
meta.assetId = assetData.assetId;
94+
meta.assetId = assetData.assetId;
9695

97-
// get CAT name
98-
const { data: nameData, error: nameError } = await fetchWithBQ({
99-
command: 'getName',
100-
service: CAT,
101-
args: { walletId: wallet.id },
102-
});
103-
104-
if (nameError) {
105-
throw nameError as Error;
106-
}
96+
// get CAT name
97+
const { data: nameData, error: nameError } = await fetchWithBQ({
98+
command: 'getName',
99+
service: CAT,
100+
args: { walletId: wallet.id },
101+
});
107102

108-
meta.name = nameData.name;
109-
} else if (type === WalletType.NFT) {
110-
// get DID assigned to the NFT Wallet (if any)
111-
const { data: didData, error: didError } = await fetchWithBQ({
112-
command: 'getNftWalletDid',
113-
service: NFT,
114-
args: { walletId: wallet.id },
115-
});
103+
if (nameError) {
104+
throw nameError as Error;
105+
}
116106

117-
if (didError) {
118-
throw didError as Error;
119-
}
107+
meta.name = nameData.name;
108+
} else if (type === WalletType.NFT) {
109+
// get DID assigned to the NFT Wallet (if any)
110+
const { data: didData, error: didError } = await fetchWithBQ({
111+
command: 'getNftWalletDid',
112+
service: NFT,
113+
args: { walletId: wallet.id },
114+
});
120115

121-
meta.did = didData.didId;
116+
if (didError) {
117+
throw didError as Error;
122118
}
123119

124-
return {
125-
...wallet,
126-
meta,
127-
};
128-
}),
129-
),
120+
meta.did = didData.didId;
121+
}
122+
123+
return {
124+
...wallet,
125+
meta,
126+
};
127+
}),
128+
);
129+
130+
return {
131+
data: allWallets,
130132
};
131133
} catch (error) {
132134
return {

packages/api/src/constants/WalletType.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ enum WalletType {
1212
NFT = 10,
1313
DATA_LAYER = 11,
1414
CRCAT = 57,
15+
RCAT = 132,
1516
}
1617

1718
export default WalletType;

packages/gui/src/components/offers/NFTOfferEditor.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ function NFTOfferConditionalsPanel(props: NFTOfferConditionalsPanelProps) {
142142
balance = mojoToChia(walletBalance.spendableBalance);
143143
break;
144144
case WalletType.CAT:
145+
case WalletType.RCAT:
145146
balanceString = mojoToCATLocaleString(walletBalance.spendableBalance, locale);
146147
balance = mojoToCAT(walletBalance.spendableBalance);
147148
break;

packages/gui/src/components/offers/NFTOfferTokenSelector.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default function NFTOfferTokenSelector(props: Props) {
5656
}),
5757
);
5858
const catOptions = wallets
59-
.filter((wallet: Wallet) => [WalletType.CAT, WalletType.CRCAT].includes(wallet.type))
59+
.filter((wallet: Wallet) => [WalletType.CAT, WalletType.RCAT, WalletType.CRCAT].includes(wallet.type))
6060
.map((wallet: Wallet) => {
6161
const cat: CATToken | undefined = catList.find(
6262
(catItem: CATToken) => catItem.assetId.toLowerCase() === wallet.tail?.toLowerCase(),

packages/gui/src/components/offers/OfferAssetSelector.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function buildAssetSelectorList(params: BuildAssetSelectorListParams): WalletOff
6666
if (wallet.type === WalletType.STANDARD_WALLET) {
6767
name = 'Chia';
6868
symbol = chiaCurrencyCode;
69-
} else if ([WalletType.CAT, WalletType.CRCAT].includes(wallet.type)) {
69+
} else if ([WalletType.CAT, WalletType.RCAT, WalletType.CRCAT].includes(wallet.type)) {
7070
name = wallet.name;
7171
tail = wallet.meta.assetId;
7272
const cat = catList.find((catItem) => catItem.assetId.toLowerCase() === tail?.toLowerCase());

packages/gui/src/components/offers/OfferEditor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ function getUpdatedOffer(offerParam: { [key: string]: BigNumber }, row: OfferEdi
197197
let mojoAmount = new BigNumber(0);
198198
if (walletTypeLocal === WalletType.STANDARD_WALLET) {
199199
mojoAmount = chiaToMojo(amount);
200-
} else if ([WalletType.CAT, WalletType.CRCAT].includes(walletTypeLocal)) {
200+
} else if ([WalletType.CAT, WalletType.RCAT, WalletType.CRCAT].includes(walletTypeLocal)) {
201201
mojoAmount = catToMojo(amount);
202202
}
203203

packages/gui/src/components/offers/OfferEditorConditionsPanel.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ function OfferEditorConditionRow(props: OfferEditorConditionsRowProps) {
6666
balance = mojoToChia(walletBalance.spendableBalance);
6767
break;
6868
case WalletType.CAT:
69+
case WalletType.RCAT:
6970
balanceString = mojoToCATLocaleString(walletBalance.spendableBalance, locale);
7071
balance = mojoToCAT(walletBalance.spendableBalance);
7172
break;

packages/gui/src/components/offers/OfferSummaryRow.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ export function OfferSummaryTokenRow(props: OfferSummaryTokenRowProps): React.Re
175175
<Box flexGrow={1}>
176176
<StyledTitle>Name</StyledTitle>
177177
</Box>
178-
{(!assetIdInfo || [WalletType.CAT, WalletType.CRCAT].includes(assetIdInfo?.walletType)) && (
178+
{(!assetIdInfo ||
179+
[WalletType.CAT, WalletType.RCAT, WalletType.CRCAT].includes(assetIdInfo?.walletType)) && (
179180
<Link href={`https://www.taildatabase.com/tail/${assetId.toLowerCase()}`} target="_blank">
180181
<Trans>Search on Tail Database</Trans>
181182
</Link>
@@ -184,7 +185,7 @@ export function OfferSummaryTokenRow(props: OfferSummaryTokenRowProps): React.Re
184185

185186
<StyledValue>{tooltipDisplayName}</StyledValue>
186187
</Flex>
187-
{(!assetIdInfo || [WalletType.CAT, WalletType.CRCAT].includes(assetIdInfo?.walletType)) && (
188+
{(!assetIdInfo || [WalletType.CAT, WalletType.RCAT, WalletType.CRCAT].includes(assetIdInfo?.walletType)) && (
188189
<Flex flexDirection="column" gap={0}>
189190
<StyledTitle>Asset ID</StyledTitle>
190191
<Flex alignItems="center" gap={1}>

packages/gui/src/components/offers/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export function formatAmountForWalletType(amount: string | number, walletType: W
152152
if (walletType === WalletType.STANDARD_WALLET) {
153153
return mojoToChiaLocaleString(amount, locale);
154154
}
155-
if ([WalletType.CAT, WalletType.CRCAT].includes(walletType)) {
155+
if ([WalletType.CAT, WalletType.RCAT, WalletType.CRCAT].includes(walletType)) {
156156
return mojoToCATLocaleString(amount, locale);
157157
}
158158

packages/gui/src/components/offers2/OfferBuilderTokenSelector.tsx

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { WalletType } from '@chia-network/api';
22
import type { CATToken, Wallet } from '@chia-network/api';
33
import { useGetCatListQuery, useGetWalletsQuery } from '@chia-network/api-react';
4+
import { Flex, TooltipIcon } from '@chia-network/core';
45
import { Trans, t } from '@lingui/macro';
5-
import { FormControl, InputLabel, MenuItem, Select, Typography } from '@mui/material';
6+
import { Chip, FormControl, InputLabel, MenuItem, Select, Typography } from '@mui/material';
67
import { orderBy } from 'lodash';
78
import React, { useMemo } from 'react';
89
import { useFormContext, useWatch } from 'react-hook-form';
@@ -30,7 +31,7 @@ export default function OfferBuilderTokenSelector(props: OfferBuilderTokenSelect
3031
}
3132

3233
const allOptions = wallets
33-
.filter((wallet: Wallet) => [WalletType.CAT, WalletType.CRCAT].includes(wallet.type))
34+
.filter((wallet: Wallet) => [WalletType.CAT, WalletType.RCAT, WalletType.CRCAT].includes(wallet.type))
3435
.map((wallet: Wallet) => {
3536
const assetId = wallet.meta?.assetId ? wallet.meta.assetId.toLowerCase() : '';
3637

@@ -45,6 +46,7 @@ export default function OfferBuilderTokenSelector(props: OfferBuilderTokenSelect
4546
return {
4647
assetId,
4748
displayName: wallet.name + (cat?.symbol ? ` (${cat.symbol})` : ''),
49+
walletType: wallet.type,
4850
};
4951
})
5052
.filter(Boolean);
@@ -64,6 +66,23 @@ export default function OfferBuilderTokenSelector(props: OfferBuilderTokenSelect
6466
return (
6567
<Typography variant="h6" noWrap>
6668
{warnUnknownCAT ? t`Unknown` : (selectedOption?.displayName ?? currentValue)}
69+
{selectedOption?.walletType === WalletType.RCAT && (
70+
<>
71+
&nbsp;
72+
<Chip
73+
label={
74+
<Flex alignItems="center" gap={1}>
75+
<Trans>Revocable</Trans>
76+
<TooltipIcon>
77+
<Trans>This token can be revoked by the issuer</Trans>
78+
</TooltipIcon>
79+
</Flex>
80+
}
81+
variant="outlined"
82+
size="small"
83+
/>
84+
</>
85+
)}
6786
</Typography>
6887
);
6988
}
@@ -82,6 +101,23 @@ export default function OfferBuilderTokenSelector(props: OfferBuilderTokenSelect
82101
options.map((option) => (
83102
<MenuItem value={option.assetId} key={option.assetId} onClick={() => handleSelection(option)}>
84103
{option.displayName}
104+
{option.walletType === WalletType.RCAT && (
105+
<>
106+
&nbsp;
107+
<Chip
108+
label={
109+
<Flex alignItems="center" gap={1}>
110+
<Trans>Revocable</Trans>
111+
<TooltipIcon>
112+
<Trans>This token can be revoked by the issuer</Trans>
113+
</TooltipIcon>
114+
</Flex>
115+
}
116+
variant="outlined"
117+
size="small"
118+
/>
119+
</>
120+
)}
85121
</MenuItem>
86122
))
87123
)}

0 commit comments

Comments
 (0)