Skip to content

Commit

Permalink
✨ Add wc uri in likerland getapp button
Browse files Browse the repository at this point in the history
  • Loading branch information
williamchong committed Jun 26, 2023
1 parent 403e998 commit aef13c1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
6 changes: 2 additions & 4 deletions src/components/connection-method-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface Props {
url?: string;
isMobile?: boolean;
keplrInstallCTAPreset?: KeplrInstallCTAPreset;
onPress?: () => void;
onPress?: (params?: any) => void;
}

/**
Expand Down Expand Up @@ -83,6 +83,7 @@ export const ConnectionMethodButton: FC<Props> = ({

const handleClickInstallLikerLandAppButton: MouseEventHandler = e => {
e.stopPropagation();
if (onPress) onPress({ goToGetApp: true });
};

const handleClickOpenInDAppBrowserButton: MouseEventHandler = e => {
Expand Down Expand Up @@ -197,9 +198,6 @@ export const ConnectionMethodButton: FC<Props> = ({
{type === LikeCoinWalletConnectorMethodType.LikerId && (
<div className="lk-flex lk-justify-center lk-mt-[12px]">
<Button
tag="a"
href={url}
target="_blank"
onClick={handleClickInstallLikerLandAppButton}
>
<DownloadIcon />
Expand Down
8 changes: 4 additions & 4 deletions src/components/connection-method-list-base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface ConnectionMethodListBaseProps
methods: LikeCoinWalletConnectorMethod[];
isMobile: boolean;
keplrInstallCTAPreset?: KeplrInstallCTAPreset;
onSelectMethod?: (method: LikeCoinWalletConnectorMethodType) => void;
onSelectMethod?: (method: LikeCoinWalletConnectorMethodType, params?: any) => void;
}

export const ConnectionMethodListBase: React.FC<ConnectionMethodListBaseProps> = ({
Expand All @@ -25,8 +25,8 @@ export const ConnectionMethodListBase: React.FC<ConnectionMethodListBaseProps> =
onSelectMethod,
...props
}) => {
function handleMethodSelection(method: LikeCoinWalletConnectorMethodType) {
if (onSelectMethod) onSelectMethod(method);
function handleMethodSelection(method: LikeCoinWalletConnectorMethodType, params?: any) {
if (onSelectMethod) onSelectMethod(method, params);
}

return (
Expand All @@ -46,7 +46,7 @@ export const ConnectionMethodListBase: React.FC<ConnectionMethodListBaseProps> =
url={method.url}
keplrInstallCTAPreset={keplrInstallCTAPreset}
isMobile={isMobile}
onPress={() => handleMethodSelection(method.type)}
onPress={(params?: any) => handleMethodSelection(method.type, params)}
/>
</li>
))}
Expand Down
2 changes: 1 addition & 1 deletion src/components/connection-method-selection-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export interface ConnectionMethodSelectionDialogProps
keplrInstallURLOverride?: string;
keplrInstallCTAPreset?: KeplrInstallCTAPreset;
onClose?: () => void;
onConnect?: (method: LikeCoinWalletConnectorMethodType) => void;
onConnect?: (method: LikeCoinWalletConnectorMethodType, params?: any) => void;
}

/**
Expand Down
23 changes: 15 additions & 8 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,10 @@ export class LikeCoinWalletConnector {
return new Promise<LikeCoinWalletConnectorConnectionResponse>(
async resolve => {
const connectWithMethod = async (
method: LikeCoinWalletConnectorMethodType
method: LikeCoinWalletConnectorMethodType,
params?: any,
) => {
const result = await this.selectMethod(method);
const result = await this.selectMethod(method, params);
resolve(result);
};
if (checkIsInLikerLandAppInAppBrowser()) {
Expand Down Expand Up @@ -214,10 +215,10 @@ export class LikeCoinWalletConnector {
this._isWalletConnectQRCodeDialogOpen = false;
};

private selectMethod = async (method: LikeCoinWalletConnectorMethodType) => {
private selectMethod = async (method: LikeCoinWalletConnectorMethodType, params?: any) => {
this.closeDialog();

return this.init(method);
return this.init(method, params);
};

disconnect = async () => {
Expand Down Expand Up @@ -267,17 +268,22 @@ export class LikeCoinWalletConnector {
};

private getWCQRCodeDialog: (
methodType: LikeCoinWalletConnectorMethodType
) => IQRCodeModal = (methodType: LikeCoinWalletConnectorMethodType) => ({
methodType: LikeCoinWalletConnectorMethodType,
params?: any,
) => IQRCodeModal = (methodType: LikeCoinWalletConnectorMethodType, params?: any) => ({
open: uri => {
if (methodType === LikeCoinWalletConnectorMethodType.LikerId && params?.goToGetApp) {
window.location.href = `https://liker.land/getapp?action=wc&uri=${encodeURIComponent(uri)}`;
return;
}
this.openWalletConnectQRCodeDialog(methodType, uri);
},
close: () => {
this.closeDialog();
},
});

init = async (methodType: LikeCoinWalletConnectorMethodType) => {
init = async (methodType: LikeCoinWalletConnectorMethodType, params?: any) => {
let initiator: Promise<LikeCoinWalletConnectorInitResponse>;

switch (methodType) {
Expand Down Expand Up @@ -310,9 +316,10 @@ export class LikeCoinWalletConnector {
break;

case LikeCoinWalletConnectorMethodType.LikerId:
const { goToGetApp } = params || {};
initiator = initLikerLandApp(
this.options,
this.getWCQRCodeDialog(LikeCoinWalletConnectorMethodType.LikerId),
this.getWCQRCodeDialog(LikeCoinWalletConnectorMethodType.LikerId, { goToGetApp }),
this.sessionMethod,
this.sessionAccounts
);
Expand Down

0 comments on commit aef13c1

Please sign in to comment.