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

feat(wallet): Shield ZCash Account Modal #26214

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ void WalletHandler::GetWalletInfo(GetWalletInfoCallback callback) {
keyring_service->IsWalletCreatedSync(), keyring_service->IsLockedSync(),
keyring_service->IsWalletBackedUpSync(), IsBitcoinEnabled(),
IsBitcoinImportEnabled(), IsBitcoinLedgerEnabled(), IsZCashEnabled(),
IsAnkrBalancesEnabled(), IsTransactionSimulationsEnabled()));
IsAnkrBalancesEnabled(), IsTransactionSimulationsEnabled(),
IsZCashShieldedTransactionsEnabled()));
}

} // namespace brave_wallet
10 changes: 9 additions & 1 deletion components/brave_wallet/browser/brave_wallet_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -1606,7 +1606,15 @@ inline constexpr webui::LocalizedString kLocalizedStrings[] = {
{"braveWalletFilters", IDS_BRAVE_WALLET_FILTERS},
{"braveWalletClearFilters", IDS_BRAVE_WALLET_CLEAR_FILTERS},
{"braveWalletShowMore", IDS_BRAVE_WALLET_SHOW_MORE},
{"braveWalletDetails", IDS_BRAVE_WALLET_DETAILS}};
{"braveWalletDetails", IDS_BRAVE_WALLET_DETAILS},
{"braveWalletSwitchToShieldedAccount",
IDS_BRAVE_WALLET_SWITCH_TO_SHIELDED_ACCOUNT},
{"braveWalletShieldAccount", IDS_BRAVE_WALLET_SHIELD_ACCOUNT},
{"braveWalletAccountNotShieldedDescription",
IDS_BRAVE_WALLET_ACCOUNT_NOT_SHIELDED_DESCRIPTION},
{"braveWalletAccountShieldedDescription",
IDS_BRAVE_WALLET_ACCOUNT_SHIELDED_DESCRIPTION},
{"braveWalletShielded", IDS_BRAVE_WALLET_SHIELDED}};

// 0x swap constants
inline constexpr char kZeroExSepoliaBaseAPIURL[] =
Expand Down
1 change: 1 addition & 0 deletions components/brave_wallet/common/brave_wallet.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,7 @@ struct WalletInfo {
bool is_z_cash_enabled;
bool is_ankr_balances_feature_enabled;
bool is_transaction_simulations_feature_enabled;
bool is_z_cash_shielded_transactions_enabled;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: zcash

};

// Browser-side handler for common panel / page things
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,8 @@ export class MockedWalletApiProxy {
isWalletCreated: true,
isWalletLocked: false,
isAnkrBalancesFeatureEnabled: false,
isTransactionSimulationsFeatureEnabled: true
isTransactionSimulationsFeatureEnabled: true,
isZCashShieldedTransactionsEnabled: false
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export const isAnkrBalancesFeatureEnabled = ({ wallet }: State) =>
wallet.isAnkrBalancesFeatureEnabled
export const isRefreshingNetworksAndTokens = ({ wallet }: State) =>
wallet.isRefreshingNetworksAndTokens
export const isZCashShieldedTransactionsEnabled = ({ wallet }: State) =>
wallet.isZCashShieldedTransactionsEnabled

// unsafe selectors (will cause re-render if not strictly equal "===") (objects
// and lists)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ export function createWalletApiBase() {
'MeldServiceProviders',
'MeldCryptoQuotes',
'MeldPaymentMethods',
'MeldWidget'
'MeldWidget',
'ZCashAccountInfo'
],
endpoints: ({ mutation, query }) => ({})
})
Expand Down
6 changes: 6 additions & 0 deletions components/brave_wallet_ui/common/slices/api.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { encryptionEndpoints } from './endpoints/encryption.endpoints'
import { signingEndpoints } from './endpoints/signing.endpoints'
import { dappRadarEndpoints } from './endpoints/dapp_radar.endpoints'
import { meldIntegrationEndpoints } from './endpoints/meld_integration.endpoints'
import { zcashEndpoints } from './endpoints/zcash.endpoints'

export function createWalletApi() {
// base to add endpoints to
Expand Down Expand Up @@ -160,6 +161,8 @@ export function createWalletApi() {
.injectEndpoints({ endpoints: dappRadarEndpoints })
// meld integration endpoints
.injectEndpoints({ endpoints: meldIntegrationEndpoints })
// zcash endpoints
.injectEndpoints({ endpoints: zcashEndpoints })
)
}

Expand Down Expand Up @@ -256,6 +259,7 @@ export const {
useGetTransactionsQuery,
useGetUserTokensRegistryQuery,
useGetWalletsToImportQuery,
useGetZCashAccountInfoQuery,
useHideNetworksMutation,
useImportAccountFromJsonMutation,
useImportAccountMutation,
Expand Down Expand Up @@ -293,7 +297,9 @@ export const {
useLazyGetTokensRegistryQuery,
useLazyGetTransactionsQuery,
useLazyGetUserTokensRegistryQuery,
useLazyGetZCashAccountInfoQuery,
useLockWalletMutation,
useMakeAccountShieldedMutation,
useNewUnapprovedTxAddedMutation,
useOpenPanelUIMutation,
usePrefetch,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright (c) 2024 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

// Types
import { BraveWallet } from '../../../constants/types'

// Utils
import { handleEndpointError } from '../../../utils/api-utils'
import { WalletApiEndpointBuilderParams } from '../api-base.slice'

export const zcashEndpoints = ({
query,
mutation
}: WalletApiEndpointBuilderParams) => {
return {
makeAccountShielded: mutation<true, BraveWallet.AccountId>({
queryFn: async (args, { endpoint }, _extraOptions, baseQuery) => {
try {
const { zcashWalletService } = baseQuery(undefined).data

const { errorMessage } = await zcashWalletService.makeAccountShielded(
args
)

if (errorMessage) {
return handleEndpointError(
endpoint,
'Error making account shielded: ',
errorMessage
)
}

return {
data: true
}
} catch (error) {
return handleEndpointError(
endpoint,
'Error making account shielded: ',
error
)
}
},
invalidatesTags: ['ZCashAccountInfo']
}),
getZCashAccountInfo: query<
BraveWallet.ZCashAccountInfo | null,
BraveWallet.AccountId
>({
queryFn: async (args, { endpoint }, _extraOptions, baseQuery) => {
try {
const { zcashWalletService } = baseQuery(undefined).data

const { accountInfo } = await zcashWalletService.getZCashAccountInfo(
args
)

return {
data: accountInfo
}
} catch (error) {
return handleEndpointError(
endpoint,
'Error getting ZCash account info: ',
error
)
}
},
providesTags: ['ZCashAccountInfo']
})
}
}
5 changes: 4 additions & 1 deletion components/brave_wallet_ui/common/slices/wallet.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ const defaultState: WalletState = {
passwordAttempts: 0,
assetAutoDiscoveryCompleted: true,
isAnkrBalancesFeatureEnabled: false,
isRefreshingNetworksAndTokens: false
isRefreshingNetworksAndTokens: false,
isZCashShieldedTransactionsEnabled: false
}

// async actions
Expand Down Expand Up @@ -81,6 +82,8 @@ export const createWalletSlice = (initialState: WalletState = defaultState) => {
state.isWalletLocked = payload.walletInfo.isWalletLocked
state.isAnkrBalancesFeatureEnabled =
payload.walletInfo.isAnkrBalancesFeatureEnabled
state.isZCashShieldedTransactionsEnabled =
payload.walletInfo.isZCashShieldedTransactionsEnabled
},

setAssetAutoDiscoveryCompleted(
Expand Down
Loading
Loading