Skip to content

Commit

Permalink
Merge pull request #15 from Nomis-cc/feature/show-recipient-score-on-…
Browse files Browse the repository at this point in the history
…transaction

feat: display recipient score on transaction
  • Loading branch information
SukhachevN authored Jul 1, 2024
2 parents 705602a + b366749 commit abca5db
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/template-snap-monorepo.git"
},
"source": {
"shasum": "WLnR+GJGZdPIEc4LlQa1kGlA5Z41ZUiaDpZmXXXIfy0=",
"shasum": "lKdj2bNf8RHmIe5hUyu+7f+Fwwi1gcj5ypwMkpy1IBo=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
6 changes: 5 additions & 1 deletion packages/snap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ export const onTransaction: OnTransactionHandler = async ({
transaction,
chainId,
}) => {
return renderTransactionUi(convertCAIP2ToHex(chainId), transaction.from);
return renderTransactionUi(
convertCAIP2ToHex(chainId),
transaction.from,
transaction.to,
);
};

export const onUserInput: OnUserInputHandler = async ({ id, event }) => {
Expand Down
54 changes: 42 additions & 12 deletions packages/snap/src/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,29 +87,59 @@ export const renderMainUiWithError = () => {
]);
};

export const renderTransactionUi = async (chainId: string, account: string) => {
const { score, scoreName, url, isHolder, image } = await getScore(
chainId,
account,
);
export const renderTransactionUi = async (
chainId: string,
senderAccount: string,
recipientAccount: string,
) => {
const [senderData, recipientData] = await Promise.all([
getScore(chainId, senderAccount),
getScore(chainId, recipientAccount),
]);

if (recipientData.isHolder) {
const displayData: Parameters<typeof panel>[0] = [
heading(
`Recipient ${recipientData.scoreName} Score: ${recipientData.score}`,
),
divider(),
text(`[Get your score](https://nomis.cc${recipientData.url})`),
];

if (recipientData.image) {
displayData.splice(
1,
0,
await getImageComponent(recipientData.image, { width: 400 }),
);
}

return {
content: panel(displayData),
};
}

if (!isHolder) {
if (!senderData.isHolder) {
return {
content: panel([
heading(`Get your ${scoreName} Score`),
text(`[Get Score](https://nomis.cc${url})`),
heading(`Get your ${senderData.scoreName} Score`),
text(`[Get Score](https://nomis.cc${senderData.url})`),
]),
};
}

const displayData: Parameters<typeof panel>[0] = [
heading(`${scoreName} Score: ${score}`),
heading(`Your ${senderData.scoreName} Score: ${senderData.score}`),
divider(),
text(`[Update your score](https://nomis.cc${url})`),
text(`[Update your score](https://nomis.cc${senderData.url})`),
];

if (image) {
displayData.splice(1, 0, await getImageComponent(image, { width: 400 }));
if (senderData.image) {
displayData.splice(
1,
0,
await getImageComponent(senderData.image, { width: 400 }),
);
}

return {
Expand Down

0 comments on commit abca5db

Please sign in to comment.