Skip to content

Commit

Permalink
Fix: allow colony creation with non-colony network tokens
Browse files Browse the repository at this point in the history
Basically, don't presume the token client has the `.locked()`
method available, since the ERC-20 doesn't enforce that.

Just try/catch it, and if not, set the token as 'unlocked'

Fixes: #2264
  • Loading branch information
rdig committed Apr 22, 2024
1 parent cf29884 commit c8c4426
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
7 changes: 6 additions & 1 deletion amplify/backend/function/createUniqueColony/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,12 @@ exports.handler = async (event) => {
const providerNetwork = await provider.getNetwork();
const chainId = String(providerNetwork.chainId);
const version = await colonyClient.version();
const isTokenLocked = colonyClient.tokenClient.locked();
let isTokenLocked = false;
try {
isTokenLocked = await colonyClient.tokenClient.locked();
} catch (error) {
// token doesn not support the `locked()` method
}

/*
* Create the colony
Expand Down
31 changes: 19 additions & 12 deletions src/redux/sagas/colony/colonyCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@ import {
ColonyRole,
colonyRoles2Hex,
} from '@colony/colony-js';
import { utils } from 'ethers';
import { utils, providers } from 'ethers';
import { poll } from 'ethers/lib/utils';
import { all, call, put } from 'redux-saga/effects';

import {
ADDRESS_ZERO,
DEFAULT_TOKEN_DECIMALS,
supportedExtensionsConfig,
isDev,
GANACHE_LOCAL_RPC_URL,
} from '~constants/index.ts';
import {
type ColonyManager,
ContextModule,
getContext,
} from '~context/index.ts';
import { ContextModule, getContext } from '~context/index.ts';
import {
CreateColonyEtherealMetadataDocument,
type CreateColonyEtherealMetadataMutation,
Expand Down Expand Up @@ -52,8 +50,8 @@ import {
putError,
takeFrom,
takeLatestCancellable,
getColonyManager,
initiateTransaction,
getNetworkClient,
} from '../utils/index.ts';

function* colonyCreate({
Expand All @@ -74,7 +72,17 @@ function* colonyCreate({
const apolloClient = getContext(ContextModule.ApolloClient);
const wallet = getContext(ContextModule.Wallet);
const walletAddress = utils.getAddress(wallet.address);
const colonyManager: ColonyManager = yield getColonyManager();
// const colonyManager: ColonyManager = yield getColonyManager();

const provider = (() => {
if (isDev) {
return new providers.JsonRpcProvider(GANACHE_LOCAL_RPC_URL);
}
return new providers.Web3Provider(window.ethereum!);
})();

const networkClient = yield call(getNetworkClient, provider);

const channelNames: string[] = [];

/*
Expand Down Expand Up @@ -263,17 +271,15 @@ function* colonyCreate({
const colonyClient = yield poll(
async () => {
try {
const client = await colonyManager.getClient(
ClientType.ColonyClient,
colonyAddress,
);
const client = await networkClient.getColonyClient(colonyAddress);
return client;
} catch (err) {
return undefined;
}
},
{
timeout: 30000,
retryLimit: 0,
},
);

Expand Down Expand Up @@ -335,6 +341,7 @@ function* colonyCreate({
},
{
timeout: 30000,
retryLimit: 0,
},
);

Expand Down

0 comments on commit c8c4426

Please sign in to comment.