Skip to content

Commit

Permalink
Merge branch 'Thunnini/prepare-mobile-2.0-merge' into retto/KM-110
Browse files Browse the repository at this point in the history
  • Loading branch information
blacktoast committed Dec 9, 2023
2 parents b2d499a + 308ada3 commit 0bc4c87
Show file tree
Hide file tree
Showing 160 changed files with 5,570 additions and 1,698 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
KEPLR_EXT_TRANSAK_API_KEY: ${{ secrets.KEPLR_EXT_TRANSAK_API_KEY }}
KEPLR_EXT_MOONPAY_API_KEY: ${{ secrets.KEPLR_EXT_MOONPAY_API_KEY }}
KEPLR_EXT_KADO_API_KEY: ${{ secrets.KEPLR_EXT_KADO_API_KEY }}
KEPLR_EXT_CHAIN_REGISTRY_URL: ${{ secrets.KEPLR_EXT_CHAIN_REGISTRY_URL }}
- run: sudo apt-get install gh
- run: npx zx ./scripts/publish.mjs
env:
Expand All @@ -63,7 +64,7 @@ jobs:
- run: cp ./build/firefox-archive.tar.gz ../firefox-archive.tar.gz
- run: mkdir temp && tar xvzf firefox-archive.tar.gz -C temp
working-directory: ..
- run: docker build -f ./docker/Dockerfile -t builder --build-arg KEPLR_EXT_ETHEREUM_ENDPOINT=$KEPLR_EXT_ETHEREUM_ENDPOINT --build-arg KEPLR_EXT_AMPLITUDE_API_KEY=$KEPLR_EXT_AMPLITUDE_API_KEY --build-arg KEPLR_EXT_ANALYTICS_API_AUTH_TOKEN=$KEPLR_EXT_ANALYTICS_API_AUTH_TOKEN --build-arg KEPLR_EXT_ANALYTICS_API_URL=$KEPLR_EXT_ANALYTICS_API_URL --build-arg KEPLR_EXT_COINGECKO_ENDPOINT=$KEPLR_EXT_COINGECKO_ENDPOINT --build-arg KEPLR_EXT_COINGECKO_GETPRICE=$KEPLR_EXT_COINGECKO_GETPRICE --build-arg KEPLR_EXT_TRANSAK_API_KEY=$KEPLR_EXT_TRANSAK_API_KEY --build-arg KEPLR_EXT_MOONPAY_API_KEY=$KEPLR_EXT_MOONPAY_API_KEY --build-arg KEPLR_EXT_KADO_API_KEY=$KEPLR_EXT_KADO_API_KEY .
- run: docker build -f ./docker/Dockerfile -t builder --build-arg KEPLR_EXT_ETHEREUM_ENDPOINT=$KEPLR_EXT_ETHEREUM_ENDPOINT --build-arg KEPLR_EXT_AMPLITUDE_API_KEY=$KEPLR_EXT_AMPLITUDE_API_KEY --build-arg KEPLR_EXT_ANALYTICS_API_AUTH_TOKEN=$KEPLR_EXT_ANALYTICS_API_AUTH_TOKEN --build-arg KEPLR_EXT_ANALYTICS_API_URL=$KEPLR_EXT_ANALYTICS_API_URL --build-arg KEPLR_EXT_COINGECKO_ENDPOINT=$KEPLR_EXT_COINGECKO_ENDPOINT --build-arg KEPLR_EXT_COINGECKO_GETPRICE=$KEPLR_EXT_COINGECKO_GETPRICE --build-arg KEPLR_EXT_TRANSAK_API_KEY=$KEPLR_EXT_TRANSAK_API_KEY --build-arg KEPLR_EXT_MOONPAY_API_KEY=$KEPLR_EXT_MOONPAY_API_KEY --build-arg KEPLR_EXT_KADO_API_KEY=$KEPLR_EXT_KADO_API_KEY --build-arg KEPLR_EXT_CHAIN_REGISTRY_URL=$KEPLR_EXT_CHAIN_REGISTRY_URL .
working-directory: ../temp
env:
KEPLR_EXT_ETHEREUM_ENDPOINT: ${{ secrets.KEPLR_EXT_ETHEREUM_ENDPOINT }}
Expand All @@ -75,6 +76,7 @@ jobs:
KEPLR_EXT_TRANSAK_API_KEY: ${{ secrets.KEPLR_EXT_TRANSAK_API_KEY }}
KEPLR_EXT_MOONPAY_API_KEY: ${{ secrets.KEPLR_EXT_MOONPAY_API_KEY }}
KEPLR_EXT_KADO_API_KEY: ${{ secrets.KEPLR_EXT_KADO_API_KEY }}
KEPLR_EXT_CHAIN_REGISTRY_URL: ${{ secrets.KEPLR_EXT_CHAIN_REGISTRY_URL }}
- run: docker run -v $(pwd):/data builder
working-directory: ../temp
- run: sudo apt-get update
Expand Down
2 changes: 2 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ ARG KEPLR_EXT_COINGECKO_GETPRICE
ARG KEPLR_EXT_TRANSAK_API_KEY
ARG KEPLR_EXT_MOONPAY_API_KEY
ARG KEPLR_EXT_KADO_API_KEY
ARG KEPLR_EXT_CHAIN_REGISTRY_URL

