Skip to content

Commit

Permalink
Add window.solana.isBraveWallet
Browse files Browse the repository at this point in the history
  • Loading branch information
darkdh committed Jun 14, 2022
1 parent 494d3d3 commit 000a0a0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
15 changes: 12 additions & 3 deletions browser/brave_wallet/solana_provider_renderer_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -640,12 +640,21 @@ IN_PROC_BROWSER_TEST_F(SolanaProviderRendererTest, NonWritable) {
EXPECT_EQ(base::Value(true), result6.value);
}

IN_PROC_BROWSER_TEST_F(SolanaProviderRendererTest, IsPhantom) {
auto result =
IN_PROC_BROWSER_TEST_F(SolanaProviderRendererTest, IsPhantomAndIsBraveWallet) {
ASSERT_TRUE(ExecJs(
web_contents(browser()),
"window.solana.isPhantom = 123; window.solana.isBraveWallet = 456"));
// Both are non-writable
auto result1 =
EvalJs(web_contents(browser()),
"window.domAutomationController.send(window.solana.isPhantom)",
content::EXECUTE_SCRIPT_USE_MANUAL_REPLY);
EXPECT_EQ(base::Value(true), result.value);
EXPECT_EQ(base::Value(true), result1.value);
auto result2 =
EvalJs(web_contents(browser()),
"window.domAutomationController.send(window.solana.isBraveWallet)",
content::EXECUTE_SCRIPT_USE_MANUAL_REPLY);
EXPECT_EQ(base::Value(true), result2.value);
}

IN_PROC_BROWSER_TEST_F(SolanaProviderRendererTest, Connect) {
Expand Down
5 changes: 5 additions & 0 deletions components/brave_wallet/renderer/js_solana_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ gin::ObjectTemplateBuilder JSSolanaProvider::GetObjectTemplateBuilder(
v8::Isolate* isolate) {
return gin::Wrappable<JSSolanaProvider>::GetObjectTemplateBuilder(isolate)
.SetProperty("isPhantom", &JSSolanaProvider::GetIsPhantom)
.SetProperty("isBraveWallet", &JSSolanaProvider::GetIsBraveWallet)
.SetProperty("isConnected", &JSSolanaProvider::GetIsConnected)
.SetProperty("publicKey", &JSSolanaProvider::GetPublicKey)
.SetMethod("connect", &JSSolanaProvider::Connect)
Expand Down Expand Up @@ -187,6 +188,10 @@ bool JSSolanaProvider::GetIsPhantom(gin::Arguments* arguments) {
return true;
}

bool JSSolanaProvider::GetIsBraveWallet(gin::Arguments* arguments) {
return true;
}

bool JSSolanaProvider::GetIsConnected(gin::Arguments* arguments) {
bool is_connected = false;
if (!solana_provider_->IsConnected(&is_connected)) {
Expand Down
1 change: 1 addition & 0 deletions components/brave_wallet/renderer/js_solana_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class JSSolanaProvider final : public gin::Wrappable<JSSolanaProvider>,
void OnRemoteDisconnect();

bool GetIsPhantom(gin::Arguments* arguments);
bool GetIsBraveWallet(gin::Arguments* arguments);
bool GetIsConnected(gin::Arguments* arguments);
// returns solanaWeb3.PublicKey
v8::Local<v8::Value> GetPublicKey(gin::Arguments* arguments);
Expand Down

0 comments on commit 000a0a0

Please sign in to comment.