Skip to content

Commit

Permalink
fix: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoon-Suji committed May 18, 2023
1 parent a8fe17c commit e6585e3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default class Welldone implements ConcreteCosmosWalletStrategy {
const welldoneWallet = chainId
? new WelldoneWallet(chainId)
: this.getWelldoneWallet()

return welldoneWallet.checkChainIdSupport()
}

Expand All @@ -45,6 +46,7 @@ export default class Welldone implements ConcreteCosmosWalletStrategy {

try {
const accounts = await welldoneWallet.getAccounts()

return [accounts.address]
} catch (e: unknown) {
throw new CosmosWalletException(new Error((e as any).message), {
Expand Down Expand Up @@ -81,10 +83,12 @@ export default class Welldone implements ConcreteCosmosWalletStrategy {
}): Promise<DirectSignResponse> {
const welldoneWallet = this.getWelldoneWallet()
const signDoc = createSignDocFromTransaction(transaction)

try {
const result = await welldoneWallet.signTransaction(
createCosmosSignDocFromSignDoc(signDoc),
)

return result
} catch (e: unknown) {
throw new CosmosWalletException(new Error((e as any).message), {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export default class Welldone

try {
const accounts = await welldoneWallet.getAccounts()

return [accounts.address]
} catch (e: unknown) {
throw new CosmosWalletException(new Error((e as any).message), {
Expand Down Expand Up @@ -117,10 +118,12 @@ export default class Welldone
}): Promise<DirectSignResponse> {
const welldoneWallet = this.getWelldoneWallet()
const signDoc = createSignDocFromTransaction(transaction)

try {
const result = await welldoneWallet.signTransaction(
createCosmosSignDocFromSignDoc(signDoc),
)

return result
} catch (e: unknown) {
throw new CosmosWalletException(new Error((e as any).message), {
Expand Down
44 changes: 28 additions & 16 deletions packages/wallet-ts/src/utils/wallets/welldone/WelldoneWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,18 @@ export class WelldoneWallet {

async getAccounts(): Promise<{ address: string; pubKey: string }> {
const welldone = await this.getWelldoneWallet()

try {
const accounts = await welldone.request(this.chainName, {
method: 'dapp:accounts',
})

if (Object.keys(accounts).length === 0) {
throw new Error(
`Please make the ${this.chainName} account in the WELLDONE wallet`,
)
}

return accounts[this.chainName]
} catch (e: unknown) {
throw new CosmosWalletException(new Error((e as any).message), {
Expand All @@ -51,16 +54,18 @@ export class WelldoneWallet {

public async broadcastTx(txRaw: CosmosTxV1Beta1Tx.TxRaw): Promise<string> {
const welldone = await this.getWelldoneWallet()

try {
const {hash} = await welldone.request(this.chainName, {
method: 'dapp:sendSignedTransaction',
params: [
`0x${Buffer.from(
CosmosTxV1Beta1Tx.TxRaw.encode(txRaw).finish(),
).toString('hex')}`,
],
})
return hash
const { hash } = await welldone.request(this.chainName, {
method: 'dapp:sendSignedTransaction',
params: [
`0x${Buffer.from(
CosmosTxV1Beta1Tx.TxRaw.encode(txRaw).finish(),
).toString('hex')}`,
],
})

return hash
} catch (e) {
throw new CosmosWalletException(new Error((e as any).message), {
context: 'WELLDONE',
Expand All @@ -75,8 +80,9 @@ export class WelldoneWallet {
return new TxRestApi(endpoints.rest).fetchTxPoll(txHash)
}

private changePubKeyType (authInfoBytes: Uint8Array) {
private changePubKeyType(authInfoBytes: Uint8Array) {
const authInfo = CosmosTxV1Beta1Tx.AuthInfo.decode(authInfoBytes)

authInfo.signerInfos.forEach((signerInfo) => {
if (signerInfo.publicKey) {
signerInfo.publicKey.typeUrl = '/cosmos.crypto.secp256k1.PubKey'
Expand All @@ -95,12 +101,14 @@ export class WelldoneWallet {
signDoc.authInfoBytes = authInfoBytes

const welldone = await this.getWelldoneWallet()

try {
const signBytes = makeSignBytes(signDoc)
const response = await welldone.request(this.chainName, {
method: 'dapp:signTransaction',
params: [`0x${Buffer.from(signBytes).toString('hex')}`],
})

return {
signed: signDoc,
signature: {
Expand All @@ -123,6 +131,7 @@ export class WelldoneWallet {

public async getKey() {
const account = await this.getAccounts()

return account.pubKey
}

Expand All @@ -142,34 +151,37 @@ export class WelldoneWallet {
// WELLDONE Wallet only supports injective, cosmos, juno netoworks.
public async checkChainIdSupport() {
const { chainId } = this
if (chainId.includes('cosmoshub') || chainId.includes('juno')) {
return true
}
return false

return ['injective', 'cosmoshub', 'juno'].some((cosmosChainId) =>
chainId.includes(cosmosChainId),
)
}

private async checkNetwork() {
const welldone = this.getWelldone()

try {
const { node_info } = await welldone.request(this.chainName, {
method: 'status',
})
if (node_info.network === this.chainId) return true

return node_info.network === this.chainId
} catch (e) {
throw new CosmosWalletException(new Error((e as any).message), {
context: 'WELLDONE',
contextModule: 'check-network',
})
}
return false
}

public async getWelldoneWallet() {
const { chainId } = this
const welldone = this.getWelldone()

if (!(await this.checkNetwork())) {
throw new Error(`Change the WELLDONE Wallet Network to ${chainId}`)
}

return welldone
}

Expand Down

0 comments on commit e6585e3

Please sign in to comment.