From 1ceda0d8437cb9360be7998f81bc15bec0490a9d Mon Sep 17 00:00:00 2001 From: JulesGuesnon Date: Fri, 12 Jan 2024 11:53:52 +0900 Subject: [PATCH 01/21] feat(Dapps): Added all the tezos domains and obkt transactions --- assets/images/objkt.png | Bin 0 -> 5191 bytes components/RenderProposalContentLambda.tsx | 6 +- dapps/identifyDapp.ts | 8 + dapps/objkt.tsx | 476 +++++++++++++++++++++ dapps/tezosDomains.tsx | 347 ++++++++++++++- pages/[walletAddress]/proposals.tsx | 2 +- 6 files changed, 817 insertions(+), 22 deletions(-) create mode 100644 assets/images/objkt.png create mode 100644 dapps/objkt.tsx diff --git a/assets/images/objkt.png b/assets/images/objkt.png new file mode 100644 index 0000000000000000000000000000000000000000..c3827cb8b00c034c71f2720e7cf8cf01c5c354fe GIT binary patch literal 5191 zcmchb_dA>4AI2ks7*%`kU5eOL>>Z^>?G-AuiP55z*jw!plo~awW@#xgWAE0AqIPL* zHLCsQ^G|$#IM2Dx_5ARh_j%se>%Q-kU}UIshm3^`007+4)73P=Iv9w7n?A zPXzuZI_iM>3AR1_0_37*pauXmz9RqQNQ7ULB6Y3&0RYOr{{{ipr^*=spvCEFsyz;} z|5+H4Hu;4W`|cO@SN_`mr`e;iV)|JgIZWBlb*rMs`U5x%7T*rfjWBsJX5*_5#q@aWclb@Jxm`26!h*y5I_;?6C$(m!~@|Mh8SvHygBSF_&r z@73_ypmq(jQ-`}cMT_cG$#Ddv5v7Zbu*u!;H+*E6_`bL=5a5IgNwXq4NP-{ zujvr?vALmvO2>o2R`rczUu>(#{9EKfBNlc7!64U*0>9-;B1U5Gup*C%7;TZ0O21n? z7c-dqUcwkDyuNkjYscn&6*jA}c>fxWhCQ)Te^WOlnF_i%TvZ9V@a$wur8Si278gI9 zRQdO3|9y8dZXL*f`1!Xz3^t-CSQPN*7^@#{ZM}q+@yJ^O6P0{=aqf;2Wljpay}rHP ze~)M@zb_v-Mti8qFpV___>tBATx#9-#j<0sQ*e$1twP1hFCP>f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7~T^}G(~uD+fxwLr`hsscPfG#g`1~=AV%nf%EuUb_7oHpScbM7xAmFmmB@t|8zz)O zE{+~nB+q{e*i+BjupI&Y7jlm8g?cVD5D4=0okjvdM&7GkFNX}wYU}MfWXnYWW-Ml^ zgbpJtwHN)yi(vR|JI$JMFx481^`?&Pdro?JC8`ot#VJt(as(x9yCWT5aezn|fVBO};-fvWr zgwbI#v+evrUsuKp^|pFMm7RjZC&GaJuPMn5ctK=4ek*gS!AeOBrIf%8;?~dnrX~yI zeAX}#S=?~EWe-hXHx$?sJl_=7=5|*7rp0LI954_UB$M5b-vn1CcN;gwYWTmG7ZEJJ zWMQ0g-nM>zl3OXPa_ZW64R5E=PG!q4E>>}$6Y9Ud_*wA!^~9Bi$#R*_tFf`MHyUxh zce2j*=U*w>F2OKwUT{8^1>%W?WdzE1=oueGpgiyw60#m&>$0-w*sLEvZVA{kNo7gp zicOo_*tKqTSNiwo)XmMUVW8r(`xoI`Db1kpgN4QmNg;v*09-g>Jul?&^E{mh5n9&k z)61LZ-^TC>650`vJ2S!9E$593!iV|m@DTZ9>WPsNo@(rXF3+Hu?^d=&#)2xxa)m*G zEHp~z6-Nq0qa@RYo0qrDw9>FDlGPrWYwJgfQ{^D_n6I~M9R}LasB8Tb-8EA48@^WP z@-3x2Lk3bUk(sbO)8Eh>0qX<)!8n-hC|uJhQieS4JB*m5a)7F8R>%b7N3;PP{Y2MI zEnuK4fnWX~Eh{l|aR*yGNNa}T%cs^L1kbAH8Fps^xTqe1@jvb#oA5IKpW>+h)16mk cmC4q>x; export const contentToData = ( diff --git a/dapps/identifyDapp.ts b/dapps/identifyDapp.ts index 3a39a187..3f058c31 100644 --- a/dapps/identifyDapp.ts +++ b/dapps/identifyDapp.ts @@ -1,9 +1,11 @@ import { NetworkType } from "@airgap/beacon-sdk"; import { PREFERED_NETWORK } from "../context/config"; +import { objktContractsMatcher } from "./objkt"; import { tezosDomainsContractsMatcher } from "./tezosDomains"; export enum Dapp { TEZOS_DOMAINS = "TEZOS_DOMAINS", + OBJKT = "OBJKT", } export function identifyDapp(contract: string): Dapp | undefined { @@ -13,6 +15,12 @@ export function identifyDapp(contract: string): Dapp | undefined { : tezosDomainsContractsMatcher.ghostnet)[contract] ) { return Dapp.TEZOS_DOMAINS; + } else if ( + (PREFERED_NETWORK === NetworkType.MAINNET + ? objktContractsMatcher.mainnet + : objktContractsMatcher.ghostnet)[contract] + ) { + return Dapp.OBJKT; } else { return undefined; } diff --git a/dapps/objkt.tsx b/dapps/objkt.tsx new file mode 100644 index 00000000..3a82d9dc --- /dev/null +++ b/dapps/objkt.tsx @@ -0,0 +1,476 @@ +import { Parser } from "@taquito/michel-codec"; +import { Schema } from "@taquito/michelson-encoder"; +import { bytes2Char } from "@taquito/tzip16"; +import { contracts, CustomViewData, CustomView } from "."; +import logo from "../assets/images/objkt.png"; +import Alias from "../components/Alias"; +import { transaction } from "../components/RenderProposalContentLambda"; +import { mutezToTez } from "../utils/tez"; + +const parser = new Parser(); + +function makeNftImageUrl(contract: string, id: string) { + return `https://assets.objkt.media/file/assets-003/${contract}/${id}/thumb288`; +} + +export const MARKETPLACE_V4 = { + mainnet: "KT1WvzYHCNBvDSdwafTHv7nJ1dWmZ8GCYuuC", + ghostnet: "", + name: "Marketplace", +}; + +export const askSchema = new Schema( + parser.parseMichelineExpression( + `(pair %ask (pair %token (address %address) (nat %token_id)) + (pair + (or %currency (address %fa12) + (or (pair %fa2 (address %address) (nat %token_id)) (unit %tez))) + (pair (nat %amount) + (pair (nat %editions) + (pair (list %shares (pair (nat %amount) (address %recipient))) + (pair (option %expiry_time timestamp) (option %target address)))))))` + )! +); + +export const fullfilAskSchema = new Schema( + parser.parseMichelineExpression( + `(pair %fulfill_ask (nat %ask_id) (option %proxy address))` + )! +); + +export const fullfilOfferSchema = new Schema( + parser.parseMichelineExpression( + `(pair %fulfill_offer (nat %offer_id) (option %token_id nat))` + )! +); + +export const offerSchema = new Schema( + parser.parseMichelineExpression( + `(pair %offer (pair %token (address %address) (option %token_id nat)) + (pair + (or %currency (address %fa12) + (or (pair %fa2 (address %address) (nat %token_id)) (unit %tez))) + (pair (nat %amount) + (pair (list %shares (pair (nat %amount) (address %recipient))) + (pair (option %expiry_time timestamp) + (pair (option %target address) (option %proxy address)))))))` + )! +); + +export const retractAskSchema = new Schema( + parser.parseMichelineExpression(`(nat %retract_ask)`)! +); + +export const retractOfferSchema = new Schema( + parser.parseMichelineExpression(`(nat %retract_offer)`)! +); + +export const ENGLISH_AUCTION_V4 = { + mainnet: "KT18p94vjkkHYY3nPmernmgVR7HdZFzE7NAk", + ghostnet: "", + name: "English auction", +}; + +export const englishBidSchema = new Schema( + parser.parseMichelineExpression( + `(pair %bid (nat %auction_id) (nat %amount))` + )! +); +export const englishCancelAuctionSchema = new Schema( + parser.parseMichelineExpression(`(nat %cancel_auction)`)! +); +export const englishCreateAuctionSchema = new Schema( + parser.parseMichelineExpression(`(pair %create_auction (pair %token (address %address) (nat %token_id)) + (pair + (or %currency (address %fa12) + (or (pair %fa2 (address %address) (nat %token_id)) (unit %tez))) + (pair (nat %reserve) + (pair (timestamp %start_time) + (pair (timestamp %end_time) + (pair (nat %extension_time) + (pair (nat %price_increment) + (list %shares (pair (nat %amount) + (address %recipient))))))))))`)! +); +export const settleAuctionSchema = new Schema( + parser.parseMichelineExpression(`(nat %settle_auction)`)! +); + +export const DUTCH_AUCTION_V4 = { + mainnet: "KT1XXu88HkNzQRHNgAf7Mnq68LyS9MZJNoHP", + ghostnet: "", + name: "Dutch auction", +}; + +export const dutchBuySchema = new Schema( + parser.parseMichelineExpression( + `(pair %buy (nat %auction_id) (pair (nat %amount) (option %proxy address)))` + )! +); + +export const dutchCancelAuctionSchema = new Schema( + parser.parseMichelineExpression(`(nat %cancel_auction)`)! +); +export const dutchCreateAuctionSchema = new Schema( + parser.parseMichelineExpression(`(pair %create_auction (pair %token (address %address) (nat %token_id)) + (pair + (or %currency (address %fa12) + (or (pair %fa2 (address %address) (nat %token_id)) (unit %tez))) + (pair (nat %editions) + (pair (timestamp %start_time) + (pair (timestamp %end_time) + (pair (nat %start_price) + (pair (nat %end_price) + (list %shares (pair (nat %amount) + (address %recipient))))))))))`)! +); + +export const objktContracts = { + MARKETPLACE_V4, + ENGLISH_AUCTION_V4, + DUTCH_AUCTION_V4, +}; + +export const objktContractsMatcher: contracts = { + mainnet: {}, + ghostnet: {}, +}; + +export function tezosDomains(transactions: Array): CustomView { + if ( + !transactions.every( + ({ addresses }) => + !!addresses && + (objktContractsMatcher.mainnet[addresses] || + objktContractsMatcher.ghostnet[addresses]) + ) + ) + return undefined; + + return { + logo: logo.src, + logoLink: "https://objkt.com/", + logoAlt: "Objkt", + label: transactions + .flatMap(({ addresses }) => { + if (!addresses) return []; + + return [ + (() => { + switch (addresses) { + case MARKETPLACE_V4.mainnet: + case MARKETPLACE_V4.ghostnet: + return MARKETPLACE_V4.name; + case ENGLISH_AUCTION_V4.mainnet: + case ENGLISH_AUCTION_V4.ghostnet: + return ENGLISH_AUCTION_V4.name; + case DUTCH_AUCTION_V4.mainnet: + case DUTCH_AUCTION_V4.ghostnet: + return DUTCH_AUCTION_V4.name; + default: + return "Interaction with Objkt"; + } + })(), + ]; + }) + .join(", "), + data: transactions.flatMap(transaction => { + if (!transaction.params || !transaction.entrypoints) return []; + + const price = transaction.amount; + const micheline = parser.parseMichelineExpression(transaction.params); + + if (!micheline) return []; + + switch (transaction.addresses) { + case MARKETPLACE_V4.mainnet: + case MARKETPLACE_V4.ghostnet: { + switch (transaction.entrypoints) { + case "ask": { + const data = askSchema.Execute(micheline); + + const unit = "tez" in data.currency ? "Tez" : ""; + + return [ + { + image: makeNftImageUrl( + data.token.address, + data.token.token_id + ), + action: "Ask", + description: ( +
    +
  • + Price: {data.amount} {unit} +
  • + {!!data.expiry_time ? ( +
  • + Expiration date:{" "} + {new Date(data.expiry_time).toLocaleString()} +
  • + ) : null} +
+ ), + price, + }, + ]; + } + case "offer": { + const data = offerSchema.Execute(micheline); + + const unit = "tez" in data.currency ? "Tez" : ""; + + return [ + { + image: makeNftImageUrl( + data.token.address, + data.token.token_id + ), + action: "Offer", + description: ( +
    +
  • + Price: {data.amount} {unit} +
  • + {!!data.expiry_time ? ( +
  • + Expiration date:{" "} + {new Date(data.expiry_time).toLocaleString()} +
  • + ) : null} +
+ ), + price, + }, + ]; + } + case "fullfil_ask": { + const data = fullfilAskSchema.Execute(micheline); + + return [ + { + action: "Fullfil ask", + description: ( +
    +
  • Ask id: {data.ask_id}
  • +
+ ), + price, + }, + ]; + } + case "fullfil_offer": { + const data = fullfilOfferSchema.Execute(micheline); + + return [ + { + action: "Fullfil offer", + description: ( +
    +
  • Offer id: {data.offer_id}
  • +
+ ), + price, + }, + ]; + } + case "retract_ask": { + const data = retractAskSchema.Execute(micheline); + + return [ + { + action: "Retract ask", + description: ( +
    +
  • Ask id: {data.retract_ask}
  • +
+ ), + price, + }, + ]; + } + case "retract_offer": { + const data = retractOfferSchema.Execute(micheline); + + return [ + { + action: "Retract offer", + description: ( +
    +
  • Ask id: {data.retract_offer}
  • +
+ ), + price, + }, + ]; + } + + default: + return []; + } + } + case ENGLISH_AUCTION_V4.mainnet: + case ENGLISH_AUCTION_V4.ghostnet: { + switch (transaction.entrypoints) { + case "bid": { + const data = englishBidSchema.Execute(micheline); + + return [ + { + action: "Bid", + description: ( +
    +
  • Auction id: {data.auction_id}
  • +
  • Amount: {data.amount}
  • +
+ ), + price, + }, + ]; + } + case "create_auction": { + const data = englishCreateAuctionSchema.Execute(micheline); + + const unit = "tez" in data.currency ? "Tez" : ""; + + return [ + { + image: makeNftImageUrl( + data.token.address, + data.token.token_id + ), + action: "Create english auction", + description: ( +
    +
  • + Reserve price: {data.amount} {unit} +
  • +
  • + Price increment: {data.price_increment} {unit} +
  • +
  • + Start time: {new Date(data.start_time).toLocaleString()} +
  • +
  • + End time: {new Date(data.end_time).toLocaleString()} +
  • +
  • Extension time: {data.extension_time}
  • +
+ ), + price, + }, + ]; + } + case "cancel_auction": { + const data = englishCancelAuctionSchema.Execute(micheline); + + return [ + { + action: "Cancel english auction", + description: ( +
    +
  • Auction id: {data}
  • +
+ ), + price, + }, + ]; + } + case "settle_auction": { + const data = englishCancelAuctionSchema.Execute(micheline); + + return [ + { + action: "Settle english auction", + description: ( +
    +
  • Auction id: {data}
  • +
+ ), + price, + }, + ]; + } + default: + []; + } + } + case DUTCH_AUCTION_V4.ghostnet: + case DUTCH_AUCTION_V4.mainnet: { + switch (transaction.entrypoints) { + case "buy": { + const data = englishBidSchema.Execute(micheline); + + return [ + { + action: "Buy", + description: ( +
    +
  • Auction id: {data.auction_id}
  • +
  • Amount: {data.amount}
  • +
+ ), + price, + }, + ]; + } + case "create_auction": { + const data = englishCreateAuctionSchema.Execute(micheline); + + const unit = "tez" in data.currency ? "Tez" : ""; + + return [ + { + image: makeNftImageUrl( + data.token.address, + data.token.token_id + ), + action: "Create english auction", + description: ( +
    +
  • + Reserve price: {data.amount} {unit} +
  • +
  • + Start price: {data.start_price} {unit} +
  • +
  • + End price: {data.end_price} {unit} +
  • +
  • + Start time: {new Date(data.start_time).toLocaleString()} +
  • +
  • + End time: {new Date(data.end_time).toLocaleString()} +
  • +
+ ), + price, + }, + ]; + } + case "cancel_auction": { + const data = englishCancelAuctionSchema.Execute(micheline); + + return [ + { + action: "Cancel dutch auction", + description: ( +
    +
  • Auction id: {data}
  • +
+ ), + price, + }, + ]; + } + default: + []; + } + } + default: + return []; + } + }), + }; +} diff --git a/dapps/tezosDomains.tsx b/dapps/tezosDomains.tsx index d58abc70..ff4ae2ad 100644 --- a/dapps/tezosDomains.tsx +++ b/dapps/tezosDomains.tsx @@ -5,6 +5,7 @@ import { contracts, CustomViewData, CustomView } from "."; import logo from "../assets/images/TezosDomains.svg"; import Alias from "../components/Alias"; import { transaction } from "../components/RenderProposalContentLambda"; +import { mutezToTez } from "../utils/tez"; const parser = new Parser(); @@ -38,46 +39,152 @@ export const CLAIM_REVERSE_RECORD = { name: "Set domain's target", }; +export const checkAddressSchema = new Schema( + parser.parseMichelineExpression( + "(pair %check_address (bytes %name) (address %address))" + )! +); + +export const CHECK_ADDRESS = { + mainnet: "KT1F7JKNqwaoLzRsMio1MQC7zv3jG9dHcDdJ", + ghostnet: "KT1B3j3At2XMF5P8bVoPD2WeJbZ9eaPiu3pD", + name: "Check address", +}; + +export const setChildrenRecordSchema = new Schema( + parser.parseMichelineExpression( + `(pair %set_child_record (bytes %label) + (pair (bytes %parent) + (pair (option %address address) + (pair (address %owner) + (pair (map %data string bytes) (option %expiry timestamp))))))` + )! +); + +export const SET_CHILDREN_RECORD = { + mainnet: "KT1QHLk1EMUA8BPH3FvRUeUmbTspmAhb7kpd", + ghostnet: "KT1HpddfW7rX5aT2cTdsDaQZnH46bU7jQSTU", + name: "Set children record", +}; + +export const updateRecordSchema = new Schema( + parser.parseMichelineExpression( + `(pair %update_record (bytes %name) + (pair (option %address address) + (pair (address %owner) (map %data string bytes))))` + )! +); + +export const UPDATE_RECORD = { + mainnet: "KT1H1MqmUM4aK9i1833EBmYCCEfkbt6ZdSBc", + ghostnet: "KT1Ln4t64RdCG1bK8zkH6Xi4nNQVxz7qNgyj", + name: "Update record", +}; + +export const updateReverseRecordSchema = new Schema( + parser.parseMichelineExpression( + `(pair %update_reverse_record (address %address) (pair (option %name bytes) (address %owner)))` + )! +); + +export const UPDATE_REVERSE_RECORD = { + mainnet: "KT1J9VpjiH5cmcsskNb8gEXpBtjD4zrAx4Vo", + ghostnet: "KT1HDUc2xtPHqWQcjE1WuinTTHajXQN3asdk", + name: "Update reverse record", +}; + +export const renewSchema = new Schema( + parser.parseMichelineExpression( + `(pair %renew (bytes %label) (nat %duration))` + )! +); + +export const RENEW = { + mainnet: "KT1EVYBj3f1rZHNeUtq4ZvVxPTs77wuHwARU", + ghostnet: "KT1Bv32pdMYmBJeMa2HsyUQZiC6FNj1dX6VR", + name: "Renew domain", +}; + +export const bidSchema = new Schema( + parser.parseMichelineExpression(`(pair %bid (bytes %label) (mutez %bid))`)! +); + +export const BID = { + mainnet: "KT1CaSP4dn8wasbMsfdtGiCPgYFW7bvnPRRT", + ghostnet: "KT1P3wdbusZK2sj16YXxRViezzWCPXpiE28P", + name: "Bid", +}; + +export const withdrawSchema = new Schema( + parser.parseMichelineExpression(`(address %withdraw)`)! +); + +export const WITHDRAW = { + mainnet: "KT1CfuAbJQbAGYcjKfvEvbtNUx45LY5hfTVR", + ghostnet: "KT1C7EF4c1pnPW9qcfNRiTPj5tBFMQJtvUhq", + name: "Withdraw", +}; + +export const settleSchema = new Schema( + parser.parseMichelineExpression(`(pair %settle (bytes %label) + (pair (address %owner) (pair (option %address address) (map %data string bytes))))`)! +); + +export const SETTLE = { + mainnet: "KT1MeFfi4TzSCc8CF9j3qq5mecTPdc6YVUPp", + ghostnet: "KT1DMNPg3b3fJQpjXULcXjucEXfwq3zGTKGo", + name: "Settle", +}; + export const tezosDomainsContracts = { COMMIT_ADDRESS, BUY_ADDRESS, CLAIM_REVERSE_RECORD, + UPDATE_REVERSE_RECORD, + UPDATE_RECORD, + BID, + SETTLE, + WITHDRAW, + RENEW, + SET_CHILDREN_RECORD, + CHECK_ADDRESS, }; export const tezosDomainsContractsMatcher: contracts = { mainnet: { - KT1F7JKNqwaoLzRsMio1MQC7zv3jG9dHcDdJ: true, - KT1QHLk1EMUA8BPH3FvRUeUmbTspmAhb7kpd: true, - KT1H1MqmUM4aK9i1833EBmYCCEfkbt6ZdSBc: true, - KT1TnTr6b2YxSx2xUQ8Vz3MoWy771ta66yGx: true, - KT1J9VpjiH5cmcsskNb8gEXpBtjD4zrAx4Vo: true, + [CHECK_ADDRESS.mainnet]: true, + [SET_CHILDREN_RECORD.mainnet]: true, + [UPDATE_RECORD.mainnet]: true, + [CLAIM_REVERSE_RECORD.mainnet]: true, + [UPDATE_REVERSE_RECORD.mainnet]: true, [BUY_ADDRESS.mainnet]: true, - KT1EVYBj3f1rZHNeUtq4ZvVxPTs77wuHwARU: true, - KT1P8n2qzJjwMPbHJfi4o8xu6Pe3gaU3u2A3: true, - KT1CaSP4dn8wasbMsfdtGiCPgYFW7bvnPRRT: true, - KT1CfuAbJQbAGYcjKfvEvbtNUx45LY5hfTVR: true, - KT1MeFfi4TzSCc8CF9j3qq5mecTPdc6YVUPp: true, + [RENEW.mainnet]: true, + [COMMIT_ADDRESS.mainnet]: true, + [BID.mainnet]: true, + [WITHDRAW.mainnet]: true, + [SETTLE.mainnet]: true, KT1GY5qCWwmESfTv9dgjYyTYs2T5XGDSvRp1: true, KT1R4KPQxpFHAkX8MKCFmdoiqTaNSSpnJXPL: true, KT1Lu5om8u4ns2VWxcufgQRzjaLLhh3Qvf5B: true, KT1VxKQbYBVD8fSkqaewJGigL3tmcLWrsXcu: true, }, ghostnet: { - KT1B3j3At2XMF5P8bVoPD2WeJbZ9eaPiu3pD: true, - KT1HpddfW7rX5aT2cTdsDaQZnH46bU7jQSTU: true, - KT1Ln4t64RdCG1bK8zkH6Xi4nNQVxz7qNgyj: true, - KT1H19ouy5QwDBchKXcUw1QRFs5ZYyx1ezEJ: true, - KT1HDUc2xtPHqWQcjE1WuinTTHajXQN3asdk: true, + [CHECK_ADDRESS.ghostnet]: true, + [SET_CHILDREN_RECORD.ghostnet]: true, + [UPDATE_RECORD.ghostnet]: true, + [CLAIM_REVERSE_RECORD.ghostnet]: true, + [UPDATE_REVERSE_RECORD.ghostnet]: true, [BUY_ADDRESS.ghostnet]: true, - KT1Bv32pdMYmBJeMa2HsyUQZiC6FNj1dX6VR: true, - KT1PEnPDgGKyHvaGzWj6VJJYwobToiW2frff: true, - KT1P3wdbusZK2sj16YXxRViezzWCPXpiE28P: true, - KT1C7EF4c1pnPW9qcfNRiTPj5tBFMQJtvUhq: true, - KT1DMNPg3b3fJQpjXULcXjucEXfwq3zGTKGo: true, + [RENEW.ghostnet]: true, + [COMMIT_ADDRESS.ghostnet]: true, + [BID.ghostnet]: true, + [WITHDRAW.ghostnet]: true, + [SETTLE.ghostnet]: true, }, }; export function tezosDomains(transactions: Array): CustomView { + console.log(transactions); if ( !transactions.every( ({ addresses }) => @@ -108,6 +215,31 @@ export function tezosDomains(transactions: Array): CustomView { case CLAIM_REVERSE_RECORD.mainnet: case CLAIM_REVERSE_RECORD.ghostnet: return CLAIM_REVERSE_RECORD.name; + case UPDATE_REVERSE_RECORD.mainnet: + case UPDATE_REVERSE_RECORD.ghostnet: + return UPDATE_REVERSE_RECORD.name; + case UPDATE_RECORD.mainnet: + case UPDATE_RECORD.ghostnet: + return UPDATE_RECORD.name; + case BID.mainnet: + case BID.ghostnet: + return BID.name; + case SETTLE.mainnet: + case SETTLE.ghostnet: + return SETTLE.name; + case WITHDRAW.mainnet: + case WITHDRAW.ghostnet: + return WITHDRAW.name; + case RENEW.mainnet: + case RENEW.ghostnet: + return RENEW.name; + case SET_CHILDREN_RECORD.mainnet: + case SET_CHILDREN_RECORD.ghostnet: + return SET_CHILDREN_RECORD.name; + case CHECK_ADDRESS.mainnet: + case CHECK_ADDRESS.ghostnet: + return CHECK_ADDRESS.name; + default: return "Interaction with Tezos Domains"; } @@ -217,6 +349,181 @@ export function tezosDomains(transactions: Array): CustomView { }, ]; } + case UPDATE_REVERSE_RECORD.mainnet: + case UPDATE_REVERSE_RECORD.ghostnet: { + const data = updateReverseRecordSchema.Execute(micheline); + + const domain = bytes2Char(data.name?.Some ?? ""); + + return [ + { + action: UPDATE_REVERSE_RECORD.name, + description: ( +
    +
  • + Owner: +
  • +
  • + Address: +
  • + {!!data.name?.Some && ( +
  • + Domain:{" "} + + {domain} + +
  • + )} +
+ ), + price, + }, + ]; + } + case UPDATE_RECORD.mainnet: + case UPDATE_RECORD.ghostnet: { + const data = updateRecordSchema.Execute(micheline); + + const recordName = bytes2Char(data.name); + const updateData = JSON.stringify(data.data); + + return [ + { + action: UPDATE_RECORD.name, + description: ( +
    +
  • Record name: {recordName}
  • +
  • + Address: +
  • +
  • Data: {updateData}
  • +
+ ), + price, + }, + ]; + } + case BID.mainnet: + case BID.ghostnet: { + const data = bidSchema.Execute(micheline); + + return [ + { + action: BID.name, + description: ( +
    +
  • Label: {data.label}
  • +
  • Bid: {mutezToTez(data.bid)} Tez
  • +
+ ), + price, + }, + ]; + } + case SETTLE.mainnet: + case SETTLE.ghostnet: { + const data = settleSchema.Execute(micheline); + + return [ + { + action: SETTLE.name, + description: ( +
    +
  • Label: {data.label}
  • +
  • + Owner: +
  • +
+ ), + price, + }, + ]; + } + case WITHDRAW.mainnet: + case WITHDRAW.ghostnet: { + const data = withdrawSchema.Execute(micheline); + + return [ + { + action: WITHDRAW.name, + description: ( +
    +
  • + Withdraw address: +
  • +
+ ), + price, + }, + ]; + } + case RENEW.mainnet: + case RENEW.ghostnet: { + const data = renewSchema.Execute(micheline); + + return [ + { + action: RENEW.name, + description: ( +
    +
  • Label: {bytes2Char(data.label)}
  • +
  • + Duration: {data.duration} day{data.duration <= 1 ? "" : "s"} +
  • +
+ ), + price, + }, + ]; + } + case SET_CHILDREN_RECORD.mainnet: + case SET_CHILDREN_RECORD.ghostnet: { + const data = setChildrenRecordSchema.Execute(micheline); + + return [ + { + action: SET_CHILDREN_RECORD.name, + description: ( +
    +
  • Label: {bytes2Char(data.label)}
  • +
  • Parent: {bytes2Char(data.owner)}
  • +
  • + Owner: +
  • +
+ ), + price, + }, + ]; + } + case CHECK_ADDRESS.mainnet: + case CHECK_ADDRESS.ghostnet: { + const data = checkAddressSchema.Execute(micheline); + + return [ + { + action: CHECK_ADDRESS.name, + description: ( +
    +
  • Name: {bytes2Char(data.name)}
  • +
  • + Address: {" "} +
  • +
+ ), + price, + }, + ]; + } + default: return []; } diff --git a/pages/[walletAddress]/proposals.tsx b/pages/[walletAddress]/proposals.tsx index 5e6ec9ad..6999048e 100644 --- a/pages/[walletAddress]/proposals.tsx +++ b/pages/[walletAddress]/proposals.tsx @@ -353,7 +353,7 @@ const Proposals = () => { return ( Date: Fri, 12 Jan 2024 16:12:52 +0900 Subject: [PATCH 02/21] feat(Dapps): Tezos domains is working --- components/Alias.tsx | 1 + components/PoeModal.tsx | 15 +++++++------- components/ProposalCard.tsx | 11 ++++++++--- dapps/index.ts | 3 ++- dapps/objkt.tsx | 39 +++++++++++++++++++++---------------- dapps/tezosDomains.tsx | 33 ++++++++++++++++++------------- 6 files changed, 61 insertions(+), 41 deletions(-) diff --git a/components/Alias.tsx b/components/Alias.tsx index 738832e9..34a25ebb 100644 --- a/components/Alias.tsx +++ b/components/Alias.tsx @@ -14,6 +14,7 @@ const Alias = ({ disabled?: boolean; }) => { const state = useContext(AppStateContext)!; + console.log("ADDRESS:", address); const formatted = useMemo( () => diff --git a/components/PoeModal.tsx b/components/PoeModal.tsx index 55cb8b58..bd3eb26e 100644 --- a/components/PoeModal.tsx +++ b/components/PoeModal.tsx @@ -3,7 +3,6 @@ import { BeaconErrorType, NetworkType, OperationRequestOutput, - ProofOfEventChallengeRequest, ProofOfEventChallengeRequestOutput, SignPayloadRequest, TezosOperationType, @@ -24,7 +23,7 @@ import { } from "../context/generateLambda"; import fetchVersion from "../context/metadata"; import { AppDispatchContext, AppStateContext } from "../context/state"; -import Beacon, { State } from "../pages/[walletAddress]/beacon"; +import { State } from "../pages/[walletAddress]/beacon"; import { proposalContent } from "../types/display"; import useWalletTokens from "../utils/useWalletTokens"; import { signers, toStorage, VersionedApi } from "../versioned/apis"; @@ -213,11 +212,13 @@ const PoeModal = () => { setTransactionError(errorMessage); console.log("Contract conversion error:", e); - state.p2pClient?.sendError( - message.id, - errorMessage, - BeaconErrorType.TRANSACTION_INVALID_ERROR - ); + state.p2pClient + ?.sendError( + message.id, + errorMessage, + BeaconErrorType.TRANSACTION_INVALID_ERROR + ) + .catch(_ => {}); return undefined; } } else { diff --git a/components/ProposalCard.tsx b/components/ProposalCard.tsx index bd25210f..c9d41a50 100644 --- a/components/ProposalCard.tsx +++ b/components/ProposalCard.tsx @@ -44,6 +44,7 @@ const ProposalCard = ({ isSignable = false, shouldResolve = false, }: ProposalCardProps) => { + console.log(content); const state = useContext(AppStateContext)!; const currentContract = state.currentContract ?? ""; @@ -72,9 +73,13 @@ const ProposalCard = ({ let dapp: CustomView; - for (let i = 0; i < customViewMatchers.length; ++i) { - dapp = customViewMatchers[i](rows as transaction[]); - if (!!dapp) break; + try { + for (let i = 0; i < customViewMatchers.length; ++i) { + dapp = customViewMatchers[i](rows as transaction[]); + if (!!dapp) break; + } + } catch (e) { + console.log("Failed to parse dapp:", e); } return { rows, dapp }; }, [content, state.currentContract, state.currentStorage, state.contracts]); diff --git a/dapps/index.ts b/dapps/index.ts index 057a3c67..536818fd 100644 --- a/dapps/index.ts +++ b/dapps/index.ts @@ -1,5 +1,6 @@ import { ReactNode } from "react"; import { transaction } from "../components/RenderProposalContentLambda"; +import { objkt } from "./objkt"; import { tezosDomains } from "./tezosDomains"; export type contracts = { @@ -27,4 +28,4 @@ export type CustomView = export const customViewMatchers: Array< (transactions: Array) => CustomView -> = [tezosDomains]; +> = [tezosDomains, objkt]; diff --git a/dapps/objkt.tsx b/dapps/objkt.tsx index 3a82d9dc..1b6ef75b 100644 --- a/dapps/objkt.tsx +++ b/dapps/objkt.tsx @@ -1,11 +1,8 @@ import { Parser } from "@taquito/michel-codec"; import { Schema } from "@taquito/michelson-encoder"; -import { bytes2Char } from "@taquito/tzip16"; import { contracts, CustomViewData, CustomView } from "."; import logo from "../assets/images/objkt.png"; -import Alias from "../components/Alias"; import { transaction } from "../components/RenderProposalContentLambda"; -import { mutezToTez } from "../utils/tez"; const parser = new Parser(); @@ -15,7 +12,7 @@ function makeNftImageUrl(contract: string, id: string) { export const MARKETPLACE_V4 = { mainnet: "KT1WvzYHCNBvDSdwafTHv7nJ1dWmZ8GCYuuC", - ghostnet: "", + ghostnet: "KT1AiEcg7D2Jm9GKDgguVLBwRPjzjkkPpwds", name: "Marketplace", }; @@ -32,13 +29,13 @@ export const askSchema = new Schema( )! ); -export const fullfilAskSchema = new Schema( +export const fulfilAskSchema = new Schema( parser.parseMichelineExpression( `(pair %fulfill_ask (nat %ask_id) (option %proxy address))` )! ); -export const fullfilOfferSchema = new Schema( +export const fulfilOfferSchema = new Schema( parser.parseMichelineExpression( `(pair %fulfill_offer (nat %offer_id) (option %token_id nat))` )! @@ -67,7 +64,7 @@ export const retractOfferSchema = new Schema( export const ENGLISH_AUCTION_V4 = { mainnet: "KT18p94vjkkHYY3nPmernmgVR7HdZFzE7NAk", - ghostnet: "", + ghostnet: "KT1AiEcg7D2Jm9GKDgguVLBwRPjzjkkPpwds", name: "English auction", }; @@ -98,7 +95,7 @@ export const settleAuctionSchema = new Schema( export const DUTCH_AUCTION_V4 = { mainnet: "KT1XXu88HkNzQRHNgAf7Mnq68LyS9MZJNoHP", - ghostnet: "", + ghostnet: "KT18gCSfQZQHEu8pkzkkxuTLiE8ZAVUc1kSe", name: "Dutch auction", }; @@ -132,11 +129,19 @@ export const objktContracts = { }; export const objktContractsMatcher: contracts = { - mainnet: {}, - ghostnet: {}, + mainnet: { + [MARKETPLACE_V4.mainnet]: true, + [ENGLISH_AUCTION_V4.mainnet]: true, + [DUTCH_AUCTION_V4.mainnet]: true, + }, + ghostnet: { + [MARKETPLACE_V4.ghostnet]: true, + [ENGLISH_AUCTION_V4.ghostnet]: true, + [DUTCH_AUCTION_V4.ghostnet]: true, + }, }; -export function tezosDomains(transactions: Array): CustomView { +export function objkt(transactions: Array): CustomView { if ( !transactions.every( ({ addresses }) => @@ -244,12 +249,12 @@ export function tezosDomains(transactions: Array): CustomView { }, ]; } - case "fullfil_ask": { - const data = fullfilAskSchema.Execute(micheline); + case "fulfill_ask": { + const data = fulfilAskSchema.Execute(micheline); return [ { - action: "Fullfil ask", + action: "Fulfill ask", description: (