Skip to content

Commit

Permalink
Add bindings to WebUI
Browse files Browse the repository at this point in the history
  • Loading branch information
cypt4 committed Dec 2, 2022
1 parent 7def1af commit ba27385
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 7 deletions.
13 changes: 12 additions & 1 deletion browser/ui/webui/brave_wallet/wallet_page_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "brave/browser/brave_wallet/asset_ratio_service_factory.h"
#include "brave/browser/brave_wallet/brave_wallet_auto_pin_service_factory.h"
#include "brave/browser/brave_wallet/brave_wallet_pin_service_factory.h"
#include "brave/browser/brave_wallet/brave_wallet_service_factory.h"
#include "brave/browser/brave_wallet/json_rpc_service_factory.h"
#include "brave/browser/brave_wallet/keyring_service_factory.h"
Expand All @@ -21,6 +23,7 @@
#include "brave/components/brave_wallet/browser/asset_ratio_service.h"
#include "brave/components/brave_wallet/browser/blockchain_registry.h"
#include "brave/components/brave_wallet/browser/brave_wallet_constants.h"
#include "brave/components/brave_wallet/browser/brave_wallet_pin_service.h"
#include "brave/components/brave_wallet/browser/brave_wallet_service.h"
#include "brave/components/brave_wallet/browser/json_rpc_service.h"
#include "brave/components/brave_wallet/browser/keyring_service.h"
Expand Down Expand Up @@ -111,7 +114,11 @@ void WalletPageUI::CreatePageHandler(
mojo::PendingReceiver<brave_wallet::mojom::BraveWalletService>
brave_wallet_service_receiver,
mojo::PendingReceiver<brave_wallet::mojom::BraveWalletP3A>
brave_wallet_p3a_receiver) {
brave_wallet_p3a_receiver,
mojo::PendingReceiver<brave_wallet::mojom::WalletPinService>
brave_wallet_pin_service_receiver,
mojo::PendingReceiver<brave_wallet::mojom::WalletAutoPinService>
brave_wallet_auto_pin_service_receiver) {
DCHECK(page);
auto* profile = Profile::FromWebUI(web_ui());
DCHECK(profile);
Expand Down Expand Up @@ -142,6 +149,10 @@ void WalletPageUI::CreatePageHandler(
wallet_service->Bind(std::move(brave_wallet_service_receiver));
wallet_service->GetBraveWalletP3A()->Bind(
std::move(brave_wallet_p3a_receiver));
brave_wallet::BraveWalletPinServiceFactory::BindForContext(
profile, std::move(brave_wallet_pin_service_receiver));
brave_wallet::BraveWalletAutoPinServiceFactory::BindForContext(
profile, std::move(brave_wallet_auto_pin_service_receiver));

auto* blockchain_registry = brave_wallet::BlockchainRegistry::GetInstance();
if (blockchain_registry) {
Expand Down
6 changes: 5 additions & 1 deletion browser/ui/webui/brave_wallet/wallet_page_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ class WalletPageUI : public ui::MojoWebUIController,
mojo::PendingReceiver<brave_wallet::mojom::BraveWalletService>
brave_wallet_service,
mojo::PendingReceiver<brave_wallet::mojom::BraveWalletP3A>
brave_wallet_p3a) override;
brave_wallet_p3a,
mojo::PendingReceiver<brave_wallet::mojom::WalletPinService>
brave_wallet_pin_service_receiver,
mojo::PendingReceiver<brave_wallet::mojom::WalletAutoPinService>
brave_wallet_auto_pin_service_receiver) override;

std::unique_ptr<WalletPageHandler> page_handler_;
std::unique_ptr<WalletHandler> wallet_handler_;
Expand Down
3 changes: 2 additions & 1 deletion components/brave_wallet_ui/common/actions/wallet_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,6 @@
unlocked,
updateUnapprovedTransactionGasFields,
updateUnapprovedTransactionNonce,
updateUnapprovedTransactionSpendAllowance
updateUnapprovedTransactionSpendAllowance,
updateTokenPinStatus
} = WalletActions
3 changes: 2 additions & 1 deletion components/brave_wallet_ui/common/slices/wallet.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ export const WalletAsyncActions = {
addAccount: createAction<AddAccountPayloadType>('addAccount'), // alias for keyringService.addAccount
addFilecoinAccount: createAction<AddFilecoinAccountPayloadType>('addFilecoinAccount'), // alias for keyringService.addFilecoinAccount
getOnRampCurrencies: createAction('getOnRampCurrencies'),
autoLockMinutesChanged: createAction('autoLockMinutesChanged') // No reducer or API logic for this (UNUSED)
autoLockMinutesChanged: createAction('autoLockMinutesChanged'), // No reducer or API logic for this (UNUSED)
updateTokenPinStatus: createAction<BraveWallet.BlockchainToken>('updateTokenPinStatus')
}

