-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Release] Hotfix 2.18.2 => 2.18.3 (patch) (#9143)
* chore: bump version to 2.18.3 * chore: pick simple hash (#9147) * chore: pick simple hash * chore: sync simplehash (#9083) * refactor: gray simple hash (#9104) * refactor: add canvas fingerprinting (#9012) * refactor: opt fp * test: add createDeviceSeed * fix: lint errors * feat: add isDeviceOnWhitelist * test: isDeviceOnWhitelist * fix: ci errors * refactor: update comment * fix: type error * fix: type error * feat: A/B simplehash (#9019) * refactor: set tag * chore: add ab tags * feat: debug A/B * chore: type * fix: type --------- Co-authored-by: guanbinrui <52657989+guanbinrui@users.noreply.github.com> * fix: bugfix for invalid gas (#9127) * fix: simple hash img fallback (#9155) * refactor: adjust sample rate (#9159) * refactor: events as transactions (#9160) * refactor: events as transactions * refactor: send events as transactions * refactor: update lock file * fix: mf-3718 NFTScan gnosis host is incorrect (#9118) * fix: mf-3719 image size in dashboard assets * fix: mf-3718 NFTScan gnosis host is incorrect * fix: several bugs (#9171) * fix: several bugs * fix: type * fix: mf-3717 pass plugin id to collectible card (#9168) * fix: mf-3717 pass plugin id to collectible card * fixup! fix: mf-3717 pass plugin id to collectible card * feat: remote flags (#9176) * refactor: add @masknet/flags (#9053) * chore: simplehash_ab_percentage * feat: remote flags * refactor: comment * refactor: error handling * fix: cspell * fix: logic errors * fix: simple hash rp history nft (#9177) --------- Co-authored-by: Hancheng Zhou <z308114274@gmail.com> Co-authored-by: nuanyang233 <nuanyang233@gmail.com> Co-authored-by: UncleBill <billbill290@gmail.com>
- Loading branch information
1 parent
d039d37
commit 98dbced
Showing
81 changed files
with
1,084 additions
and
298 deletions.
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 |
---|---|---|
|
@@ -380,6 +380,7 @@ | |
"rehype", | ||
"renfil", | ||
"shapeclip", | ||
"simplehash", | ||
"ssrb", | ||
"steth", | ||
"swaptoken", | ||
|
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
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
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
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "@masknet/flags", | ||
"private": true, | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"mask-src": "./src/index.ts", | ||
"default": "./dist/index.js" | ||
} | ||
}, | ||
"types": "./dist/index.d.ts", | ||
"devDependencies": { | ||
"urlcat": "^2.0.4" | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { flags as defaultFlags } from './flags/index.js' | ||
import { RemoteFlags } from './libs/RemoteFlags.js' | ||
|
||
const flags = new RemoteFlags('https://mask-flags.r2d2.to/', defaultFlags) | ||
|
||
// fetch each time starts the app, updates will be enabled | ||
flags.fetchAndActive() | ||
|
||
export const Flags = flags.accessor |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export class Flags<T extends object> { | ||
constructor(protected defaults: T) {} | ||
|
||
get accessor(): Readonly<T> { | ||
return new Proxy(this.defaults, { | ||
get(target, key, receiver) { | ||
return Reflect.get(target, key, receiver) | ||
}, | ||
set(target, key, value, receiver) { | ||
throw new Error('Not allowed') | ||
}, | ||
}) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import urlcat from 'urlcat' | ||
import { has } from 'lodash-es' | ||
import { Flags } from './Flags.js' | ||
|
||
interface FetchResult<T extends Record<string, unknown>> { | ||
flags?: T | ||
timestamp: number | ||
} | ||
|
||
export class RemoteFlags<T extends Record<string, unknown>> extends Flags<T> { | ||
private readonly KEY = 'mask-last-fetch-result' | ||
|
||
private lastFetchResult: FetchResult<T> | null = null | ||
|
||
private get lastStorageResult() { | ||
try { | ||
const json = localStorage.getItem(this.KEY) | ||
const result: FetchResult<T> | null = json ? JSON.parse(json) : null | ||
return result | ||
} catch (error) { | ||
return null | ||
} | ||
} | ||
|
||
constructor( | ||
private remoteFlagsURL: string, | ||
defaults: T, | ||
private initials?: { | ||
// the valid duration for remote fetched flags | ||
fetchTTL?: number | ||
// the valid duration for local storage flags | ||
storageTTL?: number | ||
}, | ||
) { | ||
super(defaults) | ||
|
||
this.sync() | ||
} | ||
|
||
get options() { | ||
return { | ||
fetchTTL: 60 * 60 * 1000, // 1hr | ||
storageTTL: 2 * 60 * 60 * 1000, // 2hr | ||
...this.initials, | ||
} | ||
} | ||
|
||
get isLastFetchResultFresh() { | ||
return Date.now() - this.lastFetchTimestamp < this.options.fetchTTL | ||
} | ||
|
||
get isLastStorageResultFresh() { | ||
return Date.now() - this.lastStorageTimestamp < this.options.storageTTL | ||
} | ||
|
||
get lastFetchTimestamp() { | ||
return this.lastFetchResult?.timestamp ?? 0 | ||
} | ||
|
||
get lastStorageTimestamp() { | ||
return this.lastStorageResult?.timestamp ?? 0 | ||
} | ||
|
||
override get accessor(): Readonly<T> { | ||
return new Proxy(this.defaults, { | ||
get: (target, key, receiver) => { | ||
if (has(this.lastFetchResult?.flags, key)) return this.lastFetchResult?.flags?.[key as string] | ||
return Reflect.get(target, key, receiver) | ||
}, | ||
set: (target, key, value, receiver) => { | ||
throw new Error('Not allowed') | ||
}, | ||
}) | ||
} | ||
|
||
/** | ||
* Sync with the local storage. | ||
*/ | ||
sync() { | ||
if (!this.isLastStorageResultFresh) { | ||
localStorage.removeItem(this.KEY) | ||
} | ||
|
||
const lastFetchResult = this.lastFetchResult | ||
const lastStorageResult = this.lastStorageResult | ||
|
||
if ( | ||
(lastFetchResult?.timestamp && !lastStorageResult?.timestamp) || | ||
(lastFetchResult?.timestamp && | ||
lastStorageResult?.timestamp && | ||
lastStorageResult.timestamp < lastFetchResult.timestamp) | ||
) { | ||
console.log('[RemoteFlags] sync from remote') | ||
localStorage.setItem(this.KEY, JSON.stringify(lastFetchResult)) | ||
} else if (lastStorageResult?.timestamp) { | ||
console.log('[RemoteFlags] sync from storage') | ||
this.lastFetchResult = lastStorageResult | ||
} | ||
} | ||
|
||
/** | ||
* Fetch flags from the remote server. | ||
*/ | ||
async fetch() { | ||
const response = await fetch( | ||
urlcat(this.remoteFlagsURL, { | ||
architecture: process.env.architecture, | ||
channel: process.env.channel, | ||
engine: process.env.engine, | ||
NODE_ENV: process.env.NODE_ENV, | ||
}), | ||
) | ||
const flags: T = await response.json() | ||
return flags | ||
} | ||
|
||
/** | ||
* Fetch flags from the remote server and patch updates right after fetched. | ||
*/ | ||
async fetchAndActive() { | ||
// Prevent fetching too frequently | ||
if (this.isLastFetchResultFresh) return | ||
|
||
this.lastFetchResult = { | ||
flags: await this.fetch(), | ||
timestamp: Date.now(), | ||
} | ||
this.sync() | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": "./src/", | ||
"outDir": "./dist/", | ||
"tsBuildInfoFile": "./dist/.tsbuildinfo" | ||
}, | ||
"include": ["./src"], | ||
"references": [] | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
4 changes: 2 additions & 2 deletions
4
packages/mask/background/services/helper/request-permission.ts
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
2 changes: 1 addition & 1 deletion
2
packages/mask/background/tasks/Cancellable/InjectContentScripts-mv3.ts
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
2 changes: 1 addition & 1 deletion
2
packages/mask/background/tasks/Cancellable/InjectContentScripts.ts
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
2 changes: 1 addition & 1 deletion
2
packages/mask/background/tasks/Cancellable/IsolatedDashboardBridge.ts
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
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
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
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
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
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
export * from './messages.js' | ||
export * from './flags.js' | ||
export { InMemoryStorages, PersistentStorages } from './kv-storage.js' | ||
export * from './helpers/index.js' |
6 changes: 3 additions & 3 deletions
6
packages/mask/src/components/CompositionDialog/Composition.tsx
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
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
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.