|
199 | 199 |
|
200 | 200 | (rf/reg-event-fx :wallet/clear-stored-collectibles clear-stored-collectibles)
|
201 | 201 |
|
| 202 | +(defn store-last-collectible-details |
| 203 | + [{:keys [db]} [collectible]] |
| 204 | + {:db (assoc-in db |
| 205 | + [:wallet :last-collectible-details] |
| 206 | + collectible)}) |
| 207 | + |
| 208 | +(rf/reg-event-fx :wallet/store-last-collectible-details store-last-collectible-details) |
| 209 | + |
| 210 | +(defn clear-stored-last-collectible-details |
| 211 | + [{:keys [db]}] |
| 212 | + {:db (update db :wallet dissoc :last-collectible-details)}) |
| 213 | + |
| 214 | +(rf/reg-event-fx :wallet/clear-stored-last-collectible-details clear-stored-last-collectible-details) |
| 215 | + |
202 | 216 | (rf/reg-event-fx :wallet/request-collectibles
|
203 | 217 | (fn [{:keys [db]} [{:keys [start-at-index new-request?]}]]
|
204 | 218 | (let [request-id 0
|
|
234 | 248 | [:wallet/request-collectibles
|
235 | 249 | {:start-at-index start-at-index}]])]})))
|
236 | 250 |
|
| 251 | +(rf/reg-event-fx :wallet/get-collectible-details |
| 252 | + (fn [_ [collectible-id]] |
| 253 | + (let [request-id 0 |
| 254 | + collectible-id-converted (cske/transform-keys csk/->PascalCaseKeyword collectible-id) |
| 255 | + request-params [request-id [collectible-id-converted]]] |
| 256 | + {:json-rpc/call [{:method "wallet_getCollectiblesDetailsAsync" |
| 257 | + :params request-params |
| 258 | + :on-error (fn [error] |
| 259 | + (log/error "failed to request collectible" |
| 260 | + {:event :wallet/get-collectible-details |
| 261 | + :error error |
| 262 | + :params request-params}))}]}))) |
| 263 | + |
| 264 | +(rf/reg-event-fx :wallet/get-collectible-details-done |
| 265 | + (fn [_ [{:keys [message]}]] |
| 266 | + (let [response (cske/transform-keys csk/->kebab-case-keyword |
| 267 | + (types/json->clj message)) |
| 268 | + {:keys [collectibles]} response |
| 269 | + collectible (first collectibles)] |
| 270 | + (if collectible |
| 271 | + {:fx |
| 272 | + [[:dispatch [:wallet/store-last-collectible-details collectible]]]} |
| 273 | + (log/error "failed to get collectible details" |
| 274 | + {:event :wallet/get-collectible-details-done |
| 275 | + :response response}))))) |
| 276 | + |
237 | 277 | (rf/reg-event-fx :wallet/fetch-address-suggestions
|
238 | 278 | (fn [{:keys [db]} [address]]
|
239 | 279 | {:db (assoc db
|
|
0 commit comments