Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add authcore login #452

Merged
merged 5 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion components/Alerts/SignFailed.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default class SignFailed extends Vue {
@walletModule.Action closeSnackbar!: () => void
@walletModule.Action('disconnectWallet') disconnectWallet!: () => void
@walletModule.Action('openConnectWalletModal')
openConnectWalletModal!: (params: { language: string }) => Promise<any>
openConnectWalletModal!: (params: { language: string, fullPath?: string }) => Promise<any>
@walletModule.Action('initWallet') initWallet!: (params: {
method: any
Expand Down Expand Up @@ -72,6 +72,7 @@ export default class SignFailed extends Vue {
await this.disconnectWallet()
const connection = await this.openConnectWalletModal({
language: this.$i18n.locale.split('-')[0],
fullPath: this.$route.fullPath,
})
if (connection) {
const { method, accounts } = connection
Expand Down
15 changes: 10 additions & 5 deletions components/AppHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@
:title="currentAddress"
>
<template
v-if="isWalletFromLikerLikerApp"
v-if="isUsingMobileApp"
#prepend
>
<IconWalletConnectLogo />
</template>
<div
:class="[
isWalletFromLikerLikerApp ? 'w-[116px]' : 'w-[148px]',
isUsingMobileApp ? 'w-[116px]' : 'w-[148px]',
'overflow-hidden',
'overflow-ellipsis',
]"
Expand Down Expand Up @@ -162,7 +162,7 @@ const walletModule = namespace('wallet')
export default class AppHeader extends Vue {
@walletModule.Getter('getType') walletType!: string | null
@walletModule.Action('disconnectWallet') disconnectWallet!: () => void
@walletModule.Action('openConnectWalletModal') openConnectWalletModal!: (params: { language: string }) => Promise<any>
@walletModule.Action('openConnectWalletModal') openConnectWalletModal!: (params: { language: string, fullPath?: string }) => Promise<any>
@walletModule.Action('initWallet') initWallet!: (params: { method: any, accounts: any, offlineSigner?: any }) => Promise<any>
@walletModule.Getter('getWalletAddress') currentAddress!: string

Expand All @@ -171,8 +171,12 @@ export default class AppHeader extends Vue {
return !!IS_TESTNET
}

get isWalletFromLikerLikerApp() {
return this.walletType === 'liker-id';
get isUsingMobileApp() {
return this.walletType?.includes('mobile') || this.walletType?.includes('walletconnect') || this.isUsingLikerLandApp
}

get isUsingLikerLandApp() {
return this.walletType === 'likerland-app'
}

handleClickSignOutButton() {
Expand All @@ -182,6 +186,7 @@ export default class AppHeader extends Vue {
async handleConnectWalletButtonClick() {
const connection = await this.openConnectWalletModal({
language: this.$i18n.locale.split('-')[0],
fullPath: this.$route.fullPath,
})
if (connection) {
const { method, accounts } = connection
Expand Down
23 changes: 7 additions & 16 deletions components/Attentions/OpenLikerLandApp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,20 @@
]"
>
<IconAttention class="mr-[12px] w-[32px]" />
<a
:href="LIKER_LAND_APP_URI"
<Label
class="whitespace-pre-line text-dark-gray underline"
:text="$t('NFTPortal.attention.openApp')"
>
<Label
class="whitespace-pre-line text-dark-gray underline"
:text="$t('NFTPortal.attention.openApp')"
>
<template #prepend>
<IconLikerLandApp :class="['inline', 'w-[32px]', 'h-[32px]']" />
</template>
</Label>
</a>
<template #prepend>
<IconLikerLandApp :class="['inline', 'w-[32px]', 'h-[32px]']" />
</template>
</Label>
</div>
</template>
<script lang="ts">
import { Vue, Component } from 'vue-property-decorator'
import { LIKER_LAND_APP_URI } from '~/constant';

@Component
export default class OpenLikerLandApp extends Vue {
// eslint-disable-next-line class-methods-use-this
get LIKER_LAND_APP_URI() {
return LIKER_LAND_APP_URI;
}
}
</script>
12 changes: 6 additions & 6 deletions components/IscnRegisterForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ export default class IscnRegisterForm extends Vue {
isOpenFileInfoDialog = false
isOpenAuthorDialog = false
isOpenWarningSnackbar = false
isOpenKeplr = true
isOpenWallet = true
activeEditingAuthorIndex = -1

isOpenSignDialog = false
Expand Down Expand Up @@ -1018,11 +1018,11 @@ export default class IscnRegisterForm extends Vue {

get buttonState() {
return {
preset: this.isOpenKeplr ? 'tertiary' : 'outline',
text: this.isOpenKeplr
? this.$t('IscnRegisterForm.signDialog.keplr')
preset: this.isOpenWallet ? 'tertiary' : 'outline',
text: this.isOpenWallet
? this.$t('IscnRegisterForm.signDialog.wallet')
: this.$t('IscnRegisterForm.signDialog.retry'),
isDisable: this.isOpenKeplr,
isDisable: this.isOpenWallet,
}
}

Expand Down Expand Up @@ -1318,7 +1318,7 @@ estimation,

onOpenKeplr() {
logTrackerEvent(this, 'ISCNCreate', 'OpenKeplr', '', 1)
this.isOpenKeplr = true
this.isOpenWallet = true
}

validateField(
Expand Down
12 changes: 0 additions & 12 deletions components/IscnUploadForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@
isOpenFileInfoDialog = false
isOpenSignDialog = false
isOpenWarningSnackbar = false
isOpenKeplr = true
isSizeExceeded = false
isAddISCNPageToEpub = false

Expand Down Expand Up @@ -630,7 +629,7 @@
}
this.epubMetadataList.push(epubMetadata)
} catch (err) {
console.error(err)

Check warning on line 632 in components/IscnUploadForm.vue

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest, 18)

Unexpected console statement
}
}

Expand Down Expand Up @@ -688,16 +687,6 @@
this.displayExifInfo = this.fileRecords[index].exifInfo
}

onOpenKeplr() {
logTrackerEvent(this, 'ISCNCreate', 'OpenKeplr', '', 1);
this.isOpenKeplr = true
// Hack: In some cases, there might be no response from Keplr,
// so we set a timeout to automatically close it after 5 seconds.
setTimeout(() => {
this.isOpenKeplr = false
}, 5000)
}

async estimateArweaveFee(): Promise<void> {
try {
const results = await Promise.all(
Expand Down Expand Up @@ -783,7 +772,6 @@
logTrackerEvent(this, 'ISCNCreate', 'SubmitToArweave', '', 1);
if (!tempRecord.fileBlob) return;
this.isOpenSignDialog = true;
this.onOpenKeplr();

tempRecord.transactionHash = transactionHash
if (!tempRecord.transactionHash) {
Expand Down
10 changes: 7 additions & 3 deletions components/MintPageContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
<slot />
<div class="flex flex-col max-w-[600px]">
<div class="mt-[-20px]">
<AttentionsOpenLikerLandApp v-if="isUsingLikerLandApp && isStateTransaction" />
<AttentionsLedger v-if="!isUsingLikerLandApp" />
<AttentionsOpenLikerLandApp v-if="isUsingMobileApp && isStateTransaction" />
<AttentionsLedger v-if="!isUsingMobileApp" />
<AlertsSignFailed />
</div>
</div>
Expand All @@ -72,8 +72,12 @@ export default class Min5PageContainer extends Vue {
@Prop({ default: false }) readonly isStateTransaction: boolean | undefined


get isUsingMobileApp() {
return this.walletType?.includes('mobile') || this.walletType?.includes('walletconnect') || this.isUsingLikerLandApp
}

get isUsingLikerLandApp() {
return this.walletType === 'liker-id'
return this.walletType === 'likerland-app'
}

get googleFormUrl() {
Expand Down
1 change: 1 addition & 0 deletions components/NFTMint/Process.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
class="
w-full
bg-shade-gray
break-words
px-[16px]
py-[8px]
rounded-[12px]
Expand Down
8 changes: 7 additions & 1 deletion constant/network.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
IS_TESTNET,
SITE_URL,
LIKECOIN_CHAIN_ID,
LIKECOIN_CHAIN_NFT_RPC,
LIKECOIN_CHAIN_API,
Expand Down Expand Up @@ -62,11 +63,12 @@ export const LIKECOIN_WALLET_CONNECTOR_CONFIG = {
bech32PrefixConsAddr: 'likevalcons',
bech32PrefixConsPub: 'likevalconspub',
availableMethods: [
'liker-id',
'keplr',
'keplr-mobile',
'cosmostation',
'cosmostation-mobile',
'liker-id',
'likerland-app',
'leap',
'metamask-leap',
'walletconnect-v2',
Expand All @@ -81,6 +83,10 @@ export const LIKECOIN_WALLET_CONNECTOR_CONFIG = {
icons: ['https://like.co/logo.png'],
name: 'app.like.co',
},
authcoreApiHost: IS_TESTNET
? 'https://likecoin-integration-test.authcore.io'
: 'https://authcore.like.co',
authcoreRedirectUrl: `${SITE_URL}/auth/redirect?method=liker-id`,
};

const combinedConfig = {
Expand Down
3 changes: 2 additions & 1 deletion layouts/wallet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const walletModule = namespace('wallet')
@Component
export default class WalletLayout extends Vue {
@walletModule.Getter('getWalletAddress') walletAddress!: string
@walletModule.Action('openConnectWalletModal') openConnectWalletModal!: (params: { language: string }) => Promise<any>
@walletModule.Action('openConnectWalletModal') openConnectWalletModal!: (params: { language: string, fullPath?: string }) => Promise<any>
@walletModule.Action('initWallet') initWallet!: (params: { method: any, accounts: any, offlineSigner?: any }) => Promise<any>
@walletModule.Action('restoreSessionIfNecessary') restoreSessionIfNecessary!: () => Promise<any>

Expand All @@ -41,6 +41,7 @@ export default class WalletLayout extends Vue {
if (!this.walletAddress) {
const connection = await this.openConnectWalletModal({
language: this.$i18n.locale.split('-')[0],
fullPath: this.$route.fullPath,
})
// Re-login
if (connection) {
Expand Down
5 changes: 3 additions & 2 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,11 @@
"IscnRegisterForm.register.fee": "Fee: {fee} LIKE",
"IscnRegisterForm.signDialog.closeWarning": "Please don't close the window...",
"IscnRegisterForm.signDialog.fee": "Fee",
"IscnRegisterForm.signDialog.keplr": "Opening Keplr ...",
"IscnRegisterForm.signDialog.retry": "Retry",
"IscnRegisterForm.signDialog.sign.arweave.upload": "Please sign to upload to Arweave",
"IscnRegisterForm.signDialog.sign.arweave.uploading": "Depending on the file size, it may take several minutes.\n You will be requested to sign again before finishing.",
"IscnRegisterForm.signDialog.sign.iscn.register": "Please sign to register ISCN record",
"IscnRegisterForm.signDialog.wallet": "Opening Wallet ...",
"IscnRegisterForm.sameAsDialog.title": "Define sameAs URLs",
"IscnRegisterForm.title.editAuthor": "Add Author",
"IscnRegisterForm.title.editStakeholder": "Edit Stakeholder",
Expand All @@ -273,7 +273,7 @@
"IscnUploaded.button.new": "Register Another ISCN",
"IscnUploaded.guide.title": "Completed! Here is your ISCN",
"IscnUploaded.title": "ISCN Registerd",
"NFTPortal.attention.openApp": "You have connected with WalletConnect. Please approve the transaction in Liker Land app.",
"NFTPortal.attention.openApp": "You have connected with WalletConnect. Please approve the transaction in wallet app.",
"NFTPortal.button.create": "Create",
"NFTPortal.button.collect": "Collect Now",
"NFTPortal.button.convertToIscn": "Convert Content to Writing NFT",
Expand Down Expand Up @@ -365,6 +365,7 @@
"page.iscnId.default.title": "ISCN Viewer - Decentralized Publishing - LikeCoin",
"page.iscnId.default.description": "Mint Writing NFT for your content. Turn your stories into collectibles.",
"Registration.step": "Step {step}/{total}",
"RedirectPage.title": "Redirecting...",
"SearchPage.empty.label": "No record",
"SearchPage.error": "Oops, something went wrong please try again",
"UploadForm.attention": "Do not connect to Ledger hardware wallets for signing.\n Ledger service temporarily unavailable.",
Expand Down
2 changes: 2 additions & 0 deletions nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ export default {
],
'frame-src': [
'verify.walletconnect.com',
'authcore.like.co',
'likecoin-integration-test.authcore.io',
],
'style-src': [
"'self'",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@keplr-wallet/types": "^0.11.4",
"@likecoin/iscn-js": "^0.6.10",
"@likecoin/iscn-message-types": "^0.0.7",
"@likecoin/wallet-connector": "^0.25.3",
"@likecoin/wallet-connector": "^0.26.1",
"@nuxtjs/axios": "^5.13.6",
"@nuxtjs/i18n": "^7.0.1",
"@nuxtjs/pwa": "^3.3.5",
Expand Down
73 changes: 73 additions & 0 deletions pages/auth/redirect.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<template>
<main class="redirect-page">
<div class="flex flex-col items-center my-48">
<h1 class="text-24">{{ $t('RedirectPage.title') }}</h1>
<ProgressIndicator preset="thin" />
</div>
</main>
</template>

<script lang="ts">
import { Vue, Component } from 'vue-property-decorator'
import { namespace } from 'vuex-class'
import logTrackerEvent, { setLoggerUser } from '~/utils/logger'

const walletModule = namespace('wallet')

@Component
export default class RedirectPage extends Vue {
@walletModule.Action('initWallet') initWallet!: (params: { method: any; accounts: any; offlineSigner?: any }) => Promise<any>
@walletModule.Action('handleConnectorRedirect') handleConnectorRedirect!: (params: { method: string; params: any }) => Promise<any>

async mounted() {
const { error, method, code } = this.$route.query;
if (method && code) {
try {
const connection = await this.handleConnectorRedirect({
method: method as string,
params: { code },
});
if (connection) {
const { accounts } = connection
logTrackerEvent(
this,
'user',
`connected_wallet_${method}`,
'connected_wallet',
1,
)
setLoggerUser(this, {
wallet: accounts[0].address,
method: method as string,
})
await this.initWallet(connection)
}
let postAuthRoute = '/';
if (window.sessionStorage) {
const storedRoute = window.sessionStorage.getItem(
'USER_POST_AUTH_ROUTE',
);
if (storedRoute) {
postAuthRoute = storedRoute;
window.sessionStorage.removeItem('USER_POST_AUTH_ROUTE');
}
}
this.$router.replace(postAuthRoute);
} catch (err) {
this.$nuxt.error({
statusCode: 400,
message: (err as Error).toString(),
});
}
} else {
if (window.sessionStorage) {
window.sessionStorage.removeItem('USER_POST_AUTH_ROUTE');
}
Comment on lines +63 to +65
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are some duplicated actions, maybe we could reorganize them like this:

manageSessionStorage(key: string, value?: string): void {
  if (window.sessionStorage) {
    if (value !== undefined) {
      window.sessionStorage.setItem(key, value);
    } else {
      window.sessionStorage.removeItem(key);
    }
  }
}

const USER_POST_AUTH_ROUTE = 'USER_POST_AUTH_ROUTE'

manageSessionStorage(USER_POST_AUTH_ROUTE, storedRoute); 
manageSessionStorage(USER_POST_AUTH_ROUTE);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe when we reach rule of three

this.$nuxt.error({
statusCode: 400,
message: error as string,
});
}
}
};
</script>
8 changes: 6 additions & 2 deletions pages/nft/iscn/_iscnId.vue
Original file line number Diff line number Diff line change
Expand Up @@ -424,12 +424,16 @@
return getNftModelApi(this.classId);
}

get isUsingMobileApp() {
return this.walletType?.includes('mobile') || this.walletType?.includes('walletconnect') || this.isUsingLikerLandApp
}

get isUsingLikerLandApp() {
return this.walletType === 'liker-id'
return this.walletType === 'likerland-app'
}

get isTransactionSizeLimited() {
return this.isUsingLikerLandApp
return this.isUsingMobileApp
}

get createNftClassPayload() {
Expand Down Expand Up @@ -731,7 +735,7 @@
} catch (err) {
console.error(err)
}
}

Check warning on line 738 in pages/nft/iscn/_iscnId.vue

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest, 18)

Unexpected console statement
if (!this.ogImageBlob && !this.ogImageArweaveId) {
const url = this.iscnData.contentMetadata?.url
if (!url) {
Expand Down
Loading
Loading