Skip to content

Commit 38b3877

Browse files
committed
Copy address button
1 parent fbaf509 commit 38b3877

10 files changed

Lines changed: 314 additions & 72 deletions

File tree

Packages/com.walletconnect.web3modal/Resources/Fonts & Materials/Inter/Inter-Medium SDF.asset

Lines changed: 169 additions & 38 deletions
Large diffs are not rendered by default.

Packages/com.walletconnect.web3modal/Resources/Fonts & Materials/Inter/Inter-SemiBold SDF.asset

Lines changed: 75 additions & 21 deletions
Large diffs are not rendered by default.

Packages/com.walletconnect.web3modal/Resources/WalletConnect/Web3Modal/Components/IconLink/IconLink.uss

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
background-color: var(--wui-gray-glass-005);
1010
}
1111

12-
.icon-link--variant-main,
13-
.icon-link--variant-gray {
12+
.icon-link--variant-main {
1413
border-width: 1;
1514
}
1615

@@ -19,11 +18,6 @@
1918
background-color: var(--wui-accent-glass-010);
2019
}
2120

22-
.icon-link--variant-gray {
23-
border-color: var(--wui-gray-glass-005);
24-
background-color: var(--wui-gray-glass-005);
25-
}
26-
2721
#icon-link:active:hover {
2822
background-color: var(--wui-gray-glass-010);
2923
}
@@ -33,9 +27,21 @@
3327
}
3428

3529
.icon-link--variant-shade > #icon-link__image {
30+
--unity-image-tint-color: var(--wui-color-fg-275);
31+
}
32+
33+
.icon-link--variant-neutral > #icon-link__image {
3634
--unity-image-tint-color: var(--wui-accent-glass-005);
3735
}
3836

37+
.icon-link--variant-shade:hover {
38+
background-color: var(--wui-gray-glass-002);
39+
}
40+
41+
.icon-link--variant-shade:active:hover {
42+
background-color: var(--wui-gray-glass-005);
43+
}
44+
3945
.icon-link--variant-main > #icon-link__image {
4046
--unity-image-tint-color: var(--wui-color-accent-100);
4147
}

Packages/com.walletconnect.web3modal/Resources/WalletConnect/Web3Modal/Components/Link/Link.uss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@
4848
--unity-image-tint-color: var(--wui-color-fg-200);
4949
}
5050

51+
.link--variant-icon > #link__icon {
52+
margin-right: 0;
53+
}
54+
55+
.link--variant-icon > #link__text {
56+
display: none;
57+
}
58+
5159
Label {
5260
padding: 0;
5361
}

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
align-items: center;
55
justify-content: center;
66
margin-bottom: 12px;
7-
margin-top: -20px;
7+
margin-top: -12px;
88
}
99

1010
#account-view__profile-avatar {
@@ -46,8 +46,13 @@
4646
margin-top: 12px;
4747
}
4848

49+
#account-view__profile-address-container {
50+
display: flex;
51+
flex-direction: row;
52+
}
53+
4954
#account-view__explorer-button-text {
50-
margin: 0 6 0 6;
55+
margin: 0 6 0 6px;
5156
padding: 0;
5257
-unity-text-align: middle-center;
5358
}
@@ -61,3 +66,7 @@
6166
height: 8px;
6267
--unity-image: resource('WalletConnect/Web3Modal/Icons/icon_bold_externallink');
6368
}
69+
70+
#account-view__profile-address-copy-link-container {
71+
justify-content: flex-end;
72+
}

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@
44
<ui:VisualElement name="account-view__profile-avatar">
55
<ui:Image name="account-view__profile-avatar-image"/>
66
</ui:VisualElement>
7-
<ui:Label name="account-view__profile-address"/>
7+
<ui:VisualElement name="account-view__profile-address-container">
8+
<ui:Label name="account-view__profile-address"/>
9+
<ui:VisualElement name="account-view__profile-address-copy-link-container">
10+
<WalletConnect.UI.IconLink name="account-view__profile-address-copy-link"
11+
icon="WalletConnect/Web3Modal/Icons/icon_bold_copy"
12+
variant="Shade"
13+
/>
14+
</ui:VisualElement>
15+
16+
</ui:VisualElement>
817
<ui:VisualElement name="account-view__profile-balance-container">
918
<ui:Label name="account-view__profile-balance-value"/>
1019
<ui:Label name="account-view__profile-balance-symbol"/>

Packages/com.walletconnect.web3modal/Runtime/Components/IconLink.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ public event Action Clicked
7979
name = "variant"
8080
};
8181

