Skip to content

Commit

Permalink
Merge pull request #1220 from Coflnet/subscribe-to-coflcoin-changes
Browse files Browse the repository at this point in the history
subscribe to coflcoin changes
  • Loading branch information
matthias-luger committed Feb 27, 2024
2 parents 7a4e404 + 0ff706d commit 4acc6d9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
25 changes: 14 additions & 11 deletions api/ApiHelper.tsx
Expand Up @@ -50,11 +50,12 @@ import {
storeUsedTagsInLocalStorage
} from '../utils/SettingsUtils'
import { isClientSideRendering } from '../utils/SSRUtils'
import { HttpApi, RequestType, Subscription, SubscriptionType } from './ApiTypes.d'
import { HttpApi, RequestType, SubscriptionType, CUSTOM_EVENTS, Subscription } from './ApiTypes.d'
import { initHttpHelper } from './HttpHelper'
import { websocketHelper } from './WebsocketHelper'
import { canUseClipBoard, writeToClipboard } from '../utils/ClipboardUtils'
import properties from '../properties'
import { getCurrentCoflCoins } from '../utils/CoflCoinsUtils'

function getApiEndpoint() {
return isClientSideRendering() ? getProperty('apiEndpoint') : process.env.API_ENDPOINT || getProperty('apiEndpoint')
Expand Down Expand Up @@ -1089,22 +1090,24 @@ export function initAPI(returnSSRResponse: boolean = false): API {
}

let subscribeCoflCoinChange = () => {
// TODO: Has yet to be implemented by the backend
/*
console.log('subscribe cofl coin change')
websocketHelper.subscribe({
type: RequestType.SUBSCRIBE_COFLCOINS,
type: RequestType.SUBSCRIBE_EVENTS,
data: '',
resubscribe: function (subscription) {
subscribeCoflCoinChange()
},
onError: function (message) {
toast.error(message)
},
callback: function (response) {
switch (response.type) {
case 'coflCoinUpdate':
document.dispatchEvent(new CustomEvent(CUSTOM_EVENTS.COFLCOIN_UPDATE, { detail: { coflCoins: response.data } }))
break
default:
break
if (response.data.sourceType === 'purchase' || response.data.sourceType === 'topup') {
document.dispatchEvent(
new CustomEvent(CUSTOM_EVENTS.COFLCOIN_UPDATE, { detail: { coflCoins: getCurrentCoflCoins() + Math.round(response.data.data.amount) } })
)
}
}
})
*/
}

let getCoflcoinBalance = (): Promise<number> => {
Expand Down
2 changes: 1 addition & 1 deletion api/ApiTypes.d.tsx
Expand Up @@ -58,7 +58,7 @@ export enum RequestType {
GET_KAT_FLIPS = 'kat/profit',
GET_TRACKED_FLIPS_FOR_PLAYER = 'flip/stats/player',
PURCHASE_WITH_COFLCOiNS = 'service/purchase',
SUBSCRIBE_COFLCOINS = 'subscribeCoflCoins',
SUBSCRIBE_EVENTS = 'subEvents',
GET_COFLCOIN_BALANCE = 'getCoflBalance',
GET_FLIP_SETTINGS = 'getFlipSettings',
SET_FLIP_SETTING = 'setFlipSetting',
Expand Down
1 change: 1 addition & 0 deletions utils/CoflCoinsUtils.tsx
Expand Up @@ -53,6 +53,7 @@ export function initCoflCoinManager() {
currentCoflCoins = coflCoins
notifyAboutCoflCoinUpdate(coflCoins)
})
document.removeEventListener(CUSTOM_EVENTS.GOOGLE_LOGIN, initCoflCoinBalanceAndSubscriptions)
}

document.addEventListener(CUSTOM_EVENTS.GOOGLE_LOGIN, initCoflCoinBalanceAndSubscriptions)
Expand Down

0 comments on commit 4acc6d9

Please sign in to comment.