Skip to content

Commit

Permalink
Merge pull request near#1155 from AZbang/update-herewallet
Browse files Browse the repository at this point in the history
feat: update @here-wallet/core
  • Loading branch information
Pavel Ivanov authored Aug 2, 2024
2 parents 3f3c954 + 0403785 commit c1edf6c
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 101 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"@angular/platform-browser": "16.1.9",
"@angular/platform-browser-dynamic": "16.1.9",
"@angular/router": "16.1.9",
"@here-wallet/core": "1.6.6",
"@here-wallet/core": "3.3.1",
"@jscutlery/semver": "3.1.0",
"@ledgerhq/hw-transport": "6.30.3",
"@ledgerhq/hw-transport-webhid": "6.28.6",
Expand Down
1 change: 0 additions & 1 deletion packages/here-wallet/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export type { HereWallet } from "./lib/types";
export { setupHereWallet } from "./lib";
28 changes: 10 additions & 18 deletions packages/here-wallet/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {
waitInjectedHereWallet,
type HereProvider,
type HereStrategy,
} from "@here-wallet/core";
import type { WalletModuleFactory } from "@near-wallet-selector/core";
import type { HereWallet } from "./types";
import type { HereInitializeOptions } from "@here-wallet/core";
import { waitInjectedHereWallet } from "@here-wallet/core";
import type {
WalletModuleFactory,
InjectedWallet,
} from "@near-wallet-selector/core";
import { initHereWallet } from "./selector";
import icon from "./icon";

Expand All @@ -13,16 +12,14 @@ export { icon };
interface Options {
deprecated?: boolean;
iconUrl?: string;
defaultStrategy?: () => HereStrategy;
defaultProvider?: HereProvider;
walletOptions?: HereInitializeOptions;
}

export function setupHereWallet({
deprecated = false,
iconUrl = icon,
defaultStrategy,
defaultProvider,
}: Options = {}): WalletModuleFactory<HereWallet> {
walletOptions,
}: Options = {}): WalletModuleFactory<InjectedWallet> {
return async () => {
const isInjected = await waitInjectedHereWallet;

Expand All @@ -39,12 +36,7 @@ export function setupHereWallet({
deprecated,
available: true,
},
init: (config) =>
initHereWallet({
...config,
defaultStrategy,
defaultProvider,
}),
init: (config) => initHereWallet({ ...config, walletOptions }),
};
};
}
42 changes: 10 additions & 32 deletions packages/here-wallet/src/lib/selector.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,23 @@
import type { NetworkId } from "@near-wallet-selector/core";
import { HereWallet, waitInjectedHereWallet } from "@here-wallet/core";

import type { SelectorInit } from "./types";