// slice
Expand Down
10 changes: 10 additions & 0 deletions components/brave_wallet_ui/common/wallet_api_proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export class WalletApiProxy {
filTxManagerProxy = new BraveWallet.FilTxManagerProxyRemote()
braveWalletService = new BraveWallet.BraveWalletServiceRemote()
braveWalletP3A = new BraveWallet.BraveWalletP3ARemote()
braveWalletPinService = new BraveWallet.WalletPinServiceRemote()
braveWalletAutoPinService = new BraveWallet.WalletAutoPinServiceRemote()

addJsonRpcServiceObserver (store: Store) {
const jsonRpcServiceObserverReceiver = new BraveWallet.JsonRpcServiceObserverReceiver({
Expand Down Expand Up @@ -125,6 +127,14 @@ export class WalletApiProxy {
})
this.braveWalletService.addObserver(braveWalletServiceObserverReceiver.$.bindNewPipeAndPassRemote())
}

addBraveWalletPinServiceObserver (store: Store) {
const braveWalletServiceObserverReceiver = new BraveWallet.BraveWalletPinServiceObserverReceiver({
onTokenStatusChanged: function (service, token, status) {
}
})
this.braveWalletPinService.addObserver(braveWalletServiceObserverReceiver.$.bindNewPipeAndPassRemote())
}
}

export default WalletApiProxy
1 change: 1 addition & 0 deletions components/brave_wallet_ui/constants/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ export interface PageState {
isFetchingNFTMetadata: boolean
nftMetadata: NFTMetadataReturnType | undefined
nftMetadataError: string | undefined
pinStatusOverview: BraveWallet.TokenPinOverview | undefined
selectedAssetFiatPrice: BraveWallet.AssetPrice | undefined
selectedAssetCryptoPrice: BraveWallet.AssetPrice | undefined
selectedAssetPriceHistory: GetPriceHistoryReturnInfo[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@ export const {
updateSelectedAsset,
walletBackupComplete,
walletCreated,
walletSetupComplete
walletSetupComplete,
updateNFTPinStatus,
getPinStatus
} = PageActions
11 changes: 11 additions & 0 deletions components/brave_wallet_ui/page/async/wallet_page_async_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ handler.on(WalletPageActions.selectAsset.type, async (store: Store, payload: Upd

if (payload.asset.isErc721) {
store.dispatch(WalletPageActions.getNFTMetadata(payload.asset))
store.dispatch(WalletPageActions.getPinStatus(payload.asset))
}
} else {
store.dispatch(WalletPageActions.updatePriceInfo({ priceHistory: undefined, defaultFiatPrice: undefined, defaultCryptoPrice: undefined, timeFrame: payload.timeFrame }))
Expand Down Expand Up @@ -305,4 +306,14 @@ handler.on(WalletPageActions.getNFTMetadata.type, async (store, payload: BraveWa
store.dispatch(WalletPageActions.setIsFetchingNFTMetadata(false))
})

handler.on(WalletPageActions.getPinStatus.type, async (store, payload: BraveWallet.BlockchainToken) => {
const braveWalletPinService = getWalletPageApiProxy().braveWalletPinService
const result = await braveWalletPinService.getTokenStatus(payload)
if (result.status) {
store.dispatch(WalletPageActions.updateNFTPinStatus(result.status))
} else {
store.dispatch(WalletPageActions.updateNFTPinStatus(undefined))
}
})

export default handler.middleware
9 changes: 8 additions & 1 deletion components/brave_wallet_ui/page/reducers/page_reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const defaultState: PageState = {
isFetchingNFTMetadata: true,
nftMetadata: undefined,
nftMetadataError: undefined,
pinStatusOverview: undefined,
selectedAssetFiatPrice: undefined,
selectedAssetCryptoPrice: undefined,
selectedAssetPriceHistory: [],
Expand Down Expand Up @@ -71,7 +72,9 @@ export const WalletPageAsyncActions = {
removeImportedAccount: createAction<RemoveImportedAccountPayloadType>('removeImportedAccount'),
restoreWallet: createAction<RestoreWalletPayloadType>('restoreWallet'),
selectAsset: createAction<UpdateSelectedAssetType>('selectAsset'),
updateAccountName: createAction<UpdateAccountNamePayloadType>('updateAccountName')
updateAccountName: createAction<UpdateAccountNamePayloadType>('updateAccountName'),
updateNFTPinStatus: createAction<BraveWallet.TokenPinOverview | undefined>('updateNFTPinStatus'),
getPinStatus: createAction<BraveWallet.BlockchainToken>('getPinStatus')
}

export const createPageSlice = (initialState: PageState = defaultState) => {
Expand Down Expand Up @@ -177,6 +180,10 @@ export const createPageSlice = (initialState: PageState = defaultState) => {
// complete setup unless explicitly halted
state.setupStillInProgress = !action?.payload
state.mnemonic = undefined
},

updateNFTPinStatus (state, { payload }: PayloadAction<BraveWallet.TokenPinOverview | undefined>) {
state.pinStatusOverview = payload
}
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const nftMetadataError = ({ page }: State) => page.nftMetadataError

export const portfolioPriceHistory = ({ page }: State) => page.portfolioPriceHistory
export const selectedAsset = ({ page }: State) => page.selectedAsset
export const pinStatusOverview = ({ page }: State) => page.pinStatusOverview
export const selectedAssetCryptoPrice = ({ page }: State) => page.selectedAssetCryptoPrice
export const selectedAssetFiatPrice = ({ page }: State) => page.selectedAssetFiatPrice
export const selectedAssetPriceHistory = ({ page }: State) => page.selectedAssetPriceHistory
Expand Down
1 change: 1 addition & 0 deletions components/brave_wallet_ui/page/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ proxy.addJsonRpcServiceObserver(store)
proxy.addKeyringServiceObserver(store)
proxy.addTxServiceObserver(store)
proxy.addBraveWalletServiceObserver(store)
proxy.addBraveWalletPinServiceObserver(store)

export const walletPageApiProxy = proxy

Expand Down
4 changes: 3 additions & 1 deletion components/brave_wallet_ui/page/wallet_page_api_proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ class WalletPageApiProxy extends WalletApiProxy {
this.solanaTxManagerProxy.$.bindNewPipeAndPassReceiver(),
this.filTxManagerProxy.$.bindNewPipeAndPassReceiver(),
this.braveWalletService.$.bindNewPipeAndPassReceiver(),
this.braveWalletP3A.$.bindNewPipeAndPassReceiver())
this.braveWalletP3A.$.bindNewPipeAndPassReceiver(),
this.braveWalletPinService.$.bindNewPipeAndPassReceiver(),
this.braveWalletAutoPinService.$.bindNewPipeAndPassReceiver())
}
}

Expand Down

0 comments on commit ba27385

Please sign in to comment.