Skip to content

Commit e7f1dab

Browse files
committed
feat: add share buttons
1 parent 5ce5de7 commit e7f1dab

File tree

7 files changed

+206
-116
lines changed

7 files changed

+206
-116
lines changed

packages/site/src/pages/index.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,26 @@ const Index = () => {
114114
await invokeSnap({ method: 'hello' });
115115
};
116116

117+
const installSnap = async () => {
118+
try {
119+
const result = await window.ethereum.request({
120+
method: 'wallet_requestSnaps',
121+
params: {
122+
'npm:nomis': {},
123+
},
124+
});
125+
console.log('Snap installed:', result);
126+
} catch (error) {
127+
console.error('Error installing snap:', error);
128+
}
129+
};
130+
117131
return (
118132
<Container>
119133
<Heading>
120134
Welcome to <Span>template-snap</Span>
121135
</Heading>
136+
122137
<Subtitle>
123138
Get started by editing <code>src/index.ts</code>
124139
</Subtitle>
@@ -128,6 +143,16 @@ const Index = () => {
128143
<b>An error happened:</b> {error.message}
129144
</ErrorMessage>
130145
)}
146+
<Card
147+
content={{
148+
title: 'Install',
149+
description:
150+
'Snaps is pre-release software only available in MetaMask Flask, a canary distribution for developers with access to upcoming features.',
151+
button: <button onClick={installSnap}>Install snap</button>,
152+
}}
153+
fullWidth
154+
/>
155+
131156
{!isMetaMaskReady && (
132157
<Card
133158
content={{

packages/snap/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nomis",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"description": "Onchain Reputation and Decentralized Identity Protocol",
55
"repository": {
66
"type": "git",

packages/snap/snap.manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"version": "0.1.2",
2+
"version": "0.1.3",
33
"description": "Onchain Reputation and Decentralized Identity Protocol",
44
"proposedName": "Nomis Protocol",
55
"repository": {
66
"type": "git",
77
"url": "https://github.com/Nomis-cc/nomis-snaps.git"
88
},
99
"source": {
10-
"shasum": "7DQPaDWXUKVIVld5tLstWABGSqvNItmnOMDx8iUSCV4=",
10+
"shasum": "xgurEG5jHmrFcnBO3CHBriCEkSOvJ8PdLRTWRtKoE7g=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

packages/snap/src/index.tsx

Lines changed: 56 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -36,56 +36,83 @@ export const onTransaction: OnTransactionHandler = async ({
3636
transaction,
3737
chainId,
3838
}) => {
39-
return renderTransactionUi(
40-
convertCAIP2ToHex(chainId),
41-
transaction.from,
42-
transaction.to,
43-
);
39+
try {
40+
return renderTransactionUi(
41+
convertCAIP2ToHex(chainId),
42+
transaction.from,
43+
transaction.to,
44+
);
45+
} catch (error) {
46+
const message = error instanceof Error ? error.message : 'Unknown error';
47+
48+
return { content: renderMainUiWithError(message) };
49+
}
4450
};
4551

4652
export const onUserInput: OnUserInputHandler = async ({ id, event }) => {
47-
if (event.name === 'calculate-score') {
48-
await snap.request({
49-
method: 'snap_updateInterface',
50-
params: {
51-
id,
52-
ui: renderMainUiWithLoading(),
53-
},
54-
});
55-
56-
const [account, chainId] = await Promise.all([getAccount(), getChainId()]);
57-
58-
try {
59-
const { score, scoreName, url } = await calculateScore(chainId, account);
60-
53+
try {
54+
if (event.name === 'calculate-score') {
6155
await snap.request({
6256
method: 'snap_updateInterface',
6357
params: {
6458
id,
65-
ui: renderMainUiWithScore(score, scoreName, url),
59+
ui: renderMainUiWithLoading(),
6660
},
6761
});
68-
} catch {
62+
63+
const [account, chainId] = await Promise.all([
64+
getAccount(),
65+
getChainId(),
66+
]);
67+
68+
try {
69+
const { score, scoreName, url } = await calculateScore(
70+
chainId,
71+
account,
72+
);
73+
74+
await snap.request({
75+
method: 'snap_updateInterface',
76+
params: {
77+
id,
78+
ui: renderMainUiWithScore(score, scoreName, url),
79+
},
80+
});
81+
} catch {
82+
await snap.request({
83+
method: 'snap_updateInterface',
84+
params: {
85+
id,
86+
ui: renderMainUiWithError('Failed to calculate score'),
87+
},
88+
});
89+
}
90+
}
91+
92+
if (event.name === 'back') {
93+
const [account, chainId] = await Promise.all([
94+
getAccount(),
95+
getChainId(),
96+
]);
97+
98+
const ui = await renderMainUi(account, chainId);
99+
69100
await snap.request({
70101
method: 'snap_updateInterface',
71102
params: {
72103
id,
73-
ui: renderMainUiWithError(),
104+
ui,
74105
},
75106
});
76107
}
77-
}
78-
79-
if (event.name === 'back') {
80-
const [account, chainId] = await Promise.all([getAccount(), getChainId()]);
81-
82-
const ui = await renderMainUi(account, chainId);
108+
} catch (error) {
109+
const message = error instanceof Error ? error.message : 'Unknown error';
83110

84111
await snap.request({
85112
method: 'snap_updateInterface',
86113
params: {
87114
id,
88-
ui,
115+
ui: renderMainUiWithError(message),
89116
},
90117
});
91118
}

packages/snap/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export type Holder = {
77
image: string;
88
tokenId: string;
99
updated_ms: string;
10+
referralCode: string;
1011
};
1112

1213
export type Score = {

0 commit comments

Comments
 (0)