Skip to content

Commit 5540868

Browse files
🔄 synced local 'src/' with remote 'src/'
1 parent 38a89ab commit 5540868

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

‎src/controllers/faucet.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ export const dripFaucet = async (
2626
await circleUserSdk.requestTestnetTokens({
2727
address: req.body.address,
2828
blockchain: req.body.blockchain,
29-
usdc: true
29+
usdc: true,
30+
native: req.body.blockchain === 'AVAX-FUJI'
3031
});
3132

3233
res.status(200).send();

‎src/controllers/wallets.ts

+18
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// See the License for the specific language governing permissions and
1515
// limitations under the License.
1616

17+
import { Blockchain } from '@circle-fin/user-controlled-wallets';
1718
import { circleUserSdk } from '../services';
1819
import { Request, Response, NextFunction } from 'express';
1920

@@ -67,3 +68,20 @@ export const getWallet = async (
6768
next(error);
6869
}
6970
};
71+
72+
export const createWallet = async (
73+
req: Request,
74+
res: Response,
75+
next: NextFunction
76+
) => {
77+
try {
78+
const response = await circleUserSdk.createWallet({
79+
blockchains: [req.body.blockchain as Blockchain],
80+
userToken: req.headers['token'] as string
81+
});
82+
83+
res.status(200).send(response.data?.challengeId);
84+
} catch (error: unknown) {
85+
next(error);
86+
}
87+
};

‎src/routers/wallets.ts

+34-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@ import {
2121
validate,
2222
walletTokenBalanceSchema
2323
} from '../middleware';
24-
import { getWallet, getWalletTokenBalance, listWallets } from '../controllers';
24+
import {
25+
createWallet,
26+
getWallet,
27+
getWalletTokenBalance,
28+
listWallets
29+
} from '../controllers';
30+
31+
import * as yup from 'yup';
2532

2633
const wallets = express.Router();
2734

@@ -122,4 +129,30 @@ wallets.get(
122129
*/
123130
wallets.get('/:id', validate(getWalletSchema), getWallet);
124131

132+
/**
133+
* POST - /wallets
134+
* Creates a user controlled wallet with given blockchain.
135+
*
136+
* Body:
137+
* blockchain: Blockchain - Blockchain network to create wallet on
138+
*
139+
* Returns:
140+
* challengeId: string - used to initiate a challenge flow for the user to create new wallet
141+
*
142+
*/
143+
wallets.post(
144+
'/',
145+
validate(
146+
yup.object({
147+
body: yup
148+
.object({
149+
blockchain: yup.string().required()
150+
})
151+
.noUnknown(true)
152+
.strict()
153+
})
154+
),
155+
createWallet
156+
);
157+
125158
export { wallets };

0 commit comments

Comments
 (0)