Skip to content

Commit

Permalink
feat: add share buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
SukhachevN committed Aug 8, 2024
1 parent 5ce5de7 commit e7f1dab
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 116 deletions.
25 changes: 25 additions & 0 deletions packages/site/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,26 @@ const Index = () => {
await invokeSnap({ method: 'hello' });
};

const installSnap = async () => {
try {
const result = await window.ethereum.request({
method: 'wallet_requestSnaps',
params: {
'npm:nomis': {},
},
});
console.log('Snap installed:', result);
} catch (error) {

Check failure on line 126 in packages/site/src/pages/index.tsx

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint

'error' is already declared in the upper scope on line 104 column 11
console.error('Error installing snap:', error);
}
};

return (
<Container>
<Heading>
Welcome to <Span>template-snap</Span>
</Heading>

<Subtitle>
Get started by editing <code>src/index.ts</code>
</Subtitle>
Expand All @@ -128,6 +143,16 @@ const Index = () => {
<b>An error happened:</b> {error.message}
</ErrorMessage>
)}
<Card
content={{
title: 'Install',
description:
'Snaps is pre-release software only available in MetaMask Flask, a canary distribution for developers with access to upcoming features.',
button: <button onClick={installSnap}>Install snap</button>,

Check failure on line 151 in packages/site/src/pages/index.tsx

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint

Promise-returning function provided to attribute where a void return was expected
}}
fullWidth
/>

{!isMetaMaskReady && (
<Card
content={{
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nomis",
"version": "0.1.2",
"version": "0.1.3",
"description": "Onchain Reputation and Decentralized Identity Protocol",
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"version": "0.1.2",
"version": "0.1.3",
"description": "Onchain Reputation and Decentralized Identity Protocol",
"proposedName": "Nomis Protocol",
"repository": {
"type": "git",
"url": "https://github.com/Nomis-cc/nomis-snaps.git"
},
"source": {
"shasum": "7DQPaDWXUKVIVld5tLstWABGSqvNItmnOMDx8iUSCV4=",
"shasum": "xgurEG5jHmrFcnBO3CHBriCEkSOvJ8PdLRTWRtKoE7g=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
85 changes: 56 additions & 29 deletions packages/snap/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,56 +36,83 @@ export const onTransaction: OnTransactionHandler = async ({
transaction,
chainId,
}) => {
return renderTransactionUi(
convertCAIP2ToHex(chainId),
transaction.from,
transaction.to,
);
try {
return renderTransactionUi(
convertCAIP2ToHex(chainId),
transaction.from,
transaction.to,
);
} catch (error) {
const message = error instanceof Error ? error.message : 'Unknown error';

return { content: renderMainUiWithError(message) };
}
};

export const onUserInput: OnUserInputHandler = async ({ id, event }) => {
if (event.name === 'calculate-score') {
await snap.request({
method: 'snap_updateInterface',
params: {
id,
ui: renderMainUiWithLoading(),
},
});

const [account, chainId] = await Promise.all([getAccount(), getChainId()]);

try {
const { score, scoreName, url } = await calculateScore(chainId, account);

try {
if (event.name === 'calculate-score') {
await snap.request({
method: 'snap_updateInterface',
params: {
id,
ui: renderMainUiWithScore(score, scoreName, url),
ui: renderMainUiWithLoading(),
},
});
} catch {

const [account, chainId] = await Promise.all([
getAccount(),
getChainId(),
]);

try {
const { score, scoreName, url } = await calculateScore(
chainId,
account,
);

await snap.request({
method: 'snap_updateInterface',
params: {
id,
ui: renderMainUiWithScore(score, scoreName, url),
},
});
} catch {
await snap.request({
method: 'snap_updateInterface',
params: {
id,
ui: renderMainUiWithError('Failed to calculate score'),
},
});
}
}

if (event.name === 'back') {
const [account, chainId] = await Promise.all([
getAccount(),
getChainId(),
]);

const ui = await renderMainUi(account, chainId);

await snap.request({
method: 'snap_updateInterface',
params: {
id,
ui: renderMainUiWithError(),
ui,
},
});
}
}

if (event.name === 'back') {
const [account, chainId] = await Promise.all([getAccount(), getChainId()]);

const ui = await renderMainUi(account, chainId);
} catch (error) {
const message = error instanceof Error ? error.message : 'Unknown error';

await snap.request({
method: 'snap_updateInterface',
params: {
id,
ui,
ui: renderMainUiWithError(message),
},
});
}
Expand Down
1 change: 1 addition & 0 deletions packages/snap/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type Holder = {
image: string;
tokenId: string;
updated_ms: string;
referralCode: string;
};

export type Score = {
Expand Down
Loading

0 comments on commit e7f1dab

Please sign in to comment.