ENV KEPLR_EXT_ETHEREUM_ENDPOINT $KEPLR_EXT_ETHEREUM_ENDPOINT
ENV KEPLR_EXT_AMPLITUDE_API_KEY $KEPLR_EXT_AMPLITUDE_API_KEY
Expand All @@ -41,6 +42,7 @@ ENV KEPLR_EXT_COINGECKO_GETPRICE $KEPLR_EXT_COINGECKO_GETPRICE
ENV KEPLR_EXT_TRANSAK_API_KEY $KEPLR_EXT_TRANSAK_API_KEY
ENV KEPLR_EXT_MOONPAY_API_KEY $KEPLR_EXT_MOONPAY_API_KEY
ENV KEPLR_EXT_KADO_API_KEY $KEPLR_EXT_KADO_API_KEY
ENV KEPLR_EXT_CHAIN_REGISTRY_URL $KEPLR_EXT_CHAIN_REGISTRY_URL

RUN yarn install --immutable

Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.12.32",
"version": "0.12.47",
"useWorkspaces": true,
"npmClient": "yarn",
"command": {
Expand Down
2 changes: 1 addition & 1 deletion packages/analytics/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@keplr-wallet/analytics",
"version": "0.12.32",
"version": "0.12.47",
"main": "build/index.js",
"author": "chainapsis",
"license": "Apache-2.0",
Expand Down
24 changes: 12 additions & 12 deletions packages/background/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@keplr-wallet/background",
"version": "0.12.32",
"version": "0.12.47",
"main": "build/index.js",
"author": "chainapsis",
"license": "Apache-2.0",
Expand Down Expand Up @@ -28,17 +28,17 @@
"@ethersproject/hash": "^5.7.0",
"@ethersproject/transactions": "^5.7.0",
"@ethersproject/wallet": "^5.7.0",
"@keplr-wallet/chain-validator": "0.12.32",
"@keplr-wallet/common": "0.12.32",
"@keplr-wallet/cosmos": "0.12.32",
"@keplr-wallet/crypto": "0.12.32",
"@keplr-wallet/ledger-cosmos": "0.12.32",
"@keplr-wallet/popup": "0.12.32",
"@keplr-wallet/proto-types": "0.12.32",
"@keplr-wallet/router": "0.12.32",
"@keplr-wallet/simple-fetch": "0.12.32",
"@keplr-wallet/types": "0.12.32",
"@keplr-wallet/unit": "0.12.32",
"@keplr-wallet/chain-validator": "0.12.47",
"@keplr-wallet/common": "0.12.47",
"@keplr-wallet/cosmos": "0.12.47",
"@keplr-wallet/crypto": "0.12.47",
"@keplr-wallet/ledger-cosmos": "0.12.47",
"@keplr-wallet/popup": "0.12.47",
"@keplr-wallet/proto-types": "0.12.47",
"@keplr-wallet/router": "0.12.47",
"@keplr-wallet/simple-fetch": "0.12.47",
"@keplr-wallet/types": "0.12.47",
"@keplr-wallet/unit": "0.12.47",
"@ledgerhq/hw-app-eth": "^6.29.3",
"@ledgerhq/hw-transport": "^6.20.0",
"@ledgerhq/hw-transport-webhid": "^6.20.0",
Expand Down
14 changes: 9 additions & 5 deletions packages/background/src/analytics/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,15 @@ export class AnalyticsService {
v2: true,
})
).toString("base64");
await simpleFetch(KEPLR_EXT_ANALYTICS_API_URL, `/log?msg=${loggingMsg}`, {
headers: {
Authorization: KEPLR_EXT_ANALYTICS_API_AUTH_TOKEN,
},
});
await simpleFetch(
KEPLR_EXT_ANALYTICS_API_URL,
`/log?msg=${encodeURIComponent(loggingMsg)}`,
{
headers: {
Authorization: KEPLR_EXT_ANALYTICS_API_AUTH_TOKEN,
},
}
);
}

