Skip to content

Commit fbaf509

Browse files
committed
Block explorer button
1 parent 0d2bf53 commit fbaf509

4 files changed

Lines changed: 44 additions & 2 deletions

File tree

Packages/com.walletconnect.web3modal/Resources/WalletConnect/Web3Modal/Views/AccountView/AccountView.uss

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
flex-direction: column;
44
align-items: center;
55
justify-content: center;
6-
margin-bottom: 20px;
6+
margin-bottom: 12px;
77
margin-top: -20px;
88
}
99

@@ -40,4 +40,24 @@
4040
-unity-text-align: middle-center;
4141
color: var(--wui-color-fg-200);
4242
font-size: var(--wui-font-size-paragraph);
43-
}
43+
}
44+
45+
#account-explorer-button-container {
46+
margin-top: 12px;
47+
}
48+
49+
#account-view__explorer-button-text {
50+
margin: 0 6 0 6;
51+
padding: 0;
52+
-unity-text-align: middle-center;
53+
}
54+
55+
#account-view__explorer-button-icon-left {
56+
--unity-image: resource('WalletConnect/Web3Modal/Icons/icon_medium_compass');
57+
}
58+
59+
#account-view__explorer-button-icon-right {
60+
width: 8px;
61+
height: 8px;
62+
--unity-image: resource('WalletConnect/Web3Modal/Icons/icon_bold_externallink');
63+
}

Packages/com.walletconnect.web3modal/Resources/WalletConnect/Web3Modal/Views/AccountView/AccountView.uxml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
<ui:Label name="account-view__profile-balance-value"/>
1010
<ui:Label name="account-view__profile-balance-symbol"/>
1111
</ui:VisualElement>
12+
<ui:VisualElement name="account-explorer-button-container">
13+
<WalletConnect.UI.Button name="account-view__explorer-button" size="Small" variant="Shade">
14+
<ui:Image name="account-view__explorer-button-icon-left"/>
15+
<ui:Label name="account-view__explorer-button-text"
16+
text="&lt;font-weight=600&gt;Block Explorer&lt;/font-weight&gt;" class="text-small"/>
17+
<ui:Image name="account-view__explorer-button-icon-right"/>
18+
</WalletConnect.UI.Button>
19+
</ui:VisualElement>
1220
</ui:VisualElement>
1321
<ui:VisualElement name="account-view__buttons"/>
1422
</ui:UXML>

Packages/com.walletconnect.web3modal/Runtime/Presenters/AccountPresenter.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23
using System.ComponentModel;
34
using UnityEngine;
@@ -33,6 +34,8 @@ public AccountPresenter(RouterController router, VisualElement parent) : base(ro
3334
};
3435
parent.Add(View);
3536

37+
View.ExplorerButton.Clicked += OnBlockExplorer;
38+
3639
CreateButtons(View.Buttons);
3740

3841
Web3Modal.AccountController.PropertyChanged += AccountPropertyChangedHandler;
@@ -160,6 +163,14 @@ private void OnNetwork()
160163
Router.OpenView(ViewType.NetworkSearch);
161164
}
162165

166+
private void OnBlockExplorer()
167+
{
168+
var chain = Web3Modal.NetworkController.ActiveChain;
169+
var blockExplorerUrl = chain.BlockExplorer.url;
170+
var address = Web3Modal.AccountController.Address;
171+
Application.OpenURL($"{blockExplorerUrl}/address/{address}");
172+
}
173+
163174
private void ItemsSetEnabled(bool value)
164175
{
165176
foreach (var item in _items)

Packages/com.walletconnect.web3modal/Runtime/Views/AccountView/AccountView.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ public class AccountView : VisualElement
1212
public static readonly string NameProfileAvatarImage = $"{Name}__profile-avatar-image";
1313
public static readonly string NameProfileBalanceValue = $"{Name}__profile-balance-value";
1414
public static readonly string NameProfileBalanceSymbol = $"{Name}__profile-balance-symbol";
15+
public static readonly string NameExplorerButton = $"{Name}__explorer-button";
1516
public static readonly string NameButtons = $"{Name}__buttons";
1617

1718
public VisualElement Profile { get; }
1819
public Label ProfileAddress { get; }
1920
public Image ProfileAvatarImage { get; }
2021
public Label ProfileBalanceValue { get; }
2122
public Label ProfileBalanceSymbol { get; }
23+
public Button ExplorerButton { get; }
2224
public VisualElement Buttons { get; }
2325

2426

@@ -38,6 +40,7 @@ public AccountView()
3840
ProfileAvatarImage = Profile.Q<Image>(NameProfileAvatarImage);
3941
ProfileBalanceValue = Profile.Q<Label>(NameProfileBalanceValue);
4042
ProfileBalanceSymbol = Profile.Q<Label>(NameProfileBalanceSymbol);
43+
ExplorerButton = this.Q<Button>(NameExplorerButton);
4144
Buttons = this.Q<VisualElement>(NameButtons);
4245
}
4346

0 commit comments

Comments
 (0)