Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions functions/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"puppeteer-core": "^10.1.0",
"sharp": "^0.32.6",
"source-map-support": "^0.5.10",
"tiny-cookie": "^2.3.2",
"url-parse": "^1.5.9",
"uuid": "^3.4.0",
"vue": "^2.6.11",
Expand Down
34 changes: 14 additions & 20 deletions src/mixins/embed-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { LIKE_CO_HOSTNAME } from '@/constant';
import { getAvatarHaloTypeFromUser } from '~/util/user';
import { isAndroid, isFacebookBrowser } from '~/util/client';

import { apiGetLikeButtonTotalCount } from '~/util/api/api';

import mixin from './embed';

export default {
mixins: [mixin],
data() {
return {
isUserFetched: false,
isShowLikeButton: true,
};
},
Expand All @@ -29,21 +30,6 @@ export default {
return this.$route.query.preview === '1';
},
},
head() {
const link = [];
if (this.isUserFetched && !this.isLoggedIn) {
if (this.hasCookieSupport) {
if (!(window.doNotTrack || navigator.doNotTrack)) { // do not prefetch if DNT
link.push({ rel: 'prefetch', href: this.signUpUrl });
}
} else {
link.push({ rel: 'prefetch', href: this.popupURL });
}
}
return {
link,
};
},
async mounted() {
try {
// Notify app when button is mounted
Expand All @@ -54,10 +40,18 @@ export default {
}
window.addEventListener('message', this.handleWindowMessage);
if (this.isPreview) { return; }
this.hasCookieSupport = await this.getIsCookieSupport();
await this.updateUserSignInStatus();
if (this.onCheckCookieSupport) { this.onCheckCookieSupport(this.hasCookieSupport); }
this.isUserFetched = true;

const { id, referrer, iscnId } = this.likeTarget;
try {
const { data: totalData } = await apiGetLikeButtonTotalCount(id, {
referrer,
iscnId,
});
this.totalLike = totalData.total;
} catch (err) {
// eslint-disable-next-line no-console
console.error(err);
}
},
beforeDestroy() {
window.removeEventListener('message', this.handleWindowMessage);
Expand Down
43 changes: 0 additions & 43 deletions src/mixins/embed.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import {
isCookieEnabled,
setCookie,
} from 'tiny-cookie';

import {
LIKE_CO_HOSTNAME,
LIKER_LAND_URL_BASE,
Expand All @@ -24,7 +19,6 @@ import {
apiGetNFTMintInfo,
} from '~/util/api/api';

import { checkHasStorageAPIAccess, checkIsFirefoxStrictMode } from '~/util/client';
import { checkIsValidISCNId, checkIsValidNFTClassId } from '~/util/nft';
import { handleQueryStringInUrl } from '~/util/url';
import { maskedWallet } from '~/util/cosmos';
Expand All @@ -43,7 +37,6 @@ const debouncedOnClick = debounce((that) => {
apiPostLikeButton(that.likeTarget.id, count, {
referrer: that.likeTarget.referrer,
iscnId: that.likeTarget.iscnId,
isCookieSupport: that.hasCookieSupport,
...that.apiMetadata,
});
}
Expand Down Expand Up @@ -229,9 +222,6 @@ export default {
hasFollowedCreator: false,
isLoadingFollowStatus: false,

hasCookieSupport: false,
hasStorageAPIAccess: false,

hasUpdateUserSignInStatus: false,

isRedirecting: false,
Expand Down Expand Up @@ -347,47 +337,20 @@ export default {
},
},
methods: {
async getIsCookieSupport() {
let res = false;
try {
this.hasStorageAPIAccess = await checkHasStorageAPIAccess();
// Cross-site Cookie randomly disappear in fx strict mode
const isFirefoxStrictMode = checkIsFirefoxStrictMode();
res = process.client &&
navigator.cookieEnabled &&
this.hasStorageAPIAccess &&
isCookieEnabled() &&
!isFirefoxStrictMode;
} catch (err) {
// eslint-disable-next-line no-console
console.error(err);
return false;
}
try {
setCookie('likebutton_cookie', 1);
} catch (err) {
// eslint-disable-next-line no-console
console.error(err);
return false;
}
return res;
},
async updateUserSignInStatus() {
const { id, referrer, iscnId } = this.likeTarget;
try {
await Promise.all([
apiGetLikeButtonMyStatus(id, {
referrer,
iscnId,
isCookieSupport: this.hasCookieSupport,
...this.apiMetadata,
})
.then(async({ data: myData }) => {
const {
liker,
isSubscribed,
isTrialSubscriber,
serverCookieSupported,
civicLikerVersion,
isSelfWork,
} = myData;
Expand All @@ -396,12 +359,6 @@ export default {
this.isSubscribed = isSubscribed;
this.isTrialSubscriber = isTrialSubscriber;
this.civicLikerVersion = civicLikerVersion;
if (
this.hasCookieSupport &&
serverCookieSupported !== undefined
) {
this.hasCookieSupport = serverCookieSupported;
}
if (this.isLoggedIn) {
if (this.$sentry) {
this.$sentry.setUser({ id: liker });
Expand Down
11 changes: 0 additions & 11 deletions src/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"nuxt": "^2.18.1",
"nuxt-svg-loader": "^1.0.1",
"on-headers": "^1.0.2",
"tiny-cookie": "^2.3.2",
"url-parse": "^1.4.4",
"uuid": "^3.4.0",
"vue-gtag": "^1.16.1",
Expand Down
29 changes: 4 additions & 25 deletions src/pages/in/embed/_id/button.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@
</template>

<script>
import {
requestStorageAPIAccess,
isAndroid,
isFacebookBrowser,
} from '~/util/client';

import mixin from '~/mixins/embed-button';

import Identity from '~/components/Identity/Identity';
Expand All @@ -65,7 +59,6 @@ export default {
layout: 'embedv2',
data() {
return {
isUserFetched: false,
isShowAltMode: false,
};
},
Expand Down Expand Up @@ -94,26 +87,12 @@ export default {
window.removeEventListener('message', this.onReceiveMessage, false);
},
methods: {
async doLogin(action) {
doLogin(action) {
if (this.isPreview) { return; }
this.postSignInAction = action;
if (!this.hasCookieSupport || (isAndroid() && isFacebookBrowser())) {
// User has not log in and 3rd party cookie is blocked
// or: android fb iab stuck when sign in new window, use like popup
this.openPopup(action);
const eventAction = action.replace(/^./, s => s.toUpperCase());
logTrackerEvent(this, 'LikeButtonFlow', `popup${eventAction}`, `popup${eventAction}(embed)`, 1);
if (!(this.hasStorageAPIAccess)) {
if (await requestStorageAPIAccess()) {
this.hasCookieSupport = await this.getIsCookieSupport();
await this.updateUserSignInStatus();
}
}
} else {
// User has not log in and 3rd party cookie is not blocked
this.signUp();
logTrackerEvent(this, 'LikeButtonFlow', 'popupSignUp', 'popupSignUp(embed)', 1);
}
this.openPopup(action);
const eventAction = action.replace(/^./, s => s.toUpperCase());
logTrackerEvent(this, 'LikeButtonFlow', `popup${eventAction}`, `popup${eventAction}(embed)`, 1);
},
doLike() {
if (!this.isMaxLike) {
Expand Down
6 changes: 2 additions & 4 deletions src/util/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@ export const apiGetUserMinById = id => axios.get(`${LIKECOIN_API}/users/id/${id}
export const apiGetLikeButtonMyStatus = (id, data) => {
const {
referrer = '',
isCookieSupport,
iscnId = '',
} = data;
const cookieParam = isCookieSupport !== undefined ? `&cookie_support=${isCookieSupport ? 1 : 0}` : '';
return axios.get(
id === 'iscn'
? `${LIKECOIN_API}/like/likebutton/iscn/self?iscn_id=${encodeURIComponent(iscnId)}${cookieParam}&show_count=0`
: `${LIKECOIN_API}/like/likebutton/${id}/self?referrer=${encodeURIComponent(referrer)}${cookieParam}&show_count=0`,
? `${LIKECOIN_API}/like/likebutton/iscn/self?iscn_id=${encodeURIComponent(iscnId)}&show_count=0`
: `${LIKECOIN_API}/like/likebutton/${id}/self?referrer=${encodeURIComponent(referrer)}&show_count=0`,
{
headers: getLikeCoinButtonHeaders(data),
withCredentials: true,
Expand Down
33 changes: 0 additions & 33 deletions src/util/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,36 +49,3 @@ export function openURL(vue, url, name, specs, replace) {
if (w) { w.opener = null; }
}
}

export async function checkHasStorageAPIAccess() {
// https://webkit.org/blog/8311/intelligent-tracking-prevention-2-0/
// TODO: try to request for storageAPI access
if (typeof document.hasStorageAccess !== 'function') { return true; }
try {
const res = await document.hasStorageAccess();
return res;
} catch (err) {
// eslint-disable-next-line no-console
console.error(err);
return false;
}
}

export function checkIsFirefoxStrictMode() {
const isFireFox = navigator.userAgent.includes('Firefox');
const DNT = window.doNotTrack || navigator.doNotTrack;
// We cannot detect ETP strict mode, but it sets DNT to 1.
return (isFireFox && DNT && DNT === '1');
}

export async function requestStorageAPIAccess() {
if (typeof document.requestStorageAccess !== 'function') { return false; }
try {
const res = await document.requestStorageAccess();
return res || true;
} catch (err) {
// eslint-disable-next-line no-console
console.error(err);
return false;
}
}
Loading