adding username translation

This commit is contained in:
Laurent Le Houerou 2021-12-22 10:56:26 +04:00
parent 2a203f3ac7
commit a842e8f8e6
3 changed files with 14 additions and 40 deletions

13
nft.go
View File

@ -207,12 +207,7 @@ func (s *MarketService) GetNft(ctx context.Context, collection string, tokenId i
res.IsRecent = time.Unix(res.UpdatedAt, 0).After(time.Now().Add(-1 * time.Hour))
res.IsVeryRecent = time.Unix(res.UpdatedAt, 0).After(time.Now().Add(-5 * time.Minute))
res.IsNotMine = res.CurrentSeller != s.bscaddress
if n, err := s.profileService.GetUsername(res.CurrentSeller); err != nil {
res.CurrentSellerUsername = res.CurrentSeller
} else {
res.CurrentSellerUsername = n
}
res.CurrentSellerUsername = s.profileService.GetUsername(res.CurrentSeller)
return res, nil
}
@ -274,11 +269,7 @@ func (s *MarketService) getPage(ctx context.Context, collection string, pagenum
floor = nft.CurrentAskPrice
}
nft.IsNotMine = nft.CurrentSeller != s.bscaddress
if n, err := s.profileService.GetUsername(nft.CurrentSeller); err != nil {
nft.CurrentSellerUsername = nft.CurrentSeller
} else {
nft.CurrentSellerUsername = n
}
nft.CurrentSellerUsername = s.profileService.GetUsername(nft.CurrentSeller)
res = append(res, nft)
}

View File

@ -52,18 +52,17 @@ func NewProfileService() *ProfileService {
}
}
func (s *ProfileService) GetUsername(address string) (string, error) {
func (s *ProfileService) GetUsername(address string) string {
s.lock.Lock()
defer s.lock.Unlock()
if name, ok := s.cache[address]; ok {
return name, nil
return name
}
if name, err := getUsernameFromAddress(address); err != nil {
s.cache[address] = address
} else {
s.cache[address] = name
}
name, err := getUsernameFromAddress(address)
if err != nil {
return "", err
}
s.cache[address] = name
return name, nil
return s.cache[address]
}

View File

@ -110,16 +110,8 @@ func (s *TransactionService) GetLightPageByLimit(ctx context.Context, pagenumber
return transaction.Nft.TransactionHistory[i].Timestamp > transaction.Nft.TransactionHistory[j].Timestamp
})
transaction.IsMine = transaction.Buyer.Address == s.bscaddress || transaction.Seller.Address == s.bscaddress
if n, err := s.profileService.GetUsername(transaction.Seller.Address); err != nil {
transaction.SellerUsername = transaction.Seller.Address
} else {
transaction.SellerUsername = n
}
if n, err := s.profileService.GetUsername(transaction.Buyer.Address); err != nil {
transaction.BuyerUsername = transaction.Buyer.Address
} else {
transaction.BuyerUsername = n
}
transaction.SellerUsername = s.profileService.GetUsername(transaction.Seller.Address)
transaction.BuyerUsername = s.profileService.GetUsername(transaction.Buyer.Address)
}
var res []Transaction
@ -179,16 +171,8 @@ func (s *TransactionService) GetPageByLimit(ctx context.Context, pagenumber int,
transaction.Time = time.Unix(transaction.Timestamp, 0)
transaction.TimeDescription = humanize.Time(transaction.Time)
if n, err := s.profileService.GetUsername(transaction.Seller.Address); err != nil {
transaction.SellerUsername = transaction.Seller.Address
} else {
transaction.SellerUsername = n
}
if n, err := s.profileService.GetUsername(transaction.Buyer.Address); err != nil {
transaction.BuyerUsername = transaction.Buyer.Address
} else {
transaction.BuyerUsername = n
}
transaction.SellerUsername = s.profileService.GetUsername(transaction.Seller.Address)
transaction.BuyerUsername = s.profileService.GetUsername(transaction.Buyer.Address)
}
var res []Transaction