logEventIgnoreError(
Expand Down
11 changes: 8 additions & 3 deletions packages/background/src/chains-update/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,14 @@ export class ChainsUpdateService {

let updated1 = false;
if (!chainInfo.updateFromRepoDisabled) {
updated1 = await this.chainsService.tryUpdateChainInfoFromRepo(
chainIdentifier
);
try {
updated1 = await this.chainsService.tryUpdateChainInfoFromRepo(
chainIdentifier
);
} catch (e) {
console.log(e);
// Ignore error to proceed to tryUpdateChainInfoFromRpcOrRest if it fails.
}
}

const updated2 = await this.chainsService.tryUpdateChainInfoFromRpcOrRest(
Expand Down
21 changes: 16 additions & 5 deletions packages/background/src/chains/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,14 @@ export class ChainsService {
readonly organizationName: string;
readonly repoName: string;
readonly branchName: string;
readonly alternativeURL?: string;
},
protected readonly interactionService: InteractionService,
protected readonly afterInitFn:
| ((service: ChainsService) => void | Promise<void>)
| ((
service: ChainsService,
lastEmbedChainInfos: ChainInfoWithCoreTypes[]
) => void | Promise<void>)
| undefined
) {
this.updatedChainInfoKVStore = new PrefixKVStore(
Expand Down Expand Up @@ -237,11 +241,14 @@ export class ChainsService {
* 모든 서비스가 init이 된 이후에 실행될 추가적인 로직을 여기에 작성할 수 있다.
*/
async afterInit(): Promise<void> {
const lastEmbedChainInfos = await this.kvStore.get<
ChainInfoWithCoreTypes[]
>("last_embed_chain_infos");

if (this.afterInitFn) {
await this.afterInitFn(this);
await this.afterInitFn(this, lastEmbedChainInfos ?? []);
}

// 그냥 미래에 필요할지도 몰라서...
await this.kvStore.set(
"last_embed_chain_infos",
toJS(this.embedChainInfos)
Expand Down Expand Up @@ -352,8 +359,12 @@ export class ChainsService {
const chainIdentifier = ChainIdHelper.parse(chainId).identifier;

const res = await simpleFetch<ChainInfo>(
`https://raw.githubusercontent.com/${this.communityChainInfoRepo.organizationName}/${this.communityChainInfoRepo.repoName}/${this.communityChainInfoRepo.branchName}`,
`/cosmos/${chainIdentifier}.json`
this.communityChainInfoRepo.alternativeURL
? this.communityChainInfoRepo.alternativeURL.replace(
"{chain_identifier}",
chainIdentifier
)
: `https://raw.githubusercontent.com/${this.communityChainInfoRepo.organizationName}/${this.communityChainInfoRepo.repoName}/${this.communityChainInfoRepo.branchName}/cosmos/${chainIdentifier}.json`
);
let chainInfo: ChainInfo = res.data;

Expand Down
14 changes: 11 additions & 3 deletions packages/background/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export * from "./recent-send-history";
import { KVStore } from "@keplr-wallet/common";
import { ChainInfo } from "@keplr-wallet/types";
import { Notification } from "./tx";
import { ChainInfoWithCoreTypes } from "./chains";

export function init(
router: Router,
Expand All @@ -63,6 +64,7 @@ export function init(
readonly organizationName: string;
readonly repoName: string;
readonly branchName: string;
readonly alternativeURL?: string;
},
notification: Notification,
addDeviceLockedListener: (callback: () => void) => void,
Expand All @@ -71,7 +73,10 @@ export function init(
commonCrypto: KeyRingLegacy.CommonCrypto;
readonly getDisabledChainIdentifiers: () => Promise<string[]>;
},
afterInitFn?: (service: Chains.ChainsService) => void | Promise<void>
afterInitFn?: (
service: Chains.ChainsService,
lastEmbedChainInfos: ChainInfoWithCoreTypes[]
) => void | Promise<void>
): {
initFn: () => Promise<void>;
keyRingService: KeyRingV2.KeyRingService;
Expand Down Expand Up @@ -147,6 +152,7 @@ export function init(
chainsService,
interactionService,
vaultService,
analyticsService,
[
new KeyRingMnemonic.KeyRingMnemonicService(vaultService),
new KeyRingLedger.KeyRingLedgerService(),
Expand Down Expand Up @@ -205,7 +211,8 @@ export function init(
new RecentSendHistory.RecentSendHistoryService(
storeCreator("recent-send-history"),
chainsService,
backgroundTxService
backgroundTxService,
notification
);

Interaction.init(router, interactionService);
Expand Down Expand Up @@ -246,6 +253,8 @@ export function init(

return {
initFn: async () => {
await analyticsService.init();

await chainsService.init();
await vaultService.init();
await chainsUIService.init();
Expand All @@ -259,7 +268,6 @@ export function init(
await backgroundTxService.init();
await phishingListService.init();
await autoLockAccountService.init();
await analyticsService.init();
await permissionInteractiveService.init();

await secretWasmService.init();
Expand Down
45 changes: 38 additions & 7 deletions packages/background/src/keyring/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Buffer } from "buffer/";
import * as Legacy from "./legacy";
import { ChainsUIService } from "../chains-ui";
import { MultiAccounts } from "../keyring-keystone";
import { AnalyticsService } from "../analytics";

export class KeyRingService {
protected _needMigration = false;
Expand All @@ -31,6 +32,7 @@ export class KeyRingService {
protected readonly chainsService: ChainsService,
protected readonly interactionService: InteractionService,
protected readonly vaultService: VaultService,
protected readonly analyticsService: AnalyticsService,
protected readonly keyRings: KeyRing[]
) {
makeObservable(this);
Expand Down Expand Up @@ -64,6 +66,34 @@ export class KeyRingService {
this.kvStore.set<string>("selectedVaultId", null);
}
});

autorun(() => {
const vaults = this.getKeyRingVaults();
const numPerTypes: Record<string, number> = {};
for (const vault of vaults) {
let type = vault.insensitive["keyRingType"] as string;
if (type === "private-key") {
const meta = vault.insensitive["keyRingMeta"] as PlainObject;
if (meta["web3Auth"] && (meta["web3Auth"] as any)["type"]) {
type = "web3_auth_" + (meta["web3Auth"] as any)["type"];
}
}

if (type) {
type = "keyring_" + type + "_num";

if (!numPerTypes[type]) {
numPerTypes[type] = 0;
}
numPerTypes[type] += 1;
}
}

this.analyticsService.logEvent("user_properties", {
keyring_num: vaults.length,
...numPerTypes,
});
});
}

lockKeyRing(): void {
Expand Down Expand Up @@ -863,7 +893,6 @@ export class KeyRingService {
);
}

@action
async deleteKeyRing(vaultId: string, password: string) {
if (this.vaultService.isLocked) {
throw new Error("KeyRing is locked");
Expand All @@ -881,12 +910,14 @@ export class KeyRingService {
this.vaultService.removeVault("keyRing", vaultId);

if (wasSelected) {
const keyInfos = this.getKeyInfos();
if (keyInfos.length > 0) {
this._selectedVaultId = keyInfos[0].id;
} else {
this._selectedVaultId = undefined;
}
runInAction(() => {
const keyInfos = this.getKeyInfos();
if (keyInfos.length > 0) {
this._selectedVaultId = keyInfos[0].id;
} else {
this._selectedVaultId = undefined;
}
});
}

if (wasSelected) {
Expand Down
11 changes: 8 additions & 3 deletions packages/background/src/recent-send-history/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ const handleSendTxAndRecordMsg: (
msg.recipient,
msg.amount,
msg.memo,
undefined
undefined,
{
currencies: [],
}
);
};
};
Expand All @@ -105,7 +108,8 @@ const handleSendTxAndRecordWithIBCPacketForwardingMsg: (
msg.recipient,
msg.amount,
msg.memo,
msg.channels
msg.channels,
msg.notificationInfo
);
};
};
Expand All @@ -127,7 +131,8 @@ const handleSendTxAndRecordWithIBCSwapMsg: (
msg.channels,
msg.destinationAsset,
msg.swapChannelIndex,
msg.swapReceiver
msg.swapReceiver,
msg.notificationInfo
);
};
};
Expand Down
Loading

0 comments on commit 0bc4c87

Please sign in to comment.