-
Notifications
You must be signed in to change notification settings - Fork 265
Expand file tree
/
Copy patherc1155_ui.c
More file actions
158 lines (151 loc) · 5.97 KB
/
erc1155_ui.c
File metadata and controls
158 lines (151 loc) · 5.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include <string.h>
#include "erc1155_plugin.h"
#include "erc1155_internal.h"
#include "eth_plugin_internal.h"
#include "eth_plugin_interface.h"
#include "common_utils.h"
static void set_approval_for_all_ui(ethQueryContractUI_t *msg, erc1155_context_t *context) {
switch (msg->screenIndex) {
case 0:
if (context->approved) {
strlcpy(msg->title, "Allow", msg->titleLength);
} else {
strlcpy(msg->title, "Revoke", msg->titleLength);
}
if (!getEthDisplayableAddress(context->address,
msg->msg,
msg->msgLength,
chainConfig->chainId)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
break;
case 1:
strlcpy(msg->title, "To Manage ALL", msg->titleLength);
strlcpy(msg->msg, msg->item1->nft.collectionName, msg->msgLength);
break;
case 2:
strlcpy(msg->title, "NFT Address", msg->titleLength);
if (!getEthDisplayableAddress(msg->item1->nft.contractAddress,
msg->msg,
msg->msgLength,
chainConfig->chainId)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
break;
default:
PRINTF("Unsupported screen index %d\n", msg->screenIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
break;
}
}
static void set_transfer_ui(ethQueryContractUI_t *msg, erc1155_context_t *context) {
switch (msg->screenIndex) {
case 0:
strlcpy(msg->title, "To", msg->titleLength);
if (!getEthDisplayableAddress(context->address,
msg->msg,
msg->msgLength,
chainConfig->chainId)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
break;
case 1:
strlcpy(msg->title, "Collection Name", msg->titleLength);
strlcpy(msg->msg, msg->item1->nft.collectionName, msg->msgLength);
break;
case 2:
strlcpy(msg->title, "NFT Address", msg->titleLength);
if (!getEthDisplayableAddress(msg->item1->nft.contractAddress,
msg->msg,
msg->msgLength,
chainConfig->chainId)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
break;
case 3:
strlcpy(msg->title, "NFT ID", msg->titleLength);
if (!uint256_to_decimal(context->tokenId,
sizeof(context->tokenId),
msg->msg,
msg->msgLength)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
break;
case 4:
strlcpy(msg->title, "Quantity", msg->titleLength);
if (!tostring256(&context->value, 10, msg->msg, msg->msgLength)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
break;
default:
PRINTF("Unsupported screen index %d\n", msg->screenIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
break;
}
}
static void set_batch_transfer_ui(ethQueryContractUI_t *msg, erc1155_context_t *context) {
char quantity_str[48];
switch (msg->screenIndex) {
case 0:
strlcpy(msg->title, "To", msg->titleLength);
if (!getEthDisplayableAddress(context->address,
msg->msg,
msg->msgLength,
chainConfig->chainId)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
break;
case 1:
strlcpy(msg->title, "Collection Name", msg->titleLength);
strlcpy(msg->msg, msg->item1->nft.collectionName, msg->msgLength);
break;
case 2:
strlcpy(msg->title, "NFT Address", msg->titleLength);
if (!getEthDisplayableAddress(msg->item1->nft.contractAddress,
msg->msg,
msg->msgLength,
chainConfig->chainId)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
break;
case 3:
strlcpy(msg->title, "Total Quantity", msg->titleLength);
if (!tostring256(&context->value, 10, &quantity_str[0], sizeof(quantity_str))) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
break;
}
snprintf(msg->msg,
msg->msgLength,
"%s from %d NFT IDs",
quantity_str,
context->array_index);
break;
default:
PRINTF("Unsupported screen index %d\n", msg->screenIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
break;
}
}
void handle_query_contract_ui_1155(ethQueryContractUI_t *msg) {
erc1155_context_t *context = (erc1155_context_t *) msg->pluginContext;
if (msg->item1 == NULL) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
return;
}
msg->result = ETH_PLUGIN_RESULT_OK;
switch (context->selectorIndex) {
case SET_APPROVAL_FOR_ALL:
set_approval_for_all_ui(msg, context);
break;
case SAFE_TRANSFER:
set_transfer_ui(msg, context);
break;
case SAFE_BATCH_TRANSFER:
set_batch_transfer_ui(msg, context);
break;
default:
msg->result = ETH_PLUGIN_RESULT_ERROR;
PRINTF("Unsupported selector index %d\n", context->selectorIndex);
break;
}
}