Skip to content

Commit

Permalink
feat: add amounts to nft action events
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteubs-bc committed May 2, 2022
1 parent 1e1bd4e commit f30aac7
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ type AcceptedAccountsAction = {
type AcceptOfferSuccessFailAction = {
key: Events.NFT_ACCEPT_OFFER_SUCCESS_FAIL
properties: {
amount: number
amount_usd: number
currency: string
error_message?: string
type: Type
}
Expand Down Expand Up @@ -105,6 +108,9 @@ type BuyNowClickedAction = {
type BuySuccessFailAction = {
key: Events.NFT_BUY_SUCCESS_FAIL
properties: {
amount: number
amount_usd: number
currency: string
error_message?: string
type: Type
}
Expand All @@ -121,6 +127,9 @@ type CancelListingSuccessFailAction = {
type CancelOfferSuccessFailAction = {
key: Events.NFT_CANCEL_OFFER_SUCCESS_FAIL
properties: {
amount: number
amount_usd: number
currency: string
error_message?: string
type: Type
}
Expand Down Expand Up @@ -207,7 +216,10 @@ type LeftMenuExpandedAction = {
type ListingSuccessFailAction = {
key: Events.NFT_LISTING_SUCCESS_FAIL
properties: {
currency: string
end_price?: number
error_message?: string
start_price: number
type: Type
}
}
Expand Down Expand Up @@ -248,6 +260,9 @@ type OfferWithClickedAction = {
type OfferSuccessFailAction = {
key: Events.NFT_OFFER_SUCCESS_FAIL
properties: {
amount: number
amount_usd: number
currency: string
error_message?: string
type: Type
}
Expand Down Expand Up @@ -287,6 +302,9 @@ type SellItemClickedAction = {
type SellItemSuccessFailAction = {
key: Events.NFT_SELL_ITEM_SUCCESS_FAIL
properties: {
amount: number
amount_usd: number
currency: string
error_message?: string
type: Type
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ethers, Signer } from 'ethers'
import { call, put, select } from 'redux-saga/effects'

import { Exchange, Remote } from '@core'
import { convertCoinToCoin, convertCoinToFiat } from '@core/exchange'
import { APIType } from '@core/network/api'
import { NFT_ORDER_PAGE_LIMIT } from '@core/network/api/nfts'
import {
Expand Down Expand Up @@ -299,6 +300,21 @@ export default ({ api }: { api: APIType }) => {
}

const acceptOffer = function* (action: ReturnType<typeof A.acceptOffer>) {
const coin = action?.payload?.buy?.paymentTokenContract?.symbol || ''
const rates = selectors.core.data.misc
.getRatesSelector(coin, yield select())
.getOrFail('Failed to get rates')
const fiat = convertCoinToFiat({
coin,
currency: 'USD',
rates,
value: action.payload.buy.basePrice.toString()
})
const amount = convertCoinToCoin({
baseToStandard: false,
coin,
value: action?.payload?.buy?.basePrice?.toString() || ''
})
try {
yield put(A.setOrderFlowIsSubmitting(true))
const signer: Signer = yield call(getEthSigner)
Expand All @@ -310,6 +326,9 @@ export default ({ api }: { api: APIType }) => {
actions.analytics.trackEvent({
key: Analytics.NFT_ACCEPT_OFFER_SUCCESS_FAIL,
properties: {
amount: Number(amount),
amount_usd: Number(fiat),
currency: coin,
type: 'SUCCESS'
}
})
Expand All @@ -320,6 +339,9 @@ export default ({ api }: { api: APIType }) => {
actions.analytics.trackEvent({
key: Analytics.NFT_ACCEPT_OFFER_SUCCESS_FAIL,
properties: {
amount: Number(amount),
amount_usd: Number(fiat),
currency: coin,
error_message: error,
type: 'FAILED'
}
Expand All @@ -335,6 +357,21 @@ export default ({ api }: { api: APIType }) => {
}

const createOffer = function* (action: ReturnType<typeof A.createOffer>) {
const coin = action?.payload?.coin || ''
const rates = selectors.core.data.misc
.getRatesSelector(coin, yield select())
.getOrFail('Failed to get rates')
const fiat = convertCoinToFiat({
coin,
currency: 'USD',
rates,
value: action?.payload?.amount?.toString()
})
const amount = convertCoinToCoin({
baseToStandard: false,
coin,
value: action?.payload?.amount?.toString() || ''
})
try {
yield put(A.setOrderFlowIsSubmitting(true))
const signer = yield call(getEthSigner)
Expand Down Expand Up @@ -374,6 +411,9 @@ export default ({ api }: { api: APIType }) => {
actions.analytics.trackEvent({
key: Analytics.NFT_OFFER_SUCCESS_FAIL,
properties: {
amount: Number(amount),
amount_usd: Number(fiat),
currency: coin,
type: 'SUCCESS'
}
})
Expand All @@ -384,6 +424,9 @@ export default ({ api }: { api: APIType }) => {
actions.analytics.trackEvent({
key: Analytics.NFT_OFFER_SUCCESS_FAIL,
properties: {
amount: Number(amount),
amount_usd: Number(fiat),
currency: coin,
error_message: error,
type: 'FAILED'
}
Expand All @@ -400,6 +443,21 @@ export default ({ api }: { api: APIType }) => {
}

const createOrder = function* (action: ReturnType<typeof A.createOrder>) {
const coin = action?.payload?.buy?.paymentTokenContract?.symbol || ''
const rates = selectors.core.data.misc
.getRatesSelector(coin, yield select())
.getOrFail('Failed to get rates')
const fiat = convertCoinToFiat({
coin,
currency: 'USD',
rates,
value: action.payload.buy.basePrice.toString()
})
const amount = convertCoinToCoin({
baseToStandard: false,
coin,
value: action?.payload?.buy?.basePrice?.toString() || ''
})
try {
yield put(A.setOrderFlowIsSubmitting(true))
const { buy, gasData, sell } = action.payload
Expand All @@ -416,6 +474,9 @@ export default ({ api }: { api: APIType }) => {
actions.analytics.trackEvent({
key: Analytics.NFT_BUY_SUCCESS_FAIL,
properties: {
amount: Number(amount),
amount_usd: Number(fiat),
currency: coin,
type: 'SUCCESS'
}
})
Expand All @@ -425,6 +486,9 @@ export default ({ api }: { api: APIType }) => {
actions.analytics.trackEvent({
key: Analytics.NFT_SELL_ITEM_SUCCESS_FAIL,
properties: {
amount: Number(amount),
amount_usd: Number(fiat),
currency: coin,
type: 'SUCCESS'
}
})
Expand All @@ -437,6 +501,9 @@ export default ({ api }: { api: APIType }) => {
actions.analytics.trackEvent({
key: Analytics.NFT_BUY_SUCCESS_FAIL,
properties: {
amount: Number(amount),
amount_usd: Number(fiat),
currency: coin,
error_message: error,
type: 'FAILED'
}
Expand All @@ -447,6 +514,9 @@ export default ({ api }: { api: APIType }) => {
actions.analytics.trackEvent({
key: Analytics.NFT_SELL_ITEM_SUCCESS_FAIL,
properties: {
amount: Number(amount),
amount_usd: Number(fiat),
currency: coin,
error_message: error,
type: 'FAILED'
}
Expand All @@ -463,6 +533,18 @@ export default ({ api }: { api: APIType }) => {
}

const createSellOrder = function* (action: ReturnType<typeof A.createSellOrder>) {
const isTimedAuction = !!action.payload.endPrice
const coin = isTimedAuction ? 'WETH' : 'ETH'
const startPrice = convertCoinToCoin({
baseToStandard: false,
coin,
value: action?.payload?.startPrice || ''
})
const endPrice = convertCoinToCoin({
baseToStandard: false,
coin,
value: action?.payload?.endPrice || ''
})
try {
const listingTime = getUnixTime(addMinutes(new Date(), 5))
const expirationTime = getUnixTime(addDays(new Date(), action.payload.expirationDays))
Expand All @@ -489,6 +571,9 @@ export default ({ api }: { api: APIType }) => {
actions.analytics.trackEvent({
key: Analytics.NFT_LISTING_SUCCESS_FAIL,
properties: {
currency: coin,
end_price: isTimedAuction ? Number(endPrice) : undefined,
start_price: Number(startPrice),
type: 'SUCCESS'
}
})
Expand All @@ -499,7 +584,10 @@ export default ({ api }: { api: APIType }) => {
actions.analytics.trackEvent({
key: Analytics.NFT_LISTING_SUCCESS_FAIL,
properties: {
currency: coin,
end_price: isTimedAuction ? Number(endPrice) : undefined,
error_message: error,
start_price: Number(startPrice),
type: 'FAILED'
}
})
Expand Down Expand Up @@ -527,7 +615,7 @@ export default ({ api }: { api: APIType }) => {
yield put(actions.alerts.displaySuccess('Transfer successful!'))
yield put(
actions.analytics.trackEvent({
key: Analytics.NFT_LISTING_SUCCESS_FAIL,
key: Analytics.NFT_SEND_SUCCESS_FAIL,
properties: {
type: 'SUCCESS'
}
Expand Down Expand Up @@ -591,6 +679,21 @@ export default ({ api }: { api: APIType }) => {

// https://etherscan.io/tx/0x4ba256c46b0aff8b9ee4cc2a7d44649bc31f88ebafd99190bc182178c418c64a
const cancelOffer = function* (action: ReturnType<typeof A.cancelOffer>) {
const coin = action?.payload?.order?.payment_token_contract?.symbol || ''
const rates = selectors.core.data.misc
.getRatesSelector(coin, yield select())
.getOrFail('Failed to get rates')
const fiat = convertCoinToFiat({
coin,
currency: 'USD',
rates,
value: action?.payload?.order?.base_price?.toString()
})
const amount = convertCoinToCoin({
baseToStandard: false,
coin,
value: action?.payload?.order?.base_price?.toString() || ''
})
try {
if (!action.payload.order) {
throw new Error('No offer found. It may have expired already!')
Expand All @@ -605,6 +708,9 @@ export default ({ api }: { api: APIType }) => {
actions.analytics.trackEvent({
key: Analytics.NFT_CANCEL_OFFER_SUCCESS_FAIL,
properties: {
amount: Number(amount),
amount_usd: Number(fiat),
currency: coin,
type: 'SUCCESS'
}
})
Expand All @@ -615,6 +721,9 @@ export default ({ api }: { api: APIType }) => {
actions.analytics.trackEvent({
key: Analytics.NFT_CANCEL_OFFER_SUCCESS_FAIL,
properties: {
amount: Number(amount),
amount_usd: Number(fiat),
currency: coin,
error_message: error,
type: 'FAILED'
}
Expand Down

0 comments on commit f30aac7

Please sign in to comment.