Skip to content

Commit 4e63e85

Browse files
authored
feat(nfts): add nfts to blockchain api query (#3842)
### Description Broken out backend work needed to support the components in #3800. - Added new Nft types in `src/nfts/types.ts` - Updated the transaction query helper in `src/transactions/feed/queryHelper.ts` to query for Nfts. - Added mock nfts for testing. ### Test plan Tested locally on iOS and Android. ### Related issues - #3800 ### Backwards compatibility Yes
1 parent 69b3295 commit 4e63e85

File tree

6 files changed

+237
-0
lines changed

6 files changed

+237
-0
lines changed

src/nfts/types.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
interface NftMetaDataAttribute {
2+
trait_type: string
3+
value: string
4+
}
5+
6+
interface NftMedia {
7+
raw: string
8+
gateway: string
9+
}
10+
11+
export interface Nft {
12+
tokenId: string
13+
contractAddress: string
14+
tokenUri?: string | null
15+
ownerAddress?: string | null
16+
metadata: {
17+
name: string
18+
description: string
19+
image: string
20+
dna?: string | null
21+
id?: number | null
22+
date?: number | null
23+
attributes?: NftMetaDataAttribute[] | null
24+
} | null
25+
media: NftMedia[]
26+
}

src/transactions/feed/NftFeedItem.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import NftFeedItem from 'src/transactions/feed/NftFeedItem'
88
import { Fee, TokenTransactionTypeV2 } from 'src/transactions/types'
99
import networkConfig from 'src/web3/networkConfig'
1010
import { createMockStore, RecursivePartial } from 'test/utils'
11+
import { mockNftAllFields } from 'test/values'
1112

1213
const MOCK_TX_HASH = '0x006b866d20452a24d1d90c7514422188cc7c5d873e2f1ed661ec3f810ad5331c'
1314
const MOCK_ADDRESS = '0xFdd8bD58115FfBf04e47411c1d228eCC45E93075'.toLowerCase()
@@ -38,6 +39,7 @@ describe('NftFeedItem', () => {
3839
timestamp: 1234,
3940
block: '2345',
4041
fees,
42+
nfts: [mockNftAllFields],
4143
}}
4244
/>
4345
</Provider>

src/transactions/feed/queryHelper.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,28 @@ export const TRANSACTIONS_QUERY = `
293293
transactionHash
294294
timestamp
295295
block
296+
nfts {
297+
tokenId
298+
contractAddress
299+
tokenUri
300+
ownerAddress
301+
metadata {
302+
name
303+
description
304+
image
305+
id
306+
dna
307+
date
308+
attributes {
309+
trait_type
310+
value
311+
}
312+
}
313+
media {
314+
raw
315+
gateway
316+
}
317+
}
296318
}
297319
298320
fragment TokenExchangeItemV2 on TokenExchangeV2 {

src/transactions/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Address } from '@celo/base'
22
import BigNumber from 'bignumber.js'
33
import { TokenTransactionType } from 'src/apollo/types'
4+
import { Nft } from 'src/nfts/types'
45
import { Currency } from 'src/utils/currencies'
56
import { v4 as uuidv4 } from 'uuid'
67

@@ -131,6 +132,7 @@ export interface NftTransfer {
131132
timestamp: number
132133
block: string
133134
fees: Fee[]
135+
nfts: Nft[]
134136
}
135137

136138
// Can we optional the fields `transactionHash` and `block`?

test/RootStateSchema.json

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,6 +1575,132 @@
15751575
],
15761576
"type": "object"
15771577
},
1578+
"Nft": {
1579+
"additionalProperties": false,
1580+
"properties": {
1581+
"contractAddress": {
1582+
"type": "string"
1583+
},
1584+
"media": {
1585+
"items": {
1586+
"$ref": "#/definitions/NftMedia"
1587+
},
1588+
"type": "array"
1589+
},
1590+
"metadata": {
1591+
"anyOf": [
1592+
{
1593+
"additionalProperties": false,
1594+
"properties": {
1595+
"attributes": {
1596+
"anyOf": [
1597+
{
1598+
"items": {
1599+
"$ref": "#/definitions/NftMetaDataAttribute"
1600+
},
1601+
"type": "array"
1602+
},
1603+
{
1604+
"type": "null"
1605+
}
1606+
]
1607+
},
1608+
"date": {
1609+
"type": [
1610+
"null",
1611+
"number"
1612+
]
1613+
},
1614+
"description": {
1615+
"type": "string"
1616+
},
1617+
"dna": {
1618+
"type": [
1619+
"null",
1620+
"string"
1621+
]
1622+
},
1623+
"id": {
1624+
"type": [
1625+
"null",
1626+
"number"
1627+
]
1628+
},
1629+
"image": {
1630+
"type": "string"
1631+
},
1632+
"name": {
1633+
"type": "string"
1634+
}
1635+
},
1636+
"required": [
1637+
"description",
1638+
"image",
1639+
"name"
1640+
],
1641+
"type": "object"
1642+
},
1643+
{
1644+
"type": "null"
1645+
}
1646+
]
1647+
},
1648+
"ownerAddress": {
1649+
"type": [
1650+
"null",
1651+
"string"
1652+
]
1653+
},
1654+
"tokenId": {
1655+
"type": "string"
1656+
},
1657+
"tokenUri": {
1658+
"type": [
1659+
"null",
1660+
"string"
1661+
]
1662+
}
1663+
},
1664+
"required": [
1665+
"contractAddress",
1666+
"media",
1667+
"metadata",
1668+
"tokenId"
1669+
],
1670+
"type": "object"
1671+
},
1672+
"NftMedia": {
1673+
"additionalProperties": false,
1674+
"properties": {
1675+
"gateway": {
1676+
"type": "string"
1677+
},
1678+
"raw": {
1679+
"type": "string"
1680+
}
1681+
},
1682+
"required": [
1683+
"gateway",
1684+
"raw"
1685+
],
1686+
"type": "object"
1687+
},
1688+
"NftMetaDataAttribute": {
1689+
"additionalProperties": false,
1690+
"properties": {
1691+
"trait_type": {
1692+
"type": "string"
1693+
},
1694+
"value": {
1695+
"type": "string"
1696+
}
1697+
},
1698+
"required": [
1699+
"trait_type",
1700+
"value"
1701+
],
1702+
"type": "object"
1703+
},
15781704
"NftTransfer": {
15791705
"additionalProperties": false,
15801706
"properties": {
@@ -1593,6 +1719,12 @@
15931719
},
15941720
"type": "array"
15951721
},
1722+
"nfts": {
1723+
"items": {
1724+
"$ref": "#/definitions/Nft"
1725+
},
1726+
"type": "array"
1727+
},
15961728
"timestamp": {
15971729
"type": "number"
15981730
},
@@ -1607,6 +1739,7 @@
16071739
"__typename",
16081740
"block",
16091741
"fees",
1742+
"nfts",
16101743
"timestamp",
16111744
"transactionHash",
16121745
"type"

test/values.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
import { AddressToE164NumberType, E164NumberToAddressType } from 'src/identity/reducer'
3636
import { LocalCurrencyCode } from 'src/localCurrency/consts'
3737
import { StackParamList } from 'src/navigator/types'
38+
import { Nft } from 'src/nfts/types'
3839
import { NotificationTypes } from 'src/notifications/types'
3940
import { PaymentRequest, PaymentRequestStatus } from 'src/paymentRequest/types'
4041
import { Position } from 'src/positions/types'
@@ -1261,3 +1262,54 @@ export const mockLegacyMobileMoneyProvider: LegacyMobileMoneyProvider = {
12611262
url: 'fake-url-1',
12621263
},
12631264
}
1265+
1266+
export const mockNftAllFields: Nft = {
1267+
contractAddress: mockContractAddress,
1268+
media: [
1269+
{
1270+
gateway: 'https://example.com/1',
1271+
raw: 'https://example.com/1',
1272+
},
1273+
],
1274+
metadata: {
1275+
attributes: [{ trait_type: 'Fizz Buzz', value: '1' }],
1276+
date: new Date('01/01/2020').getTime(),
1277+
description: 'This is a fizzBuzz name!',
1278+
dna: '000001',
1279+
id: 1,
1280+
image: 'https://example.com/1',
1281+
name: `${mockName}.fizzBuzz`,
1282+
},
1283+
ownerAddress: mockAccount,
1284+
tokenId: '1',
1285+
tokenUri: 'https://example.com/1',
1286+
}
1287+
1288+
export const mockNftMinimumFields: Nft = {
1289+
contractAddress: mockContractAddress,
1290+
media: [
1291+
{
1292+
gateway: 'https://example.com/3',
1293+
raw: 'https://example.com/3',
1294+
},
1295+
],
1296+
metadata: {
1297+
attributes: [{ trait_type: 'Fizz Buzz', value: 'Fizz' }],
1298+
date: null,
1299+
description: 'This is a fizzBuzz name!',
1300+
dna: null,
1301+
id: null,
1302+
image: 'https://example.com/3',
1303+
name: `${mockName}.fizzBuzz`,
1304+
},
1305+
ownerAddress: mockAccount,
1306+
tokenId: '3',
1307+
tokenUri: 'https://example.com/3',
1308+
}
1309+
1310+
export const mockNftNullMetadata: Nft = {
1311+
contractAddress: mockContractAddress,
1312+
media: [],
1313+
metadata: null,
1314+
tokenId: '4',
1315+
}

0 commit comments

Comments
 (0)