Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rifeljm/#1699 verifiable credentials #1820

Merged
merged 15 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/api-react/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ export { default as useNFTCoinAdded } from './useNFTCoinAdded';
export { default as useNFTCoinRemoved } from './useNFTCoinRemoved';
export { default as useNFTCoinUpdated } from './useNFTCoinUpdated';
export { default as useNFTCoinDIDSet } from './useNFTCoinDIDSet';
export { useVCCoinAdded, useVCCoinRemoved } from './useVCEvents';
11 changes: 11 additions & 0 deletions packages/api-react/src/hooks/useVCEvents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { VC } from '@chia-network/api';

import useSubscribeToEvent from './useSubscribeToEvent';

export function useVCCoinAdded(callback: (coin: any) => void) {
return useSubscribeToEvent('onVCCoinAdded', VC, callback);
}

export function useVCCoinRemoved(callback: (coin: any) => void) {
return useSubscribeToEvent('onVCCoinRemoved', VC, callback);
}
15 changes: 14 additions & 1 deletion packages/api-react/src/services/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,20 @@ export const walletApi = apiWithTag.injectEndpoints({
transformResponse: (response) => response.vcRecord,
}),

getVCList: query(build, VC, 'getVCList'),
getVCList: query(build, VC, 'getVCList', {
onCacheEntryAdded: onCacheEntryAddedInvalidate(baseQuery, api, [
{
command: 'onVCCoinAdded',
service: VC,
endpoint: 'getVCList',
},
{
command: 'onVCCoinRemoved',
service: VC,
endpoint: 'getVCList',
},
]),
}),

spendVC: mutation(build, VC, 'spendVC'),

Expand Down
26 changes: 26 additions & 0 deletions packages/api/src/services/WalletService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,32 @@ export default class Wallet extends Service {
return this.onStateChanged('nft_coin_updated', callback);
}

onVCCoinAdded(
callback: (
data: {
additionalData: Object;
state: 'vc_coin_added';
walletId: number;
},
message: Message
) => void
) {
return this.onStateChanged('vc_coin_added', callback);
}

onVCCoinRemoved(
callback: (
data: {
additionalData: Object;
state: 'vc_coin_removed';
walletId: number;
},
message: Message
) => void
) {
return this.onStateChanged('vc_coin_removed', callback);
}

onNewDerivationIndex(
callback: (
data: {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/wallets/VC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export default class VCWallet extends Wallet {
return this.command<{ proofs: any }>('vc_get_proofs_for_root', { root });
}

async revokeVC(args: { vcParentId: string; fee: number; reusePuzhash: boolean }) {
async revokeVC(args: { vcParentId: string; fee?: number; reusePuzhash?: boolean }) {
return this.command<{
transactions: TransactionType[];
}>('vc_revoke', args);
Expand Down
8 changes: 8 additions & 0 deletions packages/gui/src/@types/WalletConnectCommandParamName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ enum WalletConnectCommandParamName {
META_URIS = 'metaUris',
NAME = 'name',
NEW_ADDRESS = 'newAddress',
NEW_PROOF_HASH = 'newProofHash',
NEW_PUZHASH = 'newPuzhash',
NFT_COIN_ID = 'nftCoinId',
NFT_COIN_IDS = 'nftCoinIds',
NFT_LAUNCHER_ID = 'nftLauncherId',
Expand All @@ -36,8 +38,12 @@ enum WalletConnectCommandParamName {
OFFER = 'offer',
OFFER_DATA = 'offerData',
OFFER_ID = 'offerId',
PROOFS = 'proofs',
PROVIDER_INNER_PUZHASH = 'providerInnerPuzhash',
PUBKEY = 'pubkey',
REVERSE = 'reverse',
REUSE_PUZHASH = 'reusePuzhash',
ROOT = 'root',
ROYALTY_ADDRESS = 'royaltyAddress',
ROYALTY_PERCENTAGE = 'royaltyPercentage',
SECURE = 'secure',
Expand All @@ -53,6 +59,8 @@ enum WalletConnectCommandParamName {
URIS = 'uris',
URL = 'url',
VALIDATE_ONLY = 'validateOnly',
VC_ID = 'vcId',
VC_PARENT_ID = 'vcParentId',
WAIT_FOR_CONFIRMATION = 'waitForConfirmation',
WALLET_ID = 'walletId',
WALLET_IDS = 'walletIds',
Expand Down
Loading