Skip to content

Commit d29f2ba

Browse files
authored
Add select_coins command (#2892)
* add selectCoins and getSpendableCoins * add to allowedcommands * attempt fix of selectCoins * export hooks * alphabetise
1 parent 84eec72 commit d29f2ba

6 files changed

Lines changed: 137 additions & 0 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ export const {
157157
useGetNextAddressMutation,
158158
useGetCoinRecordsByNamesQuery,
159159
useLazyGetCoinRecordsByNamesQuery,
160+
useSelectCoinsQuery,
161+
useLazySelectCoinsQuery,
162+
useGetSpendableCoinsQuery,
163+
useLazyGetSpendableCoinsQuery,
160164
useRegisterRemoteCoinsMutation,
161165
useFarmBlockMutation,
162166
useGetTimestampForHeightQuery,

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,10 @@ export const walletApi = apiWithTag.injectEndpoints({
546546

547547
getCoinRecordsByNames: query(build, WalletService, 'getCoinRecordsByNames'),
548548

549+
selectCoins: query(build, WalletService, 'selectCoins'),
550+
551+
getSpendableCoins: query(build, WalletService, 'getSpendableCoins'),
552+
549553
registerRemoteCoins: mutation(build, WalletService, 'registerRemoteCoins'),
550554

551555
farmBlock: mutation(build, WalletService, 'farmBlock'),
@@ -1562,6 +1566,10 @@ export const {
15621566
useGetNextAddressMutation,
15631567
useGetCoinRecordsByNamesQuery,
15641568
useLazyGetCoinRecordsByNamesQuery,
1569+
useSelectCoinsQuery,
1570+
useLazySelectCoinsQuery,
1571+
useGetSpendableCoinsQuery,
1572+
useLazyGetSpendableCoinsQuery,
15651573
useRegisterRemoteCoinsMutation,
15661574
useFarmBlockMutation,
15671575
useGetTimestampForHeightQuery,

packages/api/src/services/WalletService.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,31 @@ export default class Wallet extends Service {
5959
}>('get_coin_records_by_names', args);
6060
}
6161

62+
async selectCoins(args: {
63+
walletId: number;
64+
amount: string | number;
65+
minCoinAmount?: string | number;
66+
maxCoinAmount?: string | number;
67+
excludedCoinAmounts?: (string | number)[];
68+
excludedCoinIds?: string[];
69+
}) {
70+
return this.command<{ coins: any[] }>('select_coins', args);
71+
}
72+
73+
async getSpendableCoins(args: {
74+
walletId: number;
75+
minCoinAmount?: string | number;
76+
maxCoinAmount?: string | number;
77+
excludedCoinAmounts?: (string | number)[];
78+
excludedCoinIds?: string[];
79+
}) {
80+
return this.command<{
81+
confirmedRecords: any[];
82+
unconfirmedRemovals: any[];
83+
unconfirmedAdditions: any[];
84+
}>('get_spendable_coins', args);
85+
}
86+
6287
async registerRemoteCoins(args: { walletId: number; coinIds: string[] }) {
6388
return this.command<void>('register_remote_coins', args);
6489
}

packages/gui/src/@types/WalletConnectCommandParamName.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ enum WalletConnectCommandParamName {
2222
EDITION_TOTAL = 'editionTotal',
2323
END = 'end',
2424
END_HEIGHT = 'endHeight',
25+
EXCLUDED_COIN_AMOUNTS = 'excludedCoinAmounts',
26+
EXCLUDED_COIN_IDS = 'excludedCoinIds',
2527
EXTRA_CONDITIONS = 'extraConditions',
2628
FEE = 'fee',
2729
FINGERPRINT = 'fingerprint',
@@ -44,12 +46,14 @@ enum WalletConnectCommandParamName {
4446
LICENSE_HASH = 'licenseHash',
4547
LICENSE_URIS = 'licenseUris',
4648
MAKER = 'maker',
49+
MAX_COIN_AMOUNT = 'maxCoinAmount',
4750
MEMOS = 'memos',
4851
MESSAGE = 'message',
4952
META_HASH = 'metaHash',
5053
META_URIS = 'metaUris',
5154
METADATA = 'metadata',
5255
METADATA_LIST = 'metadataList',
56+
MIN_COIN_AMOUNT = 'minCoinAmount',
5357
MINT_FROM_DID = 'mintFromDid',
5458
MINT_NUMBER_START = 'mintNumberStart',
5559
MINT_TOTAL = 'mintTotal',

packages/gui/src/constants/WalletConnectCommands.tsx

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,100 @@ const walletConnectCommands: WalletConnectCommand[] = [
153153
},
154154
],
155155
},
156+
{
157+
command: 'selectCoins',
158+
label: <Trans>Select Coins</Trans>,
159+
description: <Trans>Selects coins to be spent from a specific wallet</Trans>,
160+
service: ServiceName.WALLET,
161+
bypassConfirm: true,
162+
waitForSync: true,
163+
params: [
164+
{
165+
name: WalletConnectCommandParamName.WALLET_ID,
166+
type: 'number',
167+
label: <Trans>Wallet Id</Trans>,
168+
defaultValue: 1,
169+
},
170+
{
171+
name: WalletConnectCommandParamName.AMOUNT,
172+
type: 'BigNumber',
173+
label: <Trans>Amount</Trans>,
174+
displayComponent: (value) => <MojoToChia value={value} />,
175+
},
176+
{
177+
name: WalletConnectCommandParamName.MIN_COIN_AMOUNT,
178+
type: 'BigNumber',
179+
label: <Trans>Min Coin Amount</Trans>,
180+
isOptional: true,
181+
displayComponent: (value) => <MojoToChia value={value} />,
182+
},
183+
{
184+
name: WalletConnectCommandParamName.MAX_COIN_AMOUNT,
185+
type: 'BigNumber',
186+
label: <Trans>Max Coin Amount</Trans>,
187+
isOptional: true,
188+
displayComponent: (value) => <MojoToChia value={value} />,
189+
},
190+
{
191+
name: WalletConnectCommandParamName.EXCLUDED_COIN_AMOUNTS,
192+
type: 'object',
193+
label: <Trans>Excluded Coin Amounts</Trans>,
194+
isOptional: true,
195+
displayComponent: (value) => <>{JSON.stringify(value)}</>,
196+
},
197+
{
198+
name: WalletConnectCommandParamName.EXCLUDED_COIN_IDS,
199+
type: 'object',
200+
label: <Trans>Excluded Coin IDs</Trans>,
201+
isOptional: true,
202+
displayComponent: (value) => <>{JSON.stringify(value)}</>,
203+
},
204+
],
205+
},
206+
{
207+
command: 'getSpendableCoins',
208+
label: <Trans>Get Spendable Coins</Trans>,
209+
description: <Trans>Requests spendable coins for a specific wallet</Trans>,
210+
service: ServiceName.WALLET,
211+
bypassConfirm: true,
212+
waitForSync: true,
213+
params: [
214+
{
215+
name: WalletConnectCommandParamName.WALLET_ID,
216+
type: 'number',
217+
label: <Trans>Wallet Id</Trans>,
218+
defaultValue: 1,
219+
},
220+
{
221+
name: WalletConnectCommandParamName.MIN_COIN_AMOUNT,
222+
type: 'BigNumber',
223+
label: <Trans>Min Coin Amount</Trans>,
224+
isOptional: true,
225+
displayComponent: (value) => <MojoToChia value={value} />,
226+
},
227+
{
228+
name: WalletConnectCommandParamName.MAX_COIN_AMOUNT,
229+
type: 'BigNumber',
230+
label: <Trans>Max Coin Amount</Trans>,
231+
isOptional: true,
232+
displayComponent: (value) => <MojoToChia value={value} />,
233+
},
234+
{
235+
name: WalletConnectCommandParamName.EXCLUDED_COIN_AMOUNTS,
236+
type: 'object',
237+
label: <Trans>Excluded Coin Amounts</Trans>,
238+
isOptional: true,
239+
displayComponent: (value) => <>{JSON.stringify(value)}</>,
240+
},
241+
{
242+
name: WalletConnectCommandParamName.EXCLUDED_COIN_IDS,
243+
type: 'object',
244+
label: <Trans>Excluded Coin IDs</Trans>,
245+
isOptional: true,
246+
displayComponent: (value) => <>{JSON.stringify(value)}</>,
247+
},
248+
],
249+
},
156250
{
157251
command: 'sendTransaction',
158252
label: <Trans>Send Transaction</Trans>,

packages/gui/src/electron/constants/AllowedCommands.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export default [
3232
'chia_wallet.get_sync_status',
3333
'chia_wallet.get_wallets',
3434
'chia_wallet.get_coin_records_by_names',
35+
'chia_wallet.select_coins',
36+
'chia_wallet.get_spendable_coins',
3537
'chia_wallet.nft_get_wallet_did',
3638
'chia_wallet.cat_get_asset_id',
3739
'chia_wallet.cat_get_name',

0 commit comments

Comments
 (0)