export const initHereWallet: SelectorInit = async (config) => {
const { store, logger, emitter, options, defaultProvider, defaultStrategy } =
config;

const here = new HereWallet({
networkId: options.network.networkId as NetworkId,
nodeUrl: options.network.nodeUrl,
defaultProvider,
defaultStrategy,
});
const { store, logger, emitter, options, walletOptions } = config;
const here = await HereWallet.connect(walletOptions);

async function getAccounts() {
logger.log("HereWallet:getAccounts");
const accountIds = await here.getAccounts();
const accounts = [];

for (let i = 0; i < accountIds.length; i++) {
accounts.push({
accountId: accountIds[i],
publicKey: (
await here.signer.getPublicKey(
accountIds[i],
options.network.networkId
)
).toString(),
});
const pub = await here.signer.getPublicKey(
accountIds[i],
options.network.networkId
);
accounts.push({ accountId: accountIds[i], publicKey: pub.toString() });
}

return accounts;
}

Expand All @@ -42,12 +30,12 @@ export const initHereWallet: SelectorInit = async (config) => {
return `https://my.herewallet.app/import?network=${options.network.networkId}`;
},

async account(id) {
async account(id: string) {
logger.log("HereWallet:account");
return await here.account(id);
},

async switchAccount(id) {
async switchAccount(id: string) {
logger.log("HereWallet:switchAccount");
await here.switchAccount(id);
},
Expand Down Expand Up @@ -80,16 +68,6 @@ export const initHereWallet: SelectorInit = async (config) => {
return await getAccounts();
},

async getHereBalance() {
logger.log("HereWallet:getHereBalance");
return await here.getHereBalance();
},

async getAvailableBalance(): Promise<bigint> {
logger.log("HereWallet:getAvailableBalance");
return await here.getAvailableBalance();
},

async signOut() {
logger.log("HereWallet:signOut");
await here.signOut();
Expand Down
13 changes: 3 additions & 10 deletions packages/here-wallet/src/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import type {
HereInitializeOptions,
HereWalletProtocol,
} from "@here-wallet/core";

import type { HereInitializeOptions } from "@here-wallet/core";
import type {
WalletBehaviourFactory,
InjectedWallet,
} from "@near-wallet-selector/core";

export type HereWallet = InjectedWallet &
Omit<Omit<Omit<HereWalletProtocol, "getAccounts">, "signIn">, "signMessage">;

export type SelectorInit = WalletBehaviourFactory<
HereWallet,
HereInitializeOptions
InjectedWallet,
{ walletOptions?: HereInitializeOptions }
>;
7 changes: 7 additions & 0 deletions packages/modal-ui/src/lib/components/WalletOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ export const WalletOptions: React.FC<WalletOptionsProps> = ({
} sidebar ${module.id}`}
key={module.id}
onClick={() => {
if (
selector.options.network.networkId === "testnet" &&
module.id === "here-wallet"
) {
alert("Here Wallet is not supported on testnet");
return;
}
if (module.id === modulesToRender[index].id) {
setActiveWalletId(module.id!);
}
Expand Down
62 changes: 23 additions & 39 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3290,12 +3290,16 @@
resolved "https://registry.yarnpkg.com/@gar/promisify/-/promisify-1.1.3.tgz#555193ab2e3bb3b6adc3d551c9c030d9e860daf6"
integrity sha512-k2Ty1JcVojjJFwrg/ThKi2ujJ7XNLYaFGNB/bWT9wGR+oSMJHMa5w+CUq6p/pVrKeNNgA7pCqEcjSnHVoqJQFw==

"@here-wallet/[email protected]":
version "1.6.6"
resolved "https://registry.yarnpkg.com/@here-wallet/core/-/core-1.6.6.tgz#db31fcd048c4977da3bc6923fcf25113a32b5a49"
integrity sha512-avh/PRNl3CbgrcbqIezVrNPAa4fqKvonl/mguSoUAfTwfA5jWnfq81Udd8QzOAIzBIGx5gSabzEkh9CRDH7yDA==
dependencies:
near-api-js "^3.0.1"
"@here-wallet/[email protected]":
version "3.3.1"
resolved "https://registry.yarnpkg.com/@here-wallet/core/-/core-3.3.1.tgz#41af535794903d4ac04ef06ac0bbee7b7bbaef8b"
integrity sha512-UcokwayE9J8HR+QUHotvpFGcZ6Xlpc1sjyzSOOeknkt2se56anJZdIPczhkwwNfYR7qAOj2fo3LTLbnmfj7GwA==
dependencies:
"@near-js/accounts" "^1.2.1"
"@near-js/crypto" "^1.2.4"
"@near-js/types" "^0.2.1"
"@near-js/utils" "^0.2.2"
js-sha256 "^0.11.0"
sha1 "^1.1.1"
uuid4 "2.0.3"

Expand Down Expand Up @@ -4230,7 +4234,7 @@
lru_map "0.4.1"
near-abi "0.1.1"

"@near-js/[email protected]":
"@near-js/[email protected]", "@near-js/accounts@^1.2.1":
version "1.2.1"
resolved "https://registry.yarnpkg.com/@near-js/accounts/-/accounts-1.2.1.tgz#6e5c0315a07997bbaacbe7b9021ac23974a80ea0"
integrity sha512-j6+9n/p0vVLAahmN3YRFve+j0ammOALC9ZUfFhdE3kqtJESbSWMviC5qF/s2m0JQjpJGDtEv/dTADosIJoanWw==
Expand Down Expand Up @@ -4269,7 +4273,7 @@
borsh "1.0.0"
randombytes "2.1.0"

"@near-js/[email protected]":
"@near-js/[email protected]", "@near-js/crypto@^1.2.4":
version "1.2.4"
resolved "https://registry.yarnpkg.com/@near-js/crypto/-/crypto-1.2.4.tgz#fad977d6a6d2c0c836ef42db8c8d355c1f433ec0"
integrity sha512-hcSj0ygvTcXlW9ftwEd9dbvQUWBCHNWNDLou9NLfmZERW9dr0gH8kUJPZUWfpJFlUPicb+jTiMpNwDTvP7VW4A==
Expand Down Expand Up @@ -4465,7 +4469,7 @@
dependencies:
bn.js "5.2.1"

"@near-js/[email protected]":
"@near-js/[email protected]", "@near-js/types@^0.2.1":
version "0.2.1"
resolved "https://registry.yarnpkg.com/@near-js/types/-/types-0.2.1.tgz#a298f0e70dbe059ee8c762dfac05c2eae3e0ae0e"
integrity sha512-YygQEGMdFe6d2e/6dtNZer9paH396XeAdIKEhY/RPXDUnjDdfiDQ5DK4mM130sEeID2bAH9X1LQ+7vXGRjvyWw==
Expand All @@ -4491,7 +4495,7 @@
depd "2.0.0"
mustache "4.0.0"

"@near-js/[email protected]":
"@near-js/[email protected]", "@near-js/utils@^0.2.2":
version "0.2.2"
resolved "https://registry.yarnpkg.com/@near-js/utils/-/utils-0.2.2.tgz#a42c29db9ccd5a02ad583319028fdb7231821ab2"
integrity sha512-ZAJo/cN6AHY7/gckf8DLHwjAn0z4UwG6rhLxs+QDyNYMMSx9SBg2pOQtBBv7ORWJaPhWD2q7wFhUz4SdTZi43A==
Expand Down Expand Up @@ -16186,6 +16190,11 @@ [email protected], js-sha256@^0.9.0:
resolved "https://registry.yarnpkg.com/js-sha256/-/js-sha256-0.9.0.tgz#0b89ac166583e91ef9123644bd3c5334ce9d0966"
integrity sha512-sga3MHh9sgQN2+pJ9VYZ+1LPwXOxuBJBA5nrR5/ofPfuiJBE2hnjsaN8se8JznOmGLN2p49Pe5U/ttafcs/apA==

js-sha256@^0.11.0:
version "0.11.0"
resolved "https://registry.yarnpkg.com/js-sha256/-/js-sha256-0.11.0.tgz#256a921d9292f7fe98905face82e367abaca9576"
integrity sha512-6xNlKayMZvds9h1Y1VWc0fQHQ82BxTXizWPEtEeGvmOUYpBRy4gbWroHLpzowe6xiQhHpelCQiE7HEdznyBL9Q==

[email protected]:
version "0.8.0"
resolved "https://registry.yarnpkg.com/js-sha3/-/js-sha3-0.8.0.tgz#b9b7a5da73afad7dedd0f8c463954cbde6818840"
Expand Down Expand Up @@ -17934,7 +17943,7 @@ near-api-js@^2.1.1:
node-fetch "^2.6.1"
tweetnacl "^1.0.1"

near-api-js@^3.0.0, near-api-js@^3.0.1:
near-api-js@^3.0.0:
version "3.0.4"
resolved "https://registry.yarnpkg.com/near-api-js/-/near-api-js-3.0.4.tgz#5ee094ce53e30239cc817ca942ec3e9739296dbb"
integrity sha512-qKWjnugoB7kSFhzZ5GXyH/eABspCQYWBmWnM4hpV5ctnQBt89LqgEu9yD1z4sa89MvUu8BuCxwb1m00BE8iofg==
Expand Down Expand Up @@ -21940,16 +21949,7 @@ string-range@~1.2, string-range@~1.2.1:
resolved "https://registry.yarnpkg.com/string-range/-/string-range-1.2.2.tgz#a893ed347e72299bc83befbbf2a692a8d239d5dd"
integrity sha512-tYft6IFi8SjplJpxCUxyqisD3b+R2CSkomrtJYCkvuf1KuCAWgz7YXt4O0jip7efpfCemwHEzTEAO8EuOYgh3w==

"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -22048,14 +22048,7 @@ string_decoder@~1.1.1:
dependencies:
safe-buffer "~5.1.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down Expand Up @@ -23863,7 +23856,7 @@ wordwrap@^1.0.0:
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb"
integrity sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q==

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand All @@ -23881,15 +23874,6 @@ wrap-ansi@^6.2.0:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"
Expand Down

0 comments on commit c1edf6c

Please sign in to comment.