Skip to content

Commit

Permalink
fix: mapping of grantAuthorization
Browse files Browse the repository at this point in the history
  • Loading branch information
bangjelkoski committed Aug 10, 2023
1 parent e3b2dc8 commit 58d1310
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { grpcPaginationToPagination } from '../../../utils/pagination'
import {
GoogleProtobufAny,
CosmosAuthzV1Beta1Authz,
CosmosAuthzV1Beta1Query,
} from '@injectivelabs/core-proto-ts'
Expand All @@ -10,20 +11,18 @@ import {
export class ChainGrpcAuthZTransformer {
static grpcGrantToGrant(grant: CosmosAuthzV1Beta1Authz.Grant) {
return {
authorization: grant.authorization
? Buffer.from(grant.authorization.value).toString('utf-8')
: '',
authorization: decodeAuthorization(grant.authorization),
expiration: grant.expiration,
}
}

static grpcGrantAuthorizationToGrantAuthorization(
grant: CosmosAuthzV1Beta1Authz.Grant,
grant: CosmosAuthzV1Beta1Authz.GrantAuthorization,
) {
return {
authorization: grant.authorization
? Buffer.from(grant.authorization.value).toString('utf-8')
: '',
granter: grant.granter,
grantee: grant.grantee,
authorization: decodeAuthorization(grant.authorization),
expiration: grant.expiration,
}
}
Expand Down Expand Up @@ -59,3 +58,16 @@ export class ChainGrpcAuthZTransformer {
}
}
}

const decodeAuthorization = (authorization?: GoogleProtobufAny.Any) => {
if (!authorization) {
return ''
}

switch (authorization.typeUrl) {
case '/cosmos.authz.v1beta1.GenericAuthorization':
return Buffer.from(authorization.value).toString('utf-8')
default:
return Buffer.from(authorization.value).toString('utf-8')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,21 @@ async function listenForMetamaskInitialized({ timeout } = { timeout: 3000 }) {
}

function getMetamaskFromWindow() {
const isMetamask = (ethereum: BrowserEip1993Provider) => {
// Identify if Metamask Wallet injected provider is present.
const metamask = !!ethereum.isMetaMask

return metamask
}

const injectedProviderExist =
typeof window !== 'undefined' && typeof $window.ethereum !== 'undefined'

// No injected providers exist.
if (!injectedProviderExist) {
return null
return
}

if (isMetamask($window.ethereum)) {
if ($window.ethereum.isMetaMask) {
return $window.ethereum
}

if ($window.providers) {
return $window.providers.find(isMetamask) ?? null
return $window.providers.find((p) => p.isMetaMask)
}

return null
return
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,35 +40,27 @@ async function listenForTrustWalletInitialized(
}

function getTrustWalletFromWindow() {
const isTrustWallet = (ethereum: BrowserEip1993Provider) => {
// Identify if Trust Wallet injected provider is present.
const trustWallet = !!ethereum.isTrust

return trustWallet
}

const injectedProviderExist =
typeof window !== 'undefined' &&
(typeof $window.ethereum !== 'undefined' ||
typeof $window.trustWallet !== 'undefined')

// No injected providers exist.
if (!injectedProviderExist) {
return null
return
}

if ($window.trustWallet) {
return $window.trustWallet
}

if (isTrustWallet($window.ethereum)) {
// Trust Wallet was injected into $window.ethereum.
if ($window.ethereum.isTrust) {
return $window.ethereum
}

if ($window.providers) {
return $window.providers.find(isTrustWallet) ?? null
return $window.providers.find((p) => p.isTrust)
}

return null
return
}

0 comments on commit 58d1310

Please sign in to comment.