Skip to content

Commit c0c16bd

Browse files
committed
Added InteractiveWebAssembly sample
1 parent 9ade273 commit c0c16bd

27 files changed

+1016
-2
lines changed

MetaMask.Blazor.sln

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.31229.75
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.10.34804.81
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MetaMask.Blazor.SampleApp", "MetaMask.Blazor.SampleApp\MetaMask.Blazor.SampleApp.csproj", "{0F486791-A547-4CAB-9624-99A1A33EB55C}"
77
EndProject
88
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MetaMask.Blazor", "MetaMask.Blazor\MetaMask.Blazor.csproj", "{3A8A384E-CE91-4DC2-AEE5-DA723AE4D644}"
99
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SampleWebApp", "SampleWebApp", "{0E3BE2A7-4412-4DE2-807D-B151288DCC5E}"
11+
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Metamask.Blazor.SampleWebApp", "Metamask.Blazor.SampleWebApp\Metamask.Blazor.SampleWebApp\Metamask.Blazor.SampleWebApp.csproj", "{91775BB3-E03A-42C5-868D-14402832B839}"
13+
EndProject
14+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Metamask.Blazor.SampleWebApp.Client", "Metamask.Blazor.SampleWebApp\Metamask.Blazor.SampleWebApp.Client\Metamask.Blazor.SampleWebApp.Client.csproj", "{F56C5236-B51E-4627-B79C-EBD2D6111CDB}"
15+
EndProject
1016
Global
1117
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1218
Debug|Any CPU = Debug|Any CPU
@@ -21,10 +27,22 @@ Global
2127
{3A8A384E-CE91-4DC2-AEE5-DA723AE4D644}.Debug|Any CPU.Build.0 = Debug|Any CPU
2228
{3A8A384E-CE91-4DC2-AEE5-DA723AE4D644}.Release|Any CPU.ActiveCfg = Release|Any CPU
2329
{3A8A384E-CE91-4DC2-AEE5-DA723AE4D644}.Release|Any CPU.Build.0 = Release|Any CPU
30+
{91775BB3-E03A-42C5-868D-14402832B839}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
31+
{91775BB3-E03A-42C5-868D-14402832B839}.Debug|Any CPU.Build.0 = Debug|Any CPU
32+
{91775BB3-E03A-42C5-868D-14402832B839}.Release|Any CPU.ActiveCfg = Release|Any CPU
33+
{91775BB3-E03A-42C5-868D-14402832B839}.Release|Any CPU.Build.0 = Release|Any CPU
34+
{F56C5236-B51E-4627-B79C-EBD2D6111CDB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
35+
{F56C5236-B51E-4627-B79C-EBD2D6111CDB}.Debug|Any CPU.Build.0 = Debug|Any CPU
36+
{F56C5236-B51E-4627-B79C-EBD2D6111CDB}.Release|Any CPU.ActiveCfg = Release|Any CPU
37+
{F56C5236-B51E-4627-B79C-EBD2D6111CDB}.Release|Any CPU.Build.0 = Release|Any CPU
2438
EndGlobalSection
2539
GlobalSection(SolutionProperties) = preSolution
2640
HideSolutionNode = FALSE
2741
EndGlobalSection
42+
GlobalSection(NestedProjects) = preSolution
43+
{91775BB3-E03A-42C5-868D-14402832B839} = {0E3BE2A7-4412-4DE2-807D-B151288DCC5E}
44+
{F56C5236-B51E-4627-B79C-EBD2D6111CDB} = {0E3BE2A7-4412-4DE2-807D-B151288DCC5E}
45+
EndGlobalSection
2846
GlobalSection(ExtensibilityGlobals) = postSolution
2947
SolutionGuid = {7221E773-3EB8-4A50-A0CC-7314DCBB72ED}
3048
EndGlobalSection

MetaMask.Blazor/wwwroot/metaMaskJsInterop.js

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// functions, and may import other JavaScript modules if required.
33

44
export async function checkMetaMask() {
5+
console.log('check');
6+
57
// Modern dapp browsers...
68
if (window.ethereum) {
79
if (ethereum.selectedAddress === null || ethereum.selectedAddress === undefined) {
@@ -31,6 +33,7 @@ export async function requestAccounts() {
3133
}
3234

3335
export function hasMetaMask() {
36+
console.log('hasMetamask');
3437
return (window.ethereum != undefined);
3538
}
3639

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
@inherits LayoutComponentBase
2+
3+
<div class="page">
4+
<div class="sidebar">
5+
<NavMenu />
6+
</div>
7+
8+
<main>
9+
<div class="top-row px-4">
10+
<a href="https://learn.microsoft.com/aspnet/core/" target="_blank">About</a>
11+
</div>
12+
13+
<article class="content px-4">
14+
@Body
15+
</article>
16+
</main>
17+
</div>
18+
19+
<div id="blazor-error-ui">
20+
An unhandled error has occurred.
21+
<a href="" class="reload">Reload</a>
22+
<a class="dismiss">🗙</a>
23+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
.page {
2+
position: relative;
3+
display: flex;
4+
flex-direction: column;
5+
}
6+
7+
main {
8+
flex: 1;
9+
}
10+
11+
.sidebar {
12+
background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%);
13+
}
14+
15+
.top-row {
16+
background-color: #f7f7f7;
17+
border-bottom: 1px solid #d6d5d5;
18+
justify-content: flex-end;
19+
height: 3.5rem;
20+
display: flex;
21+
align-items: center;
22+
}
23+
24+
.top-row ::deep a, .top-row ::deep .btn-link {
25+
white-space: nowrap;
26+
margin-left: 1.5rem;
27+
text-decoration: none;
28+
}
29+
30+
.top-row ::deep a:hover, .top-row ::deep .btn-link:hover {
31+
text-decoration: underline;
32+
}
33+
34+
.top-row ::deep a:first-child {
35+
overflow: hidden;
36+
text-overflow: ellipsis;
37+
}
38+
39+
@media (max-width: 640.98px) {
40+
.top-row {
41+
justify-content: space-between;
42+
}
43+
44+
.top-row ::deep a, .top-row ::deep .btn-link {
45+
margin-left: 0;
46+
}
47+
}
48+
49+
@media (min-width: 641px) {
50+
.page {
51+
flex-direction: row;
52+
}
53+
54+
.sidebar {
55+
width: 250px;
56+
height: 100vh;
57+
position: sticky;
58+
top: 0;
59+
}
60+
61+
.top-row {
62+
position: sticky;
63+
top: 0;
64+
z-index: 1;
65+
}
66+
67+
.top-row.auth ::deep a:first-child {
68+
flex: 1;
69+
text-align: right;
70+
width: 0;
71+
}
72+
73+
.top-row, article {
74+
padding-left: 2rem !important;
75+
padding-right: 1.5rem !important;
76+
}
77+
}
78+
79+
#blazor-error-ui {
80+
background: lightyellow;
81+
bottom: 0;
82+
box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
83+
display: none;
84+
left: 0;
85+
padding: 0.6rem 1.25rem 0.7rem 1.25rem;
86+
position: fixed;
87+
width: 100%;
88+
z-index: 1000;
89+
}
90+
91+
#blazor-error-ui .dismiss {
92+
cursor: pointer;
93+
position: absolute;
94+
right: 0.75rem;
95+
top: 0.5rem;
96+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<div class="top-row ps-3 navbar navbar-dark">
2+
<div class="container-fluid">
3+
<a class="navbar-brand" href="">Metamask.Blazor.SampleWebApp</a>
4+
</div>
5+
</div>
6+
7+
<input type="checkbox" title="Navigation menu" class="navbar-toggler" />
8+
9+
<div class="nav-scrollable" onclick="document.querySelector('.navbar-toggler').click()">
10+
<nav class="flex-column">
11+
<div class="nav-item px-3">
12+
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
13+
<span class="bi bi-house-door-fill-nav-menu" aria-hidden="true"></span> Home
14+
</NavLink>
15+
</div>
16+
</nav>
17+
</div>
18+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
.navbar-toggler {
2+
appearance: none;
3+
cursor: pointer;
4+
width: 3.5rem;
5+
height: 2.5rem;
6+
color: white;
7+
position: absolute;
8+
top: 0.5rem;
9+
right: 1rem;
10+
border: 1px solid rgba(255, 255, 255, 0.1);
11+
background: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%28255, 255, 255, 0.55%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e") no-repeat center/1.75rem rgba(255, 255, 255, 0.1);
12+
}
13+
14+
.navbar-toggler:checked {
15+
background-color: rgba(255, 255, 255, 0.5);
16+
}
17+
18+
.top-row {
19+
height: 3.5rem;
20+
background-color: rgba(0,0,0,0.4);
21+
}
22+
23+
.navbar-brand {
24+
font-size: 1.1rem;
25+
}
26+
27+
.bi {
28+
display: inline-block;
29+
position: relative;
30+
width: 1.25rem;
31+
height: 1.25rem;
32+
margin-right: 0.75rem;
33+
top: -1px;
34+
background-size: cover;
35+
}
36+
37+
.bi-house-door-fill-nav-menu {
38+
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-house-door-fill' viewBox='0 0 16 16'%3E%3Cpath d='M6.5 14.5v-3.505c0-.245.25-.495.5-.495h2c.25 0 .5.25.5.5v3.5a.5.5 0 0 0 .5.5h4a.5.5 0 0 0 .5-.5v-7a.5.5 0 0 0-.146-.354L13 5.793V2.5a.5.5 0 0 0-.5-.5h-1a.5.5 0 0 0-.5.5v1.293L8.354 1.146a.5.5 0 0 0-.708 0l-6 6A.5.5 0 0 0 1.5 7.5v7a.5.5 0 0 0 .5.5h4a.5.5 0 0 0 .5-.5Z'/%3E%3C/svg%3E");
39+
}
40+
41+
.bi-plus-square-fill-nav-menu {
42+
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-plus-square-fill' viewBox='0 0 16 16'%3E%3Cpath d='M2 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2H2zm6.5 4.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3a.5.5 0 0 1 1 0z'/%3E%3C/svg%3E");
43+
}
44+
45+
.bi-list-nested-nav-menu {
46+
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-list-nested' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M4.5 11.5A.5.5 0 0 1 5 11h10a.5.5 0 0 1 0 1H5a.5.5 0 0 1-.5-.5zm-2-4A.5.5 0 0 1 3 7h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm-2-4A.5.5 0 0 1 1 3h10a.5.5 0 0 1 0 1H1a.5.5 0 0 1-.5-.5z'/%3E%3C/svg%3E");
47+
}
48+
49+
.nav-item {
50+
font-size: 0.9rem;
51+
padding-bottom: 0.5rem;
52+
}
53+
54+
.nav-item:first-of-type {
55+
padding-top: 1rem;
56+
}
57+
58+
.nav-item:last-of-type {
59+
padding-bottom: 1rem;
60+
}
61+
62+
.nav-item ::deep .nav-link {
63+
color: #d7d7d7;
64+
background: none;
65+
border: none;
66+
border-radius: 4px;
67+
height: 3rem;
68+
display: flex;
69+
align-items: center;
70+
line-height: 3rem;
71+
width: 100%;
72+
}
73+
74+
.nav-item ::deep a.active {
75+
background-color: rgba(255,255,255,0.37);
76+
color: white;
77+
}
78+
79+
.nav-item ::deep .nav-link:hover {
80+
background-color: rgba(255,255,255,0.1);
81+
color: white;
82+
}
83+
84+
.nav-scrollable {
85+
display: none;
86+
}
87+
88+
.navbar-toggler:checked ~ .nav-scrollable {
89+
display: block;
90+
}
91+
92+
@media (min-width: 641px) {
93+
.navbar-toggler {
94+
display: none;
95+
}
96+
97+
.nav-scrollable {
98+
/* Never collapse the sidebar for wide screens */
99+
display: block;
100+
101+
/* Allow sidebar to scroll for tall menus */
102+
height: calc(100vh - 3.5rem);
103+
overflow-y: auto;
104+
}
105+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile>
8+
<StaticWebAssetProjectMode>Default</StaticWebAssetProjectMode>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.4" />
13+
<PackageReference Include="Nethereum.ABI" Version="4.20.0" />
14+
<PackageReference Include="Nethereum.Web3" Version="4.20.0" />
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<ProjectReference Include="..\..\MetaMask.Blazor\MetaMask.Blazor.csproj" />
19+
</ItemGroup>
20+
21+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using Newtonsoft.Json;
2+
using Newtonsoft.Json.Serialization;
3+
using System.Collections.Generic;
4+
using System.Numerics;
5+
6+
namespace MetaMask.Blazor.SampleWebApp.Client.Models
7+
{
8+
public record struct Message(string contents);
9+
10+
11+
public class TypedDataPayload<T>
12+
{
13+
public Dictionary<string, TypeMemberValue[]> Types { get; set; } = new();
14+
public string? PrimaryType { get; set; }
15+
public Domain? Domain { get; set; }
16+
public T? Message { get; set; }
17+
18+
19+
public string ToJson()
20+
{
21+
var serializerSettings = new JsonSerializerSettings
22+
{
23+
ContractResolver = new CamelCasePropertyNamesContractResolver()
24+
{
25+
NamingStrategy = new CamelCaseNamingStrategy()
26+
{
27+
ProcessDictionaryKeys = false
28+
}
29+
},
30+
31+
DefaultValueHandling = DefaultValueHandling.Ignore
32+
};
33+
return JsonConvert.SerializeObject(this, serializerSettings);
34+
}
35+
}
36+
37+
public class Domain
38+
{
39+
public string? Name { get; set; }
40+
public string? Version { get; set; }
41+
public BigInteger? ChainId { get; set; }
42+
}
43+
44+
public class TypeMemberValue
45+
{
46+
public string? Name { get; set; }
47+
public string? Type { get; set; }
48+
}
49+
}

0 commit comments

Comments
 (0)