Skip to content

Commit

Permalink
fix: minor errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvkelawala committed Nov 12, 2023
1 parent 7f43d59 commit 0770d3f
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/connectors/argentMobile/modal/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export abstract class NamespaceAdapter {
}: SessionTypes.Struct) => {
const chain = this.formatChainId(this.chainId)
if (requiredNamespaces) {
return !!requiredNamespaces[this.namespace]?.chains.includes(chain)
return !!requiredNamespaces[this.namespace]?.chains?.includes(chain)
}
return !!namespaces?.[this.namespace]?.accounts.some((account) =>
account.startsWith(chain),
Expand Down
3 changes: 2 additions & 1 deletion src/connectors/argentMobile/modal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export type { StarknetWindowObject, IArgentLoginOptions }

export const getStarknetWindowObject = async (
options: IArgentLoginOptions,
): Promise<ConnectedStarknetWindowObject> => login(options, StarknetAdapter)
): Promise<ConnectedStarknetWindowObject | null> =>
login(options, StarknetAdapter)
10 changes: 9 additions & 1 deletion src/connectors/argentMobile/modal/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ export const login = async <TAdapter extends NamespaceAdapter>(
walletConnect,
}: IArgentLoginOptions,
Adapter: new (options: NamespaceAdapterOptions) => TAdapter,
): Promise<TAdapter> => {
): Promise<TAdapter | null> => {
if (!bridgeUrl) {
throw new Error("bridgeUrl is required")
}

if (!mobileUrl) {
throw new Error("mobileUrl is required")
}
argentModal.bridgeUrl = bridgeUrl
argentModal.mobileUrl = mobileUrl
argentModal.type = modalType
Expand Down Expand Up @@ -101,6 +108,7 @@ export const login = async <TAdapter extends NamespaceAdapter>(
} catch (error) {
console.error("@argent/login::error")
argentModal.closeModal()
return null
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/connectors/webwallet/helpers/trpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const setPopupOptions = ({
: parentTop + parentHeight / 2 - height / 2

popupOrigin = origin ?? popupOrigin
popupLocation = location ?? location
popupLocation = location ?? popupLocation
popupParams = `width=${width},height=${height},top=${y},left=${x},toolbar=no,menubar=no,scrollbars=no,location=no,status=no,popup=1`
}

Expand Down
6 changes: 5 additions & 1 deletion src/connectors/webwallet/starknetWindowObject/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ export class MessageAccount extends Account implements AccountInterface {
height: EXECUTE_POPUP_HEIGHT,
location: "/review",
})
if (calls[0] && calls[0].entrypoint === "use_offchain_session") {
if (
Array.isArray(calls) &&
calls[0] &&
calls[0].entrypoint === "use_offchain_session"
) {
setPopupOptions({
width: 1,
height: 1,
Expand Down
14 changes: 10 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ export const connect = async ({
if (wallet) {
const connector = availableConnectors.find((c) => c.id === lastWalletId)
await connector?.connect()
selectedConnector = connector
if (connector) {
selectedConnector = connector
}
return wallet
} // otherwise fallback to modal
}
Expand All @@ -93,11 +95,13 @@ export const connect = async ({
dappName,
callback: async (value: StarknetWindowObject | null) => {
try {
if (value.id !== "argentWebWallet") {
if (value !== null && value.id !== "argentWebWallet") {
setStarknetLastConnectedWallet(value.id)
}
selectedConnector =
availableConnectors.find((c) => c.id === value.id) ?? null
availableConnectors.find(
(c) => value !== null && c.id === value.id,
) ?? null
resolve(value)
} finally {
setTimeout(() => modal.$destroy())
Expand All @@ -116,7 +120,9 @@ export const getSelectedConnectorWallet = () =>

export const disconnect = async (options: DisconnectOptions = {}) => {
removeStarknetLastConnectedWallet()
await selectedConnector.disconnect()
if (selectedConnector) {
await selectedConnector.disconnect()
}
selectedConnector = null

return sn.disconnect(options)
Expand Down
2 changes: 1 addition & 1 deletion src/modal/Modal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
darkModeControlClass = ""
}
if (isInAppBrowser) {
if (isInAppBrowser && window?.starknet_argentX) {
try {
const enabledValue = await sn.enable(window?.starknet_argentX)
callback(enabledValue ?? window?.starknet_argentX)
Expand Down
6 changes: 4 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
*/
"allowJs": true,
"checkJs": true,
"declaration": true
"declaration": true,
"verbatimModuleSyntax": false
},
"include": ["src"]
"include": ["src"],
"exclude": ["node_modules"]
}

0 comments on commit 0770d3f

Please sign in to comment.