Skip to content

Commit

Permalink
Merge pull request #13767 from brave/sol-is-brave-wallet
Browse files Browse the repository at this point in the history
Add window.solana.isBraveWallet
  • Loading branch information
darkdh authored Jun 14, 2022
2 parents cfe0dc5 + 000a0a0 commit 4ace4ef
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 @@ -655,12 +655,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 4ace4ef

Please sign in to comment.