Skip to content

Commit

Permalink
feat(wallet): Shield ZCash Account Modal
Browse files Browse the repository at this point in the history
  • Loading branch information
Douglashdaniel committed Oct 24, 2024
1 parent c71fdd5 commit 01c6c75
Show file tree
Hide file tree
Showing 20 changed files with 511 additions and 122 deletions.
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 @@ -1584,7 +1584,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;
};

// Browser-side handler for common panel / page things
Expand Down
3 changes: 2 additions & 1 deletion components/brave_wallet_ui/common/async/__mocks__/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,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
3 changes: 2 additions & 1 deletion components/brave_wallet_ui/common/slices/api-base.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ export function createWalletApiBase() {
'PinnableNftIds',
'PendingSignMessageRequests',
'PendingSignMessageErrors',
'ActiveOrigin'
'ActiveOrigin',
'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 @@ -49,6 +49,7 @@ import { swapEndpoints } from './endpoints/swap.endpoints'
import { encryptionEndpoints } from './endpoints/encryption.endpoints'
import { signingEndpoints } from './endpoints/signing.endpoints'
import { dappRadarEndpoints } from './endpoints/dapp_radar.endpoints'
import { zcashEndpoints } from './endpoints/zcash.endpoints'

export function createWalletApi() {
// base to add endpoints to
Expand Down Expand Up @@ -157,6 +158,8 @@ export function createWalletApi() {
.injectEndpoints({ endpoints: signingEndpoints })
// dApp Radar Endpoints
.injectEndpoints({ endpoints: dappRadarEndpoints })
// zcash endpoints
.injectEndpoints({ endpoints: zcashEndpoints })
)
}

Expand Down Expand Up @@ -253,6 +256,7 @@ export const {
useGetTransactionsQuery,
useGetUserTokensRegistryQuery,
useGetWalletsToImportQuery,
useGetZCashAccountInfoQuery,
useHideNetworksMutation,
useImportAccountFromJsonMutation,
useImportAccountMutation,
Expand Down Expand Up @@ -290,7 +294,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

0 comments on commit 01c6c75

Please sign in to comment.