Skip to content

Commit

Permalink
🔀 Merge #474 updates to deploy/rinkeby
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraHuang22 committed Sep 26, 2024
2 parents 97dbf96 + 3c503f2 commit b4df988
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 30 deletions.
29 changes: 19 additions & 10 deletions components/AppHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@
>
<IconDangerStripe />
</div>
<Snackbar
:open="shouldShowError"
class="mx-auto"
:text="errorMessage"
preset="warn"
@close="shouldShowError=false"
/>
</div>
</template>

Expand All @@ -160,7 +167,7 @@ import { Vue, Component } from 'vue-property-decorator'
import { namespace } from 'vuex-class'
import logTrackerEvent, { setLoggerUser } from '~/utils/logger'
import { IS_TESTNET } from '~/constant'
import { IS_TESTNET, SIGN_AUTHORIZATION_PERMISSIONS } from '~/constant'
const walletModule = namespace('wallet')
const bookApiModule = namespace('book-api')
Expand All @@ -179,6 +186,8 @@ export default class AppHeader extends Vue {
@bookApiModule.Action('clearSession') clearSession!: () => void
isLoading = false
errorMessage: string | null = null
shouldShowError = false
// eslint-disable-next-line class-methods-use-this
get isTestnet() {
Expand Down Expand Up @@ -218,22 +227,22 @@ export default class AppHeader extends Vue {
method,
})
await this.initWallet(connection)
if (!this.currentAddress || !this.signer) return
const signature = await this.signMessageMemo('authorize', [
'profile',
'read:nftbook',
'write:nftbook',
'read:nftcollection',
'write:nftcollection',
])
if (!signature) { return }
if (!this.currentAddress || !this.signer) {
throw new Error('FAILED_TO_CONNECT_WALLET')
}
const signature = await this.signMessageMemo('authorize', SIGN_AUTHORIZATION_PERMISSIONS)
if (!signature) {
throw new Error('SIGNING_REJECTED')
}
await this.authenticate({ inputWallet: this.currentAddress, signature })
}
} catch (error) {
this.disconnectWallet()
this.clearSession()
// eslint-disable-next-line no-console
console.error('handleConnectWalletButtonClick error', error)
this.shouldShowError = true
this.errorMessage = error as string
}
finally {
this.isLoading = false
Expand Down
8 changes: 8 additions & 0 deletions constant/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,11 @@ export const UPLOAD_FILESIZE_MAX = 200 * 1024 * 1024; // 200MB
export const NFT_BOOK_PRESS_URL = IS_TESTNET ? 'https://likecoin-nft-book-press-testnet.netlify.app/' : 'https://likecoin.github.io/nft-book-press/';

export const ARWEAVE_ENDPOINT = IS_TESTNET ? 'https://gateway.irys.xyz' : 'https://arweave.net';

export const SIGN_AUTHORIZATION_PERMISSIONS = [
'profile',
'read:nftbook',
'write:nftbook',
'read:nftcollection',
'write:nftcollection',
]
26 changes: 17 additions & 9 deletions layouts/wallet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,21 @@
<Label :text="$t('general.signIn.loading')" />
</Card>
</div>
<Snackbar
:open="shouldShowError"
class="mx-auto"
:text="errorMessage"
preset="warn"
@close="shouldShowError=false"
/>
</RootLayout>
</template>

<script lang="ts">
import { Vue, Component, Watch } from 'vue-property-decorator'
import { namespace } from 'vuex-class'
import logTrackerEvent, { setLoggerUser } from '~/utils/logger'
import { SIGN_AUTHORIZATION_PERMISSIONS } from '~/constant'
const walletModule = namespace('wallet')
Expand All @@ -48,6 +56,8 @@ export default class WalletLayout extends Vue {
) => void
isSignInLoading = false
errorMessage: string | null = null
shouldShowError = false
get isHideFooter() {
return this.$route.path.includes('/nft/purchase/') || this.$route.query.layout === 'popup';
Expand Down Expand Up @@ -77,16 +87,12 @@ export default class WalletLayout extends Vue {
method,
})
await this.initWallet(connection)
if (!this.walletAddress || !this.signer) return
const signature = await this.signMessageMemo('authorize', [
'profile',
'read:nftbook',
'write:nftbook',
'read:nftcollection',
'write:nftcollection',
])
if (!this.walletAddress || !this.signer) {
throw new Error('FAILED_TO_CONNECT_WALLET')
}
const signature = await this.signMessageMemo('authorize', SIGN_AUTHORIZATION_PERMISSIONS)
if (!signature) {
return
throw new Error('SIGNING_REJECTED')
}
await this.authenticate({
inputWallet: this.walletAddress,
Expand All @@ -101,6 +107,8 @@ export default class WalletLayout extends Vue {
this.clearSession()
// eslint-disable-next-line no-console
console.error('handleConnectWalletButtonClick error', error)
this.shouldShowError = true
this.errorMessage = error as string
}
finally {
this.isSignInLoading = false
Expand Down
17 changes: 8 additions & 9 deletions pages/auth/redirect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import { Vue, Component } from 'vue-property-decorator'
import { namespace } from 'vuex-class'
import logTrackerEvent, { setLoggerUser } from '~/utils/logger'
import { SIGN_AUTHORIZATION_PERMISSIONS } from '~/constant'
const walletModule = namespace('wallet')
const bookApiModule = namespace('book-api')
Expand Down Expand Up @@ -49,15 +50,13 @@ export default class RedirectPage extends Vue {
method: method as string,
})
await this.initWallet(connection)
if (!this.currentAddress || !this.signer) return
const signature = await this.signMessageMemo('authorize', [
'profile',
'read:nftbook',
'write:nftbook',
'read:nftcollection',
'write:nftcollection',
])
if (!signature) { return }
if (!this.currentAddress || !this.signer) {
throw new Error('FAILED_TO_CONNECT_WALLET')
}
const signature = await this.signMessageMemo('authorize', SIGN_AUTHORIZATION_PERMISSIONS)
if (!signature) {
throw new Error('SIGNING_REJECTED')
}
await this.authenticate({ inputWallet: this.currentAddress, signature })
}
let postAuthRoute = '/';
Expand Down
6 changes: 5 additions & 1 deletion store/book-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ export default class BookAPI extends VuexModule {
} catch (error) {
// eslint-disable-next-line no-console
console.error(error)
throw new Error('AUTHENTICATION_FAILED')
if (axios.isAxiosError(error)) {
throw new Error(`AUTHENTICATION_FAILED: ${error.response?.data}`)
}
throw new Error(`AUTHENTICATION_FAILED`)

}
}

Expand Down
1 change: 0 additions & 1 deletion store/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ export default class Wallet extends VuexModule {
}

@Action
// eslint-disable-next-line class-methods-use-this
async signMessageMemo(action: string, permissions?: string[]) {
if (!this.signer || !this.address) {
await this.initIfNecessary()
Expand Down

0 comments on commit b4df988

Please sign in to comment.