From ff7475d01917349450599ad80b55133d502b1fdd Mon Sep 17 00:00:00 2001 From: SULTAN PEYEK Date: Fri, 16 Jul 2021 12:58:28 +0700 Subject: [PATCH] Implement Bonfida Twitter Handling --- js/packages/web/package.json | 4 ++- js/packages/web/src/views/auction/index.tsx | 37 +++++++++++++++++++-- js/yarn.lock | 19 +++++++++++ 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/js/packages/web/package.json b/js/packages/web/package.json index 6cb1439..fd5d764 100644 --- a/js/packages/web/package.json +++ b/js/packages/web/package.json @@ -4,6 +4,7 @@ "dependencies": { "@ant-design/icons": "^4.4.0", "@babel/preset-typescript": "^7.12.13", + "@bonfida/spl-name-service": "0.1.12", "@cloudflare/stream-react": "^1.1.0", "@craco/craco": "^5.7.0", "@oyster/common": "0.0.1", @@ -88,7 +89,8 @@ "gh-pages": "^3.1.0", "npm-link-shared": "0.5.6", "prettier": "^2.1.2", - "typescript": "^4.1.3" + "typescript": "^4.1.3", + "webpack-dev-server": "3.11.0" }, "peerDependencies": { "react": "*", diff --git a/js/packages/web/src/views/auction/index.tsx b/js/packages/web/src/views/auction/index.tsx index f7f91c6..0a8b4b1 100644 --- a/js/packages/web/src/views/auction/index.tsx +++ b/js/packages/web/src/views/auction/index.tsx @@ -1,7 +1,8 @@ -import React, { useRef, useState } from 'react'; +import React, { useRef, useState, useEffect } from 'react'; import { useParams } from 'react-router-dom'; import { Row, Col, Button, Skeleton, Carousel } from 'antd'; import { AuctionCard } from '../../components/AuctionCard'; +import { Connection, PublicKey } from '@solana/web3.js'; import { AuctionView as Auction, AuctionViewItem, @@ -19,6 +20,7 @@ import { Identicon, MetaplexModal, shortenAddress, + useConnection, useConnectionConfig, fromLamports, useMint, @@ -26,6 +28,7 @@ import { AuctionState, } from '@oyster/common'; import { MintInfo } from '@solana/spl-token'; +import { getHandleAndRegistryKey } from '@bonfida/spl-name-service'; import useWindowDimensions from '../../utils/layout'; import { CheckOutlined } from '@ant-design/icons'; import { useMemo } from 'react'; @@ -202,6 +205,28 @@ const BidLine = (props: { bid: any; index: number; mint?: MintInfo, isCancelled? const bidder = bid.info.bidderPubkey.toBase58(); const isme = wallet?.publicKey?.toBase58() === bidder; + // Get Twitter Handle from address + const connection = useConnection(); + const [bidderTwitterHandle, setBidderTwitterHandle] = useState(''); + useEffect(() => { + const getTwitterHandle = async ( + connection: Connection, + bidder: PublicKey, + ): Promise => { + try { + const [twitterHandle] = await getHandleAndRegistryKey( + connection, + bidder, + ); + setBidderTwitterHandle(twitterHandle); + } catch (err) { + console.warn(`err`); + return undefined; + } + }; + getTwitterHandle(connection, bidder); + }, [bidderTwitterHandle]); + return ( {' '} - {shortenAddress(bidder)} + {bidderTwitterHandle ? ( + {`@${bidderTwitterHandle}`} + ) : ( + shortenAddress(bidder) + )} {isme &&  (you)} diff --git a/js/yarn.lock b/js/yarn.lock index 2455cb9..7b48755 100644 --- a/js/yarn.lock +++ b/js/yarn.lock @@ -1247,6 +1247,25 @@ "@babel/helper-validator-identifier" "^7.14.0" to-fast-properties "^2.0.0" +"@bonfida/spl-name-service@0.1.12": + version "0.1.12" + resolved "https://registry.npmjs.org/@bonfida/spl-name-service/-/spl-name-service-0.1.12.tgz#ab186fe0c907efe66cb6818e2f429f9f4b3ab0d2" + integrity sha512-zVZiOjhZK+VZAs4aqOmxj6vplbGGwcin/gJ3Xm/gn+wV1GzgeqDkYrrDJclEpQ7WcmA4WV/Pad6tWfPtGt12/g== + dependencies: + "@solana/spl-token" "0.1.4" + "@solana/web3.js" "^1.11.0" + bip32 "^2.0.6" + bn.js "^5.1.3" + borsh "^0.4.0" + bs58 "4.0.1" + buffer-layout "^1.2.0" + core-util-is "^1.0.2" + crypto "^1.0.1" + crypto-ts "^1.0.2" + fs "^0.0.1-security" + tweetnacl "^1.0.3" + webpack-dev-server "^3.11.2" + "@chaitanyapotti/random-id@^1.0.3": version "1.0.3" resolved "https://registry.yarnpkg.com/@chaitanyapotti/random-id/-/random-id-1.0.3.tgz#f52f647cfe9f79fc7723ea2b01b0ad3889204002"