Skip to content

Commit

Permalink
feat(nfts): handle asset contract search for testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
plondon committed Dec 7, 2021
1 parent 299871b commit 5b9db36
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ export default ({ api }: { api: APIType }) => {
yield put(A.setMarketplaceData({ atBound: false, page: 1, token_ids_queried: [] }))
yield put(A.clearAndRefetchOffersMade())
yield put(A.clearAndRefetchOrders())
yield put(A.setActiveTab('offers'))
yield put(actions.alerts.displaySuccess(`Successfully created offer!`))
} catch (e) {
const error = errorHandler(e)
Expand All @@ -355,6 +356,7 @@ export default ({ api }: { api: APIType }) => {
yield put(A.resetNftOrders())
yield put(A.setMarketplaceData({ atBound: false, page: 1, token_ids_queried: [] }))
yield put(A.fetchNftOrders())
yield put(A.setActiveTab('my-collection'))
yield put(actions.alerts.displaySuccess(`Successfully created order!`))
} catch (e) {
const error = errorHandler(e)
Expand Down Expand Up @@ -522,11 +524,18 @@ export default ({ api }: { api: APIType }) => {

const searchNftAssetContract = function* (action: ReturnType<typeof A.searchNftAssetContract>) {
try {
const res: ReturnType<typeof api.searchNftCollectionInfo> = yield call(
api.searchNftCollectionInfo,
action.payload.asset_contract_address
)
yield put(A.setCollectionSearch(res))
if (action.payload.search) {
const res: ReturnType<typeof api.searchNftCollectionInfo> = yield call(
api.searchNftCollectionInfo,
action.payload.search
)
yield put(A.setCollectionSearch(res))
} else if (action.payload.asset_contract_address) {
if (ethers.utils.isAddress(action.payload.asset_contract_address)) {
const res = yield call(api.getAssetContract, action.payload.asset_contract_address)
yield put(actions.form.change('nftMarketplace', 'collection', res.collection.slug))
}
}
} catch (e) {
const error = errorHandler(e)
yield put(actions.form.stopSubmit('nftSearch'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ const nftsSlice = createSlice({
},
searchNftAssetContract: (
state,
action: PayloadAction<{ asset_contract_address: string }>
action: PayloadAction<{ asset_contract_address?: string; search?: string }>
) => {},
setActiveTab: (state, action: PayloadAction<'explore' | 'my-collection' | 'offers'>) => {
state.activeTab = action.payload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ const NftHeader: React.FC<InjectedFormProps<{}, Props> & Props> = ({
setShowDropdown(false)
}

const handleSubmit = (e) => {
e.preventDefault()
nftsActions.searchNftAssetContract({ asset_contract_address: e.target[0].value })
}

return (
<Wrapper>
<TabsContainer>
Expand All @@ -74,15 +79,15 @@ const NftHeader: React.FC<InjectedFormProps<{}, Props> & Props> = ({
</TabMenuItem>
</TabMenu>
</TabsContainer>
<StyledForm>
<StyledForm onSubmit={handleSubmit}>
<Field
placeholder='Search Collections'
name='search'
onFocus={() => setShowDropdown(true)}
onBlur={() => setShowDropdown(false)}
onChange={debounce((_, val) => {
setShowDropdown(true)
nftsActions.searchNftAssetContract({ asset_contract_address: val })
nftsActions.searchNftAssetContract({ search: val })
}, 500)}
component={TextBox}
/>
Expand Down

0 comments on commit 5b9db36

Please sign in to comment.