Skip to content

Commit

Permalink
fix encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaut committed Oct 10, 2024
1 parent 5804978 commit 21ca8d7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/ui/cypress/fixtures/testAccounts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InjectedAccount } from '@polkadot/extension-inject/types'
import { InjectedAccount } from 'polkadot-api/pjs-signer'

export interface InjectedAccountWitMnemonic extends InjectedAccount {
mnemonic: string
Expand Down
1 change: 0 additions & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"@graphql-codegen/client-preset": "4.2.5",
"@graphql-codegen/typescript-react-query": "^6.1.0",
"@graphql-eslint/eslint-plugin": "^3.20.1",
"@polkadot/extension-inject": "^0.52.3",
"@polkadot/typegen": "^13.1.1",
"@types/node": "^20.12.7",
"@types/react-dom": "^18.2.25",
Expand Down
5 changes: 3 additions & 2 deletions packages/ui/src/components/modals/ProposalSigning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,14 @@ const ProposalSigning = ({
setIsSubmitting(true)
let tx: Transaction<any, any, any, any> | undefined

console.log('proposalData', proposalData)
// if it's a rejection we can send it right away, no need for weight or calldata
if (!isApproving) {
tx = api.tx.Multisig.cancel_as_multi({
threshold,
other_signatories: otherSigners,
timepoint: proposalData.info.when,
call_hash: FixedSizeBinary.fromText(proposalData.hash)
call_hash: FixedSizeBinary.fromHex(proposalData.hash)
})

// If we can submit the proposal and have the call data
Expand All @@ -235,7 +236,7 @@ const ProposalSigning = ({
threshold,
other_signatories: otherSigners,
maybe_timepoint: proposalData.info.when,
call_hash: FixedSizeBinary.fromText(proposalData.hash),
call_hash: FixedSizeBinary.fromHex(proposalData.hash),
max_weight: { ref_time: 0n, proof_size: 0n }
})
} else {
Expand Down
35 changes: 23 additions & 12 deletions packages/ui/src/contexts/AccountsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import React, {
} from 'react'
// import { PolkadotSigner } from 'polkadot-api'
import { useAccounts as useRedotAccounts } from '@reactive-dot/react'
import { WalletAccount } from '@reactive-dot/core/wallets.js'
import { useApi } from './ApiContext'
import { encodeAccounts } from '../utils/encodeAccounts'
import { InjectedPolkadotAccount } from 'polkadot-api/pjs-signer'

const LOCALSTORAGE_SELECTED_ACCOUNT_KEY = 'multix.selectedAccount'
// const LOCALSTORAGE_ALLOWED_CONNECTION_KEY = 'multix.canConnectToExtension'
Expand All @@ -19,11 +21,11 @@ type AccountContextProps = {
}

export interface IAccountContext {
selectedAccount?: WalletAccount
ownAccountList: WalletAccount[]
selectedAccount?: InjectedPolkadotAccount
ownAccountList: InjectedPolkadotAccount[]
ownAddressList: string[]
selectAccount: (account: WalletAccount) => void
getAccountByAddress: (address: string) => WalletAccount | undefined
selectAccount: (account: InjectedPolkadotAccount) => void
getAccountByAddress: (address: string) => InjectedPolkadotAccount | undefined
// isAccountLoading: boolean
// isExtensionError: boolean
// selectedSigner?: PolkadotSigner
Expand All @@ -37,16 +39,25 @@ export interface IAccountContext {
const AccountContext = createContext<IAccountContext | undefined>(undefined)

const AccountContextProvider = ({ children }: AccountContextProps) => {
const ownAccountList = useRedotAccounts()
const [selectedAccount, setSelected] = useState<WalletAccount>(ownAccountList[0])
const redotAccountList = useRedotAccounts()
const { chainInfo } = useApi()
const ownAccountList = useMemo(
() => chainInfo && encodeAccounts(redotAccountList, chainInfo.ss58Format),
[chainInfo, redotAccountList]
)
const [selectedAccount, setSelected] = useState<InjectedPolkadotAccount | undefined>(
ownAccountList?.[0]
)
const [isConnectionDialogOpen, setIsConnectionDialogOpen] = useState(false)
// const [isAccountLoading, setIsAccountLoading] = useState(false)
// const [isExtensionError, setIsExtensionError] = useState(false)
// const [selectedSigner, setSelectedSigner] = useState<PolkadotSigner | undefined>()
// const [isAllowedToConnectToExtension, setIsAllowedToConnectToExtension] = useState(false)
const ownAddressList = useMemo(() => ownAccountList.map((a) => a.address), [ownAccountList])
const ownAddressList = useMemo(
() => (ownAccountList || []).map((a) => a.address),
[ownAccountList]
)
// const [accountGotRequested, setAccountGotRequested] = useState(false)
// const { chainInfo } = useApi()
// const [isLocalStorageSetupDone, setIsLocalStorageSetupDone] = useState(false)
// update the current account list with the right network prefix
// this will run for every network change
Expand All @@ -60,7 +71,7 @@ const AccountContextProvider = ({ children }: AccountContextProps) => {

const getAccountByAddress = useCallback(
(address: string) => {
return ownAccountList.find((account) => account.address === address)
return (ownAccountList || []).find((account) => account.address === address)
},
[ownAccountList]
)
Expand All @@ -70,7 +81,7 @@ const AccountContextProvider = ({ children }: AccountContextProps) => {
// setIsAllowedToConnectToExtension(true)
// }, [])

const selectAccount = useCallback((account: WalletAccount) => {
const selectAccount = useCallback((account: InjectedPolkadotAccount) => {
localStorage.setItem(LOCALSTORAGE_SELECTED_ACCOUNT_KEY, account.address)
setSelected(account)
}, [])
Expand Down Expand Up @@ -178,7 +189,7 @@ const AccountContextProvider = ({ children }: AccountContextProps) => {
<AccountContext.Provider
value={{
selectedAccount,
ownAccountList,
ownAccountList: ownAccountList || [],
ownAddressList,
selectAccount,
// isAccountLoading,
Expand Down
10 changes: 5 additions & 5 deletions packages/ui/src/utils/encodeAccounts.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { InjectedAccountWithMeta } from '@polkadot/extension-inject/types'
import { encodesubstrateAddress } from './encodeSubstrateAddress'
import { InjectedPolkadotAccount } from 'polkadot-api/pjs-signer'

export const encodeAccounts = (
accounts: InjectedAccountWithMeta[] | string[],
accounts: InjectedPolkadotAccount[] | string[],
ss58Format: number
) => {
return accounts
Expand All @@ -16,11 +16,11 @@ export const encodeAccounts = (
}

return encodedAddress
? ({
? {
...account,
address: encodedAddress
} as InjectedAccountWithMeta)
}
: null
})
.filter((acc) => !!acc) as (string | InjectedAccountWithMeta)[]
.filter((acc) => !!acc) as InjectedPolkadotAccount[]
}

0 comments on commit 21ca8d7

Please sign in to comment.