Skip to content

Commit

Permalink
🔀 Merge #474 to deploy/rinkeby
Browse files Browse the repository at this point in the history
  • Loading branch information
williamchong committed Sep 18, 2024
2 parents 0b41876 + e6861c5 commit e89d32f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 9 deletions.
19 changes: 14 additions & 5 deletions components/AppHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,21 @@
]"
>
<div
v-if="currentAddress"
v-if="isLoading"
class="flex items-center justify-center"
>
<ProgressIndicator />
</div>
<div
v-else-if="sessionWallet"
:class="[
'relative',
'w-[180px]',
]"
>
<Button
preset="secondary"
:title="currentAddress"
:title="sessionWallet"
>
<template
v-if="isUsingMobileApp"
Expand All @@ -104,7 +110,7 @@
'overflow-hidden',
'overflow-ellipsis',
]"
>{{ currentAddress }}</div>
>{{ sessionWallet }}</div>
</Button>
<Button
:class="[
Expand Down Expand Up @@ -168,6 +174,7 @@ export default class AppHeader extends Vue {
@walletModule.Action('signMessageMemo') signMessageMemo!: (action: string, permissions?: string[]) => Promise<any>
@walletModule.Getter('getWalletAddress') currentAddress!: string
@walletModule.Getter('getSigner') signer!: any
@bookApiModule.Getter('getSessionWallet') sessionWallet!: string
@bookApiModule.Action('authenticate') authenticate!: ({ inputWallet, signature }: { inputWallet?: string, signature?: any }) => Promise<any>
@bookApiModule.Action('clearSession') clearSession!: () => void
Expand Down Expand Up @@ -220,15 +227,17 @@ export default class AppHeader extends Vue {
'write:nftcollection',
])
if (!signature) { return }
await this.authenticate({inputWallet:this.currentAddress, signature})
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.isLoading = false
finally {
this.isLoading = false
}
}
}
</script>
1 change: 0 additions & 1 deletion store/book-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export default class BookAPI extends VuexModule {
const { data } = await axios.post(
API_POST_AUTHORIZE,
{
expiresIn: '7d',
...signature,
},
)
Expand Down
39 changes: 36 additions & 3 deletions store/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable import/no-extraneous-dependencies */
import { Module, VuexModule, Mutation, Action } from 'vuex-module-decorators'
import axios from 'axios'
import { OfflineSigner } from '@cosmjs/proto-signing'
import stringify from 'fast-json-stable-stringify';
import { catchAxiosError } from '~/utils/misc'
import { LIKECOIN_WALLET_CONNECTOR_CONFIG } from '~/constant/network'
Expand Down Expand Up @@ -39,7 +38,7 @@ async function getConnector() {
export default class Wallet extends VuexModule {
type = ''
address = ''
signer: OfflineSigner | null = null
signer: any = null
isShowKeplrWarning = false
isOpenSnackbar = false
likerInfo = null
Expand Down Expand Up @@ -251,6 +250,40 @@ export default class Wallet extends VuexModule {
sequence: '0',
account_number: '0',
}

if (this.signer?.signArbitrary) {
const { signature, pub_key: publicKey } =
await this.signer?.signArbitrary(
LIKECOIN_WALLET_CONNECTOR_CONFIG.chainId,
this.address,
payload,
)
const signDoc = {
msgs: [{
type: 'sign/MsgSignData',
value: {
signer: this.address,
data: window.btoa(payload),
},
}],
account_number: '0',
sequence: '0',
fee: {
gas: '0',
amount: [],
},
memo: '',
chain_id: '',
}
return {
signature,
signMethod: 'ADR-036',
publicKey: publicKey.value,
message: stringify(signDoc),
wallet: this.address,
expiresIn: '7d',
}
}
if ('signAmino' in this.signer) {
const { signed, signature } = await this.signer.signAmino(
this.address,
Expand All @@ -262,7 +295,7 @@ export default class Wallet extends VuexModule {
message: stringify(signed),
wallet: this.address,
signMethod: 'memo',
expiresIn: '1d',
expiresIn: '7d',
}
}
throw new Error('SIGNER_NOT_SUPPORT_AMINO')
Expand Down

0 comments on commit e89d32f

Please sign in to comment.