82+
private UxmlStringAttributeDescription tIcon = new()
83+
{
84+
name = "icon"
85+
};
86+
8287
public override IEnumerable<UxmlChildElementDescription> uxmlChildElementsDescription
8388
{
8489
get { yield break; }
@@ -90,6 +95,10 @@ public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext
9095

9196
var link = ve as IconLink;
9297
link.Variant = tVariant.GetValueFromBag(bag, cc);
98+
99+
var iconUrl = tIcon.GetValueFromBag(bag, cc);
100+
if (!string.IsNullOrEmpty(iconUrl))
101+
link.image.vectorImage = Resources.Load<VectorImage>(iconUrl);
93102
}
94103
}
95104

Packages/com.walletconnect.web3modal/Runtime/Components/Link.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class Link : VisualElement
1313
public static readonly string ClassNameSizeMedium = $"{Name}--size-medium";
1414
public static readonly string ClassNameVariantMain = $"{Name}--variant-main";
1515
public static readonly string ClassNameVariantGray = $"{Name}--variant-gray";
16+
public static readonly string ClassNameVariantIcon = $"{Name}--variant-icon";
1617

1718
public string Text
1819
{
@@ -54,6 +55,9 @@ public LinkVariant Variant
5455
case LinkVariant.Gray:
5556
AddToClassList(ClassNameVariantGray);
5657
break;
58+
case LinkVariant.Icon:
59+
AddToClassList(ClassNameVariantIcon);
60+
break;
5761
default:
5862
throw new ArgumentOutOfRangeException(nameof(value), value, null);
5963
}
@@ -161,7 +165,8 @@ public Link(string text, Action clickEvent) : this()
161165
public enum LinkVariant
162166
{
163167
Main,
164-
Gray
168+
Gray,
169+
Icon
165170
}
166171

167172
public enum LinkSize

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public AccountPresenter(RouterController router, VisualElement parent) : base(ro
3535
parent.Add(View);
3636

3737
View.ExplorerButton.Clicked += OnBlockExplorer;
38+
View.CopyLink.Clicked += OnCopyAddress;
3839

3940
CreateButtons(View.Buttons);
4041

@@ -163,14 +164,21 @@ private void OnNetwork()
163164
Router.OpenView(ViewType.NetworkSearch);
164165
}
165166

166-
private void OnBlockExplorer()
167+
protected virtual void OnBlockExplorer()
167168
{
168169
var chain = Web3Modal.NetworkController.ActiveChain;
169170
var blockExplorerUrl = chain.BlockExplorer.url;
170171
var address = Web3Modal.AccountController.Address;
171172
Application.OpenURL($"{blockExplorerUrl}/address/{address}");
172173
}
173174

175+
protected virtual void OnCopyAddress()
176+
{
177+
var address = Web3Modal.AccountController.Address;
178+
GUIUtility.systemCopyBuffer = address;
179+
Web3Modal.NotificationController.Notify(NotificationType.Success, "Address copied");
180+
}
181+
174182
private void ItemsSetEnabled(bool value)
175183
{
176184
foreach (var item in _items)

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class AccountView : VisualElement
1313
public static readonly string NameProfileBalanceValue = $"{Name}__profile-balance-value";
1414
public static readonly string NameProfileBalanceSymbol = $"{Name}__profile-balance-symbol";
1515
public static readonly string NameExplorerButton = $"{Name}__explorer-button";
16+
public static readonly string NameCopyLink = $"{Name}__profile-address-copy-link";
1617
public static readonly string NameButtons = $"{Name}__buttons";
1718

1819
public VisualElement Profile { get; }
@@ -21,6 +22,7 @@ public class AccountView : VisualElement
2122
public Label ProfileBalanceValue { get; }
2223
public Label ProfileBalanceSymbol { get; }
2324
public Button ExplorerButton { get; }
25+
public IconLink CopyLink { get; }
2426
public VisualElement Buttons { get; }
2527

2628

@@ -40,7 +42,8 @@ public AccountView()
4042
ProfileAvatarImage = Profile.Q<Image>(NameProfileAvatarImage);
4143
ProfileBalanceValue = Profile.Q<Label>(NameProfileBalanceValue);
4244
ProfileBalanceSymbol = Profile.Q<Label>(NameProfileBalanceSymbol);
43-
ExplorerButton = this.Q<Button>(NameExplorerButton);
45+
ExplorerButton = Profile.Q<Button>(NameExplorerButton);
46+
CopyLink = Profile.Q<IconLink>(NameCopyLink);
4447
Buttons = this.Q<VisualElement>(NameButtons);
4548
}
4649

0 commit comments

Comments
 (0)