-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: use exotics api v2 #298
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fcdf2ca
chore: use exotics api v2
fedeerbes 4d51d95
chore: add mapRareSatsAPIResponseToBundle util
fedeerbes 82304c7
chore: improve mapRareSatsAPIResponseToBundle util to map unsupportedβ¦
fedeerbes e18144f
fix: typos
fedeerbes 2090b0e
fix: logic and types
fedeerbes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,14 +4,20 @@ | |||||
import { INSCRIPTION_REQUESTS_SERVICE_URL, ORDINALS_URL, XVERSE_API_BASE_URL, XVERSE_INSCRIBE_URL } from '../constant'; | ||||||
import { | ||||||
Account, | ||||||
AddressBundleResponse, | ||||||
Brc20HistoryTransactionData, | ||||||
BtcOrdinal, | ||||||
Bundle, | ||||||
BundleSatRange, | ||||||
FungibleToken, | ||||||
HiroApiBrc20TxHistoryResponse, | ||||||
Inscription, | ||||||
InscriptionRequestResponse, | ||||||
NetworkType, | ||||||
RareSatsType, | ||||||
SatRangeInscription, | ||||||
UTXO, | ||||||
UtxoBundleResponse, | ||||||
UtxoOrdinalBundle, | ||||||
} from '../types'; | ||||||
import { parseBrc20TransactionData } from './helper'; | ||||||
|
@@ -101,8 +107,8 @@ | |||||
timeout: 30000, | ||||||
transformResponse: [(data) => parseOrdinalTextContentData(data)], | ||||||
}) | ||||||
.then((response) => response!.data) | ||||||
.catch((error) => { | ||||||
return ''; | ||||||
}); | ||||||
} | ||||||
|
@@ -132,9 +138,9 @@ | |||||
}) | ||||||
.then((response) => { | ||||||
if (response.data) { | ||||||
const responseTokensList = response!.data; | ||||||
const tokensList: Array<FungibleToken> = []; | ||||||
responseTokensList.forEach((responseToken: any) => { | ||||||
const token: FungibleToken = { | ||||||
name: responseToken.ticker, | ||||||
balance: responseToken.overallBalance, | ||||||
|
@@ -157,7 +163,7 @@ | |||||
return []; | ||||||
} | ||||||
}) | ||||||
.catch((error) => { | ||||||
return []; | ||||||
}); | ||||||
} | ||||||
|
@@ -216,12 +222,6 @@ | |||||
export const isOrdinalOwnedByAccount = (inscription: Inscription, account: Account) => | ||||||
inscription.address === account.ordinalsAddress; | ||||||
|
||||||
export type AddressBundleResponse = { | ||||||
total: number; | ||||||
offset: number; | ||||||
limit: number; | ||||||
results: UtxoOrdinalBundle[]; | ||||||
}; | ||||||
export const getAddressUtxoOrdinalBundles = async ( | ||||||
network: NetworkType, | ||||||
address: string, | ||||||
|
@@ -247,7 +247,7 @@ | |||||
} | ||||||
|
||||||
const response = await axios.get<AddressBundleResponse>( | ||||||
`${XVERSE_API_BASE_URL(network)}/v1/address/${address}/ordinal-utxo`, | ||||||
`${XVERSE_API_BASE_URL(network)}/v2/address/${address}/ordinal-utxo`, | ||||||
{ | ||||||
params, | ||||||
}, | ||||||
|
@@ -260,9 +260,85 @@ | |||||
network: NetworkType, | ||||||
txid: string, | ||||||
vout: number, | ||||||
): Promise<UtxoOrdinalBundle> => { | ||||||
const response = await axios.get<UtxoOrdinalBundle>( | ||||||
`${XVERSE_API_BASE_URL(network)}/v1/ordinal-utxo/${txid}:${vout}`, | ||||||
): Promise<UtxoBundleResponse> => { | ||||||
const response = await axios.get<UtxoBundleResponse>( | ||||||
`${XVERSE_API_BASE_URL(network)}/v2/ordinal-utxo/${txid}:${vout}`, | ||||||
); | ||||||
return response.data; | ||||||
}; | ||||||
|
||||||
export const mapRareSatsAPIResponseToBundle = (apiBundle: UtxoOrdinalBundle): Bundle => { | ||||||
const generalBundleInfo = { | ||||||
txid: apiBundle.txid, | ||||||
vout: apiBundle.vout, | ||||||
block_height: apiBundle.block_height, | ||||||
value: apiBundle.value, | ||||||
}; | ||||||
|
||||||
const commonUnknownRange: BundleSatRange = { | ||||||
range: { | ||||||
start: '0', | ||||||
end: '0', | ||||||
}, | ||||||
yearMined: 0, | ||||||
block: 0, | ||||||
offset: 0, | ||||||
satributes: ['COMMON'], | ||||||
inscriptions: [], | ||||||
totalSats: apiBundle.value, | ||||||
}; | ||||||
|
||||||
// if bundle has and empty sat ranges, it means that it's a common/unknown bundle | ||||||
if (!apiBundle.sat_ranges.length) { | ||||||
return { | ||||||
...generalBundleInfo, | ||||||
satRanges: [commonUnknownRange], | ||||||
inscriptions: [], | ||||||
satributes: [['COMMON']], | ||||||
totalExoticSats: 0, | ||||||
}; | ||||||
} | ||||||
|
||||||
const satRanges = apiBundle.sat_ranges.map((satRange) => { | ||||||
const { year_mined: yearMined, ...satRangeProps } = satRange; | ||||||
return { | ||||||
...satRangeProps, | ||||||
totalSats: Number(BigInt(satRange.range.end) - BigInt(satRange.range.start)), | ||||||
yearMined, | ||||||
// we want to common/unknown inscriptions to be shown as a additional row from common/unknown row | ||||||
satributes: | ||||||
!satRange.satributes.length && satRange.inscriptions.length | ||||||
? (['COMMON'] as RareSatsType[]) | ||||||
: satRange.satributes, | ||||||
}; | ||||||
}); | ||||||
|
||||||
// if totalExotics doesn't match the value of the bundle, | ||||||
// it means that the bundle is not fully exotic and we need to add a common unknown sat range more | ||||||
let totalExoticSats = 0; | ||||||
let totalCommonUnknownInscribedSats = 0; | ||||||
satRanges.forEach((satRange) => { | ||||||
if (satRange.satributes.includes('COMMON')) { | ||||||
totalCommonUnknownInscribedSats += satRange.totalSats; | ||||||
} else { | ||||||
totalExoticSats += satRange.totalSats; | ||||||
} | ||||||
}); | ||||||
if (totalExoticSats !== apiBundle.value) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
satRanges.push({ | ||||||
...commonUnknownRange, | ||||||
totalSats: apiBundle.value - (totalExoticSats + totalCommonUnknownInscribedSats), | ||||||
}); | ||||||
} | ||||||
|
||||||
const inscriptions = satRanges.reduce((acc, curr) => [...acc, ...curr.inscriptions], [] as SatRangeInscription[]); | ||||||
const satributes = satRanges.reduce((acc, curr) => [...acc, curr.satributes], [] as RareSatsType[][]); | ||||||
|
||||||
return { | ||||||
...generalBundleInfo, | ||||||
satRanges, | ||||||
inscriptions, | ||||||
satributes, | ||||||
totalExoticSats, | ||||||
}; | ||||